This document provides essential information for developers working on the Church CRM project.
- PHP 8.4 or higher
- Composer
- Node.js and npm
- SQLite (for development/testing)
- Clone the repository
- Install PHP dependencies:
composer install
- Install JavaScript dependencies:
npm install
- Create environment file:
cp .env.example .env php artisan key:generate
- Set up the database:
touch database/database.sqlite php artisan migrate
Run the development server with:
composer dev
This command starts:
- Laravel development server
- Queue worker
- Log watcher
- Vite development server
For server-side rendering, use:
composer dev:ssr
The project uses Pest PHP for testing, which is a testing framework built on top of PHPUnit with a more expressive syntax.
Run all tests:
composer test
Run specific test suites:
# Run unit tests with coverage
composer test:unit
# Run type coverage tests
composer test:type-coverage
# Run static analysis
composer test:types
# Run code style checks
composer test:lint
# Run refactoring checks
composer test:refactor
Run a specific test file:
./vendor/bin/pest tests/path/to/TestFile.php
-
Tests are organized in the
tests
directory:tests/Feature/Console
- For console command teststests/Feature/Http
- For HTTP-related teststests/Unit/Actions
- For action classestests/Unit/Models
- For model teststests/Unit/Jobs
- For job teststests/Unit/Policies
- For policy teststests/Unit/Services
- For service classes
-
Test files should follow the naming convention
*Test.php
. Use Pest for all the tests. -
Example of a basic test using Pest PHP:
<?php
declare(strict_types=1);
use App\Models\YourModel;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(TestCase::class, RefreshDatabase::class);
it('can perform some action', function (): void {
// Arrange
$data = [
'field' => 'value',
];
// Act
$result = YourModel::factory()->create($data);
// Assert
expect($result)->toBeInstanceOf(YourModel::class)
->and($result->field)->toBe('value');
});
-
Use the
RefreshDatabase
trait for tests that interact with the database -
Follow the Arrange-Act-Assert pattern in your tests.
- Arrange: Set up the necessary preconditions and inputs. Use factories to create test data.
- Act: Execute the code under test.
- Assert: Verify that the expected outcomes occur.
-
Generate a {Model}Factory with each model.
- The project uses Laravel Pint (pint.json) for PHP code style enforcement
- Strict types declaration is required
- Classes should be final when possible
- Follow PSR-12 coding standards with Laravel-specific additions
- Use PHP v8.4 features.
- Enforce strict types and array shapes via PHPStan.
Run code style checks:
composer test:lint
Fix code style issues:
composer lint
- Uses Prettier for code formatting
- ESLint for linting
- TypeScript for type checking
Configuration:
- Single quotes
- Semicolons required
- 4 spaces for indentation (except YAML files which use 2 spaces)
- 150 character line length
- Use Shadcn for UI components
- Use Tailwind CSS for styling
- Keep UI minimal
- PHPStan (via Larastan) is used for static analysis
- Type coverage is enforced at 100%
Run static analysis:
composer test:types
- Rector is used for automated code refactoring
Run refactoring checks:
composer test:refactor
Apply refactoring:
composer refactor
- Use Action classes for business logic
- Actions pattern and naming verbs. Example:
public function store(CreateTodoRequest $request, CreateTodoAction $action)
{
$user = $request->user();
$action->handle($user, $request->validated());
}
- Use FormRequest for validation
- Name with Create, Update, Delete.
- Migrations should be created for all database changes
- Use Laravel's Eloquent ORM for database interactions
- Use enums for fields with a fixed set of values
- Follow Laravel's MVC architecture
- Use Actions classes for business logic
- Use Policies for authorization
- Use Enums for type-safe constants
- Delete .gitkeep when adding a file.
- Stick to existing structure—no new folders.
- Avoid
DB::
; useModel::query()
only. - No dependency changes without approval.