GitHub - CodelyTV/php-ddd-example: 🐘🎯 Hexagonal Architecture + DDD + CQRS applie...
source link: https://github.com/CodelyTV/php-ddd-example
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
🐘🎯 Hexagonal Architecture, DDD & CQRS in PHP Symfony
Example of a PHP application following Domain-Driven Design (DDD) and
Command Query Responsibility Segregation (CQRS) principles keeping the code as simple as possible.
Take a look, play and have fun with this.
Stars are welcomed 😊
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
🚀 Environment setup
🐳 Needed tools
- Install Docker
- Clone this project:
git clone https://github.com/CodelyTV/cqrs-ddd-php-example cqrs-ddd-php-example
- Move to the project folder:
cd cqrs-ddd-php-example
🛠️ Environment configuration
- Copy the default environment variables:
cp .env.dist .env
- Modify the environment variables if needed:
vim .env
- Add
api.codelytv.localhost
domain to your local hosts:echo "127.0.0.1 api.codelytv.localhost"| sudo tee -a /etc/hosts > /dev/null
🌍 Application execution
- Install PHP dependencies and bring up the project Docker containers with Docker Compose:
make build
- Go to the API health check page
✅ Tests execution
- Install PHP dependencies if you haven't done so:
make deps
- Execute Behat and PHP Unit tests:
make test
🤔 Project explanation
This project tries to be a MOOC (Massive Open Online Course) platform. For now it only has an API and some Consumers.
⛱️ Bounded Contexts
- Mooc: Place to look in if you wanna see some code 🙂. Massive Open Online Courses public platform with users, videos, notifications, and so on
- Backoffice: Work in progress. Here you'll find the use cases needed by the Customer Support department in order to manage users, courses, videos, and so on.
🎯 Hexagonal Architecture
This repository follow the Hexagonal Architecture pattern. Also is structured using modules
.
With this, we can see that the current structure of a Bounded Context is:
$ tree -L 4 src src |-- Mooc // Company subdomain / Bounded Context: Features related to one of the company business lines / products | `-- Videos // Some Module inside the Mooc context | |-- Application | | |-- Create // Inside the application layer all is structured by actions | | | |-- CreateVideoCommand.php | | | |-- CreateVideoCommandHandler.php | | | `-- VideoCreator.php | | |-- Find | | |-- Trim | | `-- Update | |-- Domain | | |-- Video.php // The Aggregate of the Module | | |-- VideoCreatedDomainEvent.php // A Domain Event | | |-- VideoFinder.php | | |-- VideoId.php | | |-- VideoNotFound.php | | |-- VideoRepository.php // The `Interface` of the repository is inside Domain | | |-- VideoTitle.php | | |-- VideoType.php | | |-- VideoUrl.php | | `-- Videos.php // A collection of our Aggregate | `-- Infrastructure // The infrastructure of our module | |-- DependencyInjection | `-- Persistence | `--VideoRepositoryMySql.php // An implementation of the repository `-- Shared // Shared Kernel: Common infrastructure and domain shared between the different Bounded Contexts |-- Domain `-- Infrastructure
Repository pattern
Our repositories try to be as simple as possible usually only containing 2 methods search
and save
.
If we need some query with more filters we use the Strategy
pattern also known as Criteria
pattern. So we add a
searchByCriteria
method.
You can see an example here and its implementation here.
Aggregates
You can see an example of an aggregate here. All aggregates should extends the AggregateRoot.
Command Bus
There are 2 implementations of the command bus.
Query Bus
The Query Bus uses the Symfony Message Bus.
Event Bus
The Event Bus uses the Symfony Message Bus.
🤔 Contributing
There are some things missing (add swagger, improve documentation...), feel free to add this if you want! If you want some guidelines feel free to contact us :)
🤩 Extra
This code was show in the From framework coupled code to #microservices through #DDD talk and doubts where answered in DDD y CQRS: Preguntas Frecuentes video.
🎥 Used in the CodelyTV Pro courses:
Recommend
-
36
README.md Example Implementation of a Hexagonal Architecture
-
36
Hexagonal Architecture — Principles & Practical Example in JavaImplementation of Hexagonal Architecture or Ports & Adapter Architecture
-
6
As the production of Netflix Originals grows each year, so does our need to build apps that enable efficiency throughout the entire creative process. Our wider Studio Engineering Organization has built more than 30 apps t...
-
8
Sponsored by LaunchDarkly By separating code deployments from feature releases, LaunchDarkly enables you to deploy faster, reduce risk, and iterate continuously. Over 1500 organizations around the world use LaunchDarkly to bui...
-
7
Data-oriented, clean&hexagonal architecture software in RustData-oriented, clean&hexagonal architecture software in Rust – through an example projectSeptember 5, 2021This post and work behind tries to achieve multiple go...
-
5
Sairyss/domain-driven-hexagon: Guide on Domain-Driven Design, Hexagonal architecture, best practices etc. READ...
-
6
Support Tip: Update to the latest Intune App SDK for iOS to ensure APP is applied correctly ...
-
6
ddd-hexagonal-cqrs-es-eda Complete working example of using Domain Driven Design (DDD), Hexagonal Architecture, CQRS, Event Sourcing (ES), Event Driven Architecture (EDA), Behaviour Driven Development (BDD) using TypeScript and NestJS.
-
6
bitloops/ddd-hexagonal-cqrs-es-eda: DDD、六边形架构、CQRS 完整示例 解道Jdon
-
2
Public Library Inspired by eminetto's clean architecture backend API from 2020, this Public Library API project was developed from the ground up, utilizing...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK