Coding Guidelines

This page covers conventions specific to this project. For general Laravel or PHP knowledge, refer to the official Laravel documentation and PSR-12.

General Principles

Naming Conventions

Model Conventions

Entity Structure Pattern

Each entity follows a consistent file layout:

app/Http/Controllers/{Entity}Controller.php
app/Http/Requests/Store{Entity}Request.php
app/Http/Requests/Update{Entity}Request.php
app/Http/Resources/{Entity}Resource.php
app/Models/{Entity}.php
database/factories/{Entity}Factory.php
database/migrations/create_{entities}_table.php
database/seeders/{Entity}Seeder.php
tests/Feature/Api/{Entity}/AnonymousTest.php
tests/Feature/Api/{Entity}/IndexTest.php
tests/Feature/Api/{Entity}/ShowTest.php
tests/Feature/Api/{Entity}/StoreTest.php
tests/Feature/Api/{Entity}/UpdateTest.php
tests/Feature/Api/{Entity}/DestroyTest.php

When adding a new entity, replicate this structure and follow the patterns in an existing entity (e.g., Context).

Quality Controls

Run these before submitting code:

# Lint PHP (auto-fix)
composer ci-lint

# Lint check only (non-modifying)
composer ci-lint:test

# Run all tests
composer ci-test

# Build frontend assets
composer ci-build

# Full pre-PR validation
composer ci-before:pull-request

Import Order

Organise use statements in this order:

  1. Laravel/Framework imports
  2. Third-party imports
  3. Application Models
  4. Application Resources
  5. Application Requests
  6. Application Services

Common Pitfalls