Skip to content

Example of a PHP API with DDD and Hexagonal architecture

Notifications You must be signed in to change notification settings

victor-falcon/php-ddd

Repository files navigation

📡 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

About

Example of a PHP API with DDD and Hexagonal architecture

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published