This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Cohete is an asynchronous PHP framework built on ReactPHP and RxPHP, implementing Domain-Driven Design (DDD) patterns. The project follows a clean architecture with clear separation between Application, Domain, and Infrastructure layers.
The codebase follows DDD structure:
- Application Layer (
src/ddd/Application/): Contains command handlers, queries, and application services - Domain Layer (
src/ddd/Domain/): Contains entities, value objects, domain services, and repository interfaces - Infrastructure Layer (
src/ddd/Infrastructure/): Contains concrete implementations of repositories, HTTP server, message buses, and external integrations
Key architectural components:
- Message Bus: Handles commands and queries using either BunnieMessageBus or ReactMessageBus
- Async Repositories: Non-blocking database operations with MySQL and file-based implementations
- HTTP Server: ReactPHP-based async HTTP server with custom routing
- Value Objects: Strongly typed domain primitives
# Run the application
make run
# Alternative: make start (same as make run)
# Watch for file changes during development
make watch
# Run in production mode with Nix
make run-prod# Run PHPUnit tests
./vendor/bin/phpunit
# Run Behat acceptance tests
make behat
# or
./vendor/bin/behat# Run database migrations
make migrate
# Seed database with fixtures
make fixtures
# Start MySQL Docker container
make mysql# Fix code style issues
make fix
# Run PHPStan static analysis (level: max)
./vendor/bin/phpstan analyse
# Run Psalm static analysis (level: 7)
./vendor/bin/psalm# Run load tests with Apache Bench
make test_ab# Start RabbitMQ Docker container
make rabbitmq
# Install Nix (if not already installed)
make install-nixsrc/bootstrap.php: Application entry point with ReactPHP event loop setupsrc/ddd/Infrastructure/HttpServer/Kernel/Kernel.php: Core HTTP request handling with async promise-based routingsrc/ddd/Infrastructure/HttpServer/ReactHttpServer.php: Async HTTP server implementationsrc/ddd/Infrastructure/HttpServer/Router/routes.json: Route definitions mapped to controllerssrc/ddd/Infrastructure/PSR11/ContainerFactory.php: Dependency injection container setupcomposer.json: Dependencies and autoloading configuration
The project uses Nix for reproducible development environments. After running make install-nix, use nix develop to enter the development shell with all dependencies.
- Unit tests in
test/directory mirror thesrc/structure - Integration tests use Behat for behavior-driven development
- Test configuration excludes Infrastructure layer from coverage
- PHPUnit configured for strict testing with coverage metadata
- PHPStan runs at maximum level with bootstrap support
- Psalm configured at error level 7 with unused code detection
- Both tools focus on the
src/directory and ignore vendor files
When adding new features, follow these patterns:
- Commands:
src/ddd/Application/Post/CreatePostCommand.phpandCreatePostCommandHandler.php - Queries:
src/ddd/Application/Post/FindAllPostsQuery.phpand query handlers - Controllers:
src/ddd/Infrastructure/HttpServer/RequestHandler/for HTTP endpoints
- Interface:
src/ddd/Domain/Entity/PostRepository.php - MySQL implementation:
src/ddd/Infrastructure/Repository/Post/AsyncMysqlPostRepository.php - Returns React\Promise\PromiseInterface for non-blocking operations
- Extend base classes:
StringValueObject,UuidValueObject,AtomDateValueObject - Example:
src/ddd/Domain/Entity/Post/ValueObject/PostId.php