Cqrs Example Php,php-ddd-example

f71fb9a0d9f740fb66e1ead2ccbdb973.png

🐘🎯 Hexagonal Architecture, DDD & CQRS in PHP

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f64656c7954562d4f532d677265656e2e7376673f7374796c653d666c61742d737175617265

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f64656c7954562d50524f2d626c61636b2e7376673f7374796c653d666c61742d737175617265

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d352e302d707572706c652e7376673f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79

badge.svg

Example of a PHP application using 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 😊

View Demo

·

Report a bug

·

Request a feature

🚀 Environment Setup

🐳 Needed tools

Clone this project: git clone https://github.com/CodelyTV/php-ddd-example php-ddd-example

Move to the project folder: cd php-ddd-example

🛠️ Environment configuration

Create a local environment file (cp .env .env.local) if you want to modify any parameter

🔥 Application execution

✅ Tests execution

Install the dependencies if you haven't done it previously: make deps

Execute PHPUnit and Behat tests: make test

👩‍💻 Project explanation

This project tries to be a MOOC (Massive Open Online Course) platform. It's decoupled from any framework, but it has

some Symfony and Laravel implementations.

⛱️ 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: 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, it's 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

| `--MySqlVideoRepository.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 Specification 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 is 1 implementations of the command bus.

Sync using the Symfony Message Bus

Query Bus

The Query Bus uses the Symfony Message Bus.

Event Bus

The Event Bus uses the Symfony Message Bus.

The MySql Bus uses a MySql+Pulling as a bus.

The RabbitMQ Bus uses RabbitMQ C extension.

📱 Monitoring

Every time a domain event is published it's exported to Prometheus. You can access to the Prometheus panel here

🤔 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

🎥 Used in the CodelyTV Pro courses:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值