php-ddd
php-ddd copied to clipboard
Example of a PHP API with DDD and Hexagonal architecture
๐ก PHP DDD Api
๐ Proyect structure
Our code, it's stored in the src folder. One for leads and another for event logging.
src
โโโ EventLogger
โย ย โโโ Domain
โย ย โโโ Infrastructure
โย ย โโโ Repository
โโโ Leads
โย ย โโโ Command
โย ย โโโ Domain
โย ย โโโ Infrastructure
โย ย โโโ Repository
โโโ Shared
โโโ Domain
โโโ Infrastructure
We have two domains: one for leads and another for event logging. Also, we have a Shared folder for some shared code between al domains.
CQRS
We are implementing CQRS in our controllers in order to separate queries, commands, and most important, our code from symfony or other infrastructure code. We have a InMemorySymfonyCommandBus.php and a InMemorySymfonyQueryBus.php to dispatch any request we implement.
We also have a EventBus with two possible implementations: We have InMemorySymfonyEventBus.php and a MySqlDoctrineEventBus.php to dispatch events, store them in database and executed them assyncronous with a command.
๐ Execute and run project
With make start you can run dockers containers and you will find the project into http://localhost:8000. When you finish working you can just make stop to stop containers.
๐ท CI
We use GitHub Workflow to test our project and check style after every commit. If you go to the Actions tab you can see each execution. Also, you will receive an email if you commit something and don't pass through all our checks.
If you want yo can execute each of this tests with the following commands in this doc.
๐งช Testing
We have two testing suits with PHP Unit, one for unit testing an another for integration. You can execute any of them with:
make test/unit # Unit testing
make test/integration # Integration testing
Also we use behat to test features. You can execute this tests with:
make test/functional # Functional testing
If you want to execute all you can simply execute make test/all.
๐ Code style and error checker
To ensure that all the code write in this project follow the same style guide and it's free of error we have two types of code checks:
make style/code-style # Code style
make style/static-analysis # Static error checker
make style/all # Run both