How codelytv/php-ddd-example works
Main Components
• Bounded Contexts: There are at least two major contexts – “Mooc” (for the public course platform) and “Backoffice” (for administrative/customer support functionality), plus a “Shared” context that implements common patterns and infrastructure.
• Applications: Within each bounded context, there are clear modules (for example, Courses, Videos, Notifications, etc.) following the hexagonal architecture style (with separate Application, Domain, and Infrastructure layers). In addition, note that there are three “apps” available from a deployment perspective – Mooc Backend, Backoffice Backend, and Backoffice Frontend.
• Infrastructure Components:
– API Endpoints (HTTP controllers) for both backends and the frontend.
– Command, Query, and Event Buses (with separate implementations using Symfony Message Bus, MySQL, or RabbitMQ).
– Persistence layers (e.g., Doctrine ORM, MySQL, Elasticsearch).
– External systems such as Prometheus for monitoring and Docker for containerization.
Relationships and Interactions
• For each bounded context, show how the Application layer interfaces with the Domain (which contains Aggregates, Domain Events, Repositories etc.) and the Infrastructure layer (which adapts external systems, such as databases or messaging queues).
• That the frontends (Backoffice Frontend and the other APIs) interact with their respective backends, which in turn use the bus-based mechanisms to delegate tasks.
• External dependencies such as Prometheus (for monitoring domain events) and the Dockerized environment that orchestrates the services.
Architectural Patterns
• Hexagonal (Ports and Adapters) Architecture: Center the domain layer (with Aggregates, Domain Events, etc.) and surround it with adapters (Entry points like HTTP controllers and exit points like the database or message queues).
• CQRS Pattern: Clearly separate “Commands” (actions that modify state) from “Queries” (read-only requests), and show that each bounded context has its own ways to handle commands and queries.
• Repository and Specification Patterns: Note that repositories have a basic interface (only methods such as save and search) and extended querying via the Criteria pattern.
Elements Reflecting Technologies and Frameworks
• That some modules use Symfony components (as shown in the “config” directories and the use of Symfony Message Bus).
• Bounded Context Sections:
– Mooc Context (Modules: Courses, Videos, Notifications, Steps, etc.)
– Backoffice Context (Modules: Courses, possibly Auth, etc.)
– Shared Kernel (Common Domain and Infrastructure components)
• Layered structure inside each context:
– Application Layer: Command Handlers, Query Handlers, Application Services.
– Domain Layer: Aggregates, Domain Events, Domain Models.
– Infrastructure Layer: Persistence implementations (Doctrine, MySQL), Bus implementations, External integrations (Elasticsearch, RabbitMQ).
• API and UI Layers:
– Backoffice Frontend (with HTTP controllers and templates)
– Backoffice Backend and Mooc Backend (with Console commands and API controllers)
• Buses:
– Command Bus, Query Bus, Event Bus (with variations like InMemory, MySQL, and RabbitMQ)
• Monitoring:
– Prometheus instance that collects domain event metrics.
• Deployment:
– Docker and docker-compose as orchestrators of these services.
This detailed separation into as many distinct components as possible will assist in an accurate architectural view that both highlights the implementation of Hexagonal Architecture and the principles of DDD and CQRS as applied in this PHP project.