This file contains guidelines for agentic coding assistants working in the MicroSymfony repository.
MicroSymfony is a Symfony 8.0 micro-framework template demonstrating modern PHP development best practices. It uses PHP 8.4+, Symfony 8.0, Twig 3, Hotwired (Stimulus 3.2, Turbo 8.0), and follows strict code quality standards.
castor start # Start development server
castor test # Run all tests
castor test:unit # Run unit tests only
castor test:functional # Run functional tests only
castor test:api # Run API tests only
castor test:e2e # Run E2E tests only
castor test filter=testName # Run single test
castor stan # Run PHPStan static analysis
castor lint:all # Run all linters
castor fix:all # Run all fixers
castor ci # Run full CI locallymake start # Start development server
make test # Run all tests
make test-unit # Run unit tests only
make test-functional # Run functional tests only
make test-api # Run API tests only
make test-e2e # Run E2E tests only
make test filter=testName # Run single test
make stan # Run PHPStan static analysis
make lint # Run all linters
make fix # Run all fixers
make ci # Run full CI locally# Preferred methods
castor test filter=testSlugify
make test filter=testSlugify
# Direct PHPUnit
vendor/bin/phpunit --filter=testSlugify- Strict Types: Always use
declare(strict_types=1);at the top of every PHP file - Final Classes: Mark classes as
finalunless inheritance is required - Readonly Properties: Use
readonlyproperty promotion for services - Type Declarations: Use full type hints for parameters and return types
- ADR Pattern: Controllers use Action-Domain-Responder pattern with
__invoke()method
// Standard order: framework, Symfony components, third-party, application
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use App\Helper\StringHelper;- Controllers:
*Action(e.g.,HomeAction,SlugifyAction) - Services: Descriptive names (e.g.,
StringHelper,EmailService) - Tests:
*Testwith@coversannotations - Routes: Use class constants for route names
- DTOs: Descriptive names ending with
Dtoif applicable - Enums: Descriptive names with proper backing types
- Controllers must return Symfony Response objects
- Services use dependency injection with proper type hints
- Use proper HTTP status codes in API responses
- Implement validation using Symfony forms or constraints
- Use exceptions for error conditions with appropriate handling
src/
├── Controller/ # ADR pattern controllers
├── Data/ # Data services
├── Helper/ # Services and utilities
├── Twig/Extension/ # Custom Twig extensions
├── Form/Type/ # Form types
├── Dto/ # Data transfer objects
└── Enum/ # Enumerations
tests/
├── Unit/ # Isolated class testing
├── Integration/ # Component interaction
├── Functional/ # HTTP request/response
├── Api/ # Endpoint testing
└── E2E/ # Full application flow
- All Symfony configuration uses PHP format (not YAML)
- Service container uses full autowiring and autoconfiguration
- Asset management via importmap.php (no Webpack)
- PHPStan configured at maximum level with bleeding edge features
- Unit Tests: Test individual classes in isolation
- Integration Tests: Test component interactions
- Functional Tests: Test HTTP request/response cycles
- API Tests: Test API endpoints with proper assertions
- E2E Tests: Test complete user workflows
Always include @covers annotations in unit tests to specify what is being tested.
- PHPStan: Must pass at maximum level (use
castor stanormake stan) - PHP-CS-Fixer: Must pass with Symfony rules (use
castor fix:allormake fix) - Frontend: Use Biome for JS/CSS linting and formatting
- Container: Symfony DI container must pass linting
- Templates: Twig templates must pass linting
- Write code following the established patterns
- Run
castor testto ensure all tests pass - Run
castor stanfor static analysis - Run
castor fix:allfor code formatting - Run
castor cito simulate full CI pipeline
- Never commit secrets or API keys
- Use proper authentication and authorization
- Validate all input data
- Use HTTPS in production
- Run
composer auditregularly
- Use Stimulus for JavaScript interactions
- Use Turbo for seamless page updates
- Follow Pico CSS conventions for styling
- Use importmap.php for asset management
- Keep JavaScript modular and reusable
- Use readonly properties where possible
- Optimize database queries
- Implement proper caching strategies
- Use Symfony's built-in performance tools
- Monitor memory usage in long-running processes
Before considering any code complete:
- All tests must pass (
castor test) - PHPStan must pass (
castor stan) - Code style must be fixed (
castor fix:all) - CI pipeline must pass locally (
castor ci)
- Symfony Best Practices: https://symfony.com/doc/current/best_practices.html
- PHPStan Documentation: https://phpstan.org/
- PHP-CS-Fixer: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer
- Castor Task Runner: https://castor.io/
Remember: This project serves as a template for modern Symfony development. Maintain high standards and follow established patterns.