• Stars
    star
    2,889
  • Rank 15,142 (Top 0.4 %)
  • Language
    PHP
  • Created over 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🐘🎯 Hexagonal Architecture + DDD + CQRS in PHP using Symfony 6

Codely logo

🐘🎯 Hexagonal Architecture, DDD & CQRS in PHP

codely.tv CodelyTV Courses Symfony 5.0 CI pipeline status

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 welcome 😊

View Demo Β· Report a bug Β· Request a feature

πŸš€ Environment Setup

🐳 Needed tools

  1. Install Docker
  2. Clone this project: git clone https://github.com/CodelyTV/php-ddd-example php-ddd-example
  3. Move to the project folder: cd php-ddd-example

πŸ› οΈ Environment configuration

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

πŸ”₯ Application execution

  1. Install all the dependencies and bring up the project with Docker executing: make build
  2. Then you'll have 3 apps available (2 APIs and 1 Frontend):
    1. Mooc Backend: http://localhost:8030/health-check
    2. Backoffice Backend: http://localhost:8040/health-check
    3. Backoffice Frontend: http://localhost:8041/health-check

βœ… Tests execution

  1. Install the dependencies if you haven't done it previously: make deps
  2. 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 follows 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 extend the AggregateRoot.

Command Bus

There is 1 implementations of the command bus.

  1. 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

This code was shown in the From framework coupled code to #microservices through #DDD talk and doubts where answered in the DDD y CQRS: Preguntas Frecuentes video.

πŸŽ₯ Used in the CodelyTV Pro courses:

More Repositories

1

typescript-ddd-example

πŸ”·πŸŽ― TypeScript DDD Example: Complete project applying Hexagonal Architecture and Domain-Driven Design patterns
TypeScript
1,217
star
2

dotly

🌚 Modular and easy to customize dotfiles framework
Shell
1,151
star
3

refactoring-code_smells-design_patterns

♻️ Example projects illustrating Code Smells in order to apply Refactoring techniques
PHP
553
star
4

typescript-ddd-skeleton

πŸ”·βœ¨ TypeScript DDD Skeleton: Bootstrap your new TypeScript applying following Hexagonal Architecture and Domain-Driven Design patterns
TypeScript
420
star
5

java-ddd-example

♨️ DDD in Java skeleton & examples. Course:
Java
390
star
6

cra-template-codely

<πŸŒ±βš›οΈ> Create React App Codely template
SCSS
339
star
7

pr-size-labeler

🏷 Visualize and optionally limit the size of your Pull Requests
Shell
316
star
8

dotfiles

🐒 πŸ’¨ Speedup your MacOS setup with this fine tuning settings
Shell
304
star
9

java-ddd-example-deprecated

β˜•πŸŽ― Hexagonal Architecture + DDD + CQRS in a Java project using SpringBoot
Java
292
star
10

eslint-plugin-hexagonal-architecture

A plugin that helps you to enforce hexagonal architecture best practises
TypeScript
266
star
11

php-ddd-skeleton-deprecated

πŸ˜πŸš€ PHP DDD Skeleton: Bootstrap your new projects or be inspired by this example project
PHP
249
star
12

javascript-basic-skeleton

JavaScript
208
star
13

typescript-api-skeleton

πŸ”·πŸŒ TypeScript API Skeleton: Bootstrap your new TypeScript backend project
TypeScript
188
star
14

awesome-typescript-examples

✨ Awesome TypeScript Examples with complete show cases of how to take advantage of the language potential.
TypeScript
162
star
15

csharp-ddd-skeleton

🦈✨ C# DDD Skeleton: Bootstrap your new C# projects applying Hexagonal Architecture and Domain-Driven Design patterns
C#
153
star
16

typescript-react_best_practices-vite_template

<βš‘βš›οΈ> Start your React project with Vite following code best practices (TypeScript, Linting, testing, CI/CD…)
SCSS
147
star
17

job-offers

😊 Do you wanna work with us?
133
star
18

go-hexagonal_http_api-course

Ejemplos del curso de API HTTP en Go aplicando Arquitectura Hexagonal
Go
132
star
19

jetbrains-theme

🎨 A modern, productivity-increaser theme for all JetBrains IDEs
Shell
132
star
20

scala-ddd-example

λ🎯 Hexagonal Architecture + DDD + CQRS applied in Scala using Akka HTTP
Scala
130
star
21

typescript-basic-skeleton

πŸ”·πŸŒ± TypeScript Basic Skeleton: Bootstrap your new TypeScript project with the bare minimum dependencies
TypeScript
127
star
22

typescript-ddd-course

πŸ”·πŸ”– TypeScript DDD Course: Learn Domain-Driven Design in TS lesson by lesson
TypeScript
118
star
23

golang-examples

Introductory examples to Go programming language used in the CodelyTV Pro course
Go
112
star
24

typescript-primitives-type

🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)
TypeScript
109
star
25

php-basic-skeleton

πŸ˜πŸš€ PHP Basic Skeleton: Bootstrap your new projects using this Composer Project
PHP
103
star
26

eslint-config-codely

Opinionated linting configuration considering modern TypeScript best practices and providing consistency to your import statements. Valid for your JavaScript or TypeScript projects 🀟
JavaScript
80
star
27

java-solid-examples

Learn SOLID principles by examples in Java
Java
76
star
28

javascript-testing-frontend-course

JavaScript
74
star
29

frontend-hexagonal_architecture-course

Hexagonal Architecture in frontend
TypeScript
71
star
30

vscode-theme

A modern, good-looking, productivity-increaser theme for Visual Studio Code
58
star
31

p2p-editor

Online code editor based on P2P and JavaScript. Demo:
JavaScript
57
star
32

kotlin-api-skeleton

πŸ’Ž Kotlin Hexagonal HTTP API template to create your new projects
Kotlin
52
star
33

react-from_zero_to_best_practices-course

Developer dashboard made in the "React from 0 with good practices" course
TypeScript
49
star
34

kotlin-basic-skeleton

A basic Skeleton to create your Kotlin apps easily
Kotlin
48
star
35

java-basic-skeleton

β˜•πŸš€ Java Bootstrap: Skeleton for your new projects
Java
46
star
36

php-coding_style-codely

PHP Coding Style rules we use in Codely
PHP
43
star
37

css-architecture-course

HTML
40
star
38

figma-plugin-skeleton

πŸͺ† Template intended to serve as a starting point if you want to bootstrap a Figma Plugin in TypeScript.
TypeScript
34
star
39

elastic-stack-example

Simple app using Elastic Stack (Elasticsearch+Logstash+Kibana) & Beats with Docker for the CodelyTV Pro course
PHP
32
star
40

css-layouts-best-practises-course

Vue
32
star
41

developing_codely_website-course

Developing Codely's website course code examples https://pro.codely.tv/library/maquetando-la-web-de-codely-desde-0-181753
TypeScript
31
star
42

typescript-web-skeleton

πŸ”·πŸ•ΈοΈ TypeScript Web Skeleton: Bootstrap your new TypeScript web frontend project
JavaScript
31
star
43

java-gildedrose-kata

Java
30
star
44

awesome-p2p

A curated list of awesome P2P learning tutorials and resources
29
star
45

java-oop-examples

Object-Oriented Programming recap with Java examples
Java
29
star
46

youtube-code-examples

πŸŽ₯ Collection of code examples used in our screencasts about programming best practices
PHP
29
star
47

n8n-nodes-twitch

n8n trigger node for Twitch: Execute workflows on stream start, stream end, and new follows
TypeScript
29
star
48

prometheus-course

πŸŽ“
Go
29
star
49

vscode-awesome-settings

Awesome Settings for VSCode
TypeScript
29
star
50

css-grid-course

HTML
28
star
51

bash-github_actions-skeleton

😬 Speedup your GitHub Actions creation!
Shell
27
star
52

frontend-hexagonal_architecture-example

TypeScript
27
star
53

css-flex-course

CSS Flex course examples
HTML
26
star
54

awesome-bash-challenges

Awesome Bash Challenges
Shell
25
star
55

php-finder_refactoring-kata

πŸ˜πŸ”Incomprehensible Finder Refactoring Kata port for PHP
PHP
24
star
56

loki-grafana-course

24
star
57

design-patterns

Java
23
star
58

symfony-maintainable-scalable-course

Examples of "Symfony mantanible y escable" course
PHP
23
star
59

terraform-course

Terraform Codely course examples
HCL
23
star
60

react-devdash

Developer dashboard made in the "React from 0 with good practices" course
TypeScript
23
star
61

kotlin-hexagonal_http_api-course

πŸ’Ž Kotlin Hexagonal HTTP API Course: Learn to do scalable Kotlin web apps
Kotlin
22
star
62

csharp-basic-skeleton

πŸ¦ˆπŸš€ C# Basic Skeleton: Bootstrap your new projects.
C#
22
star
63

figma-plugin-structurer

πŸ—οΈ Figma Plugin for speeding up and ensure consistency in the structure of your Figma projects
TypeScript
22
star
64

value_objects-course

Value Objects course examples
TypeScript
21
star
65

vue-progressive-migration-course

HTML
21
star
66

react-carousel

A React Carousel supporting different slides sizes, responsive, custom styling, accesible by default, SSR compatible, and tested
TypeScript
21
star
67

makefiles-course

Makefile
20
star
68

ci_with_github_actions-course

PHP
20
star
69

web-performance-course

Web performance course examples
CSS
20
star
70

check-critical-files

πŸ‘ Check for critical files in your commits
Shell
20
star
71

refactor-from-js-to-ts-course

TypeScript
20
star
72

vue-3-course

Vue
19
star
73

javascript-modern-course

JavaScript
19
star
74

ban-words

Shell
19
star
75

css-light-dark-mode-course

HTML
18
star
76

react-state-management-course

React State Management course examples
JavaScript
18
star
77

infrastructure_design-eventbus-aws-course

Infrastructure Design: AWS SQS as a Message Queue course examples
TypeScript
18
star
78

php-coupled_code-example

πŸ˜πŸ€·β€β™‚οΈ Simple demo of a coupled code to ilustrate how to refactor to CQRS & DDD
PHP
16
star
79

reactjs-video-favourites-app

Introductory examples to ReactJS used in the CodelyTV Pro course
JavaScript
16
star
80

no-pull-requests

πŸ™… GitHub Action to autoclose all Pull Requests
Shell
15
star
81

aggregates-course

Aggregates course examples
TypeScript
15
star
82

domain_modeling-domain_events-course

Domain Modeling: Domain Events course examples
TypeScript
15
star
83

scala-examples

Ζ›πŸ€” Introduction to Scala CodelyTV Pro course examples
Scala
15
star
84

scala-basic-skeleton

Starting point if you want to bootstrap a project in Scala
Scala
15
star
85

design_patterns-criteria-course

Criteria Codely course examples
TypeScript
15
star
86

scala-basic-skeleton.g8

Ζ›πŸš€ Starting point if you want to bootstrap a project in Scala
Scala
14
star
87

from-monolith-to-microservices-using-api-gateway

CodelyTV Course
PHP
13
star
88

linting-js-ts-course

Linting js and ts course examples
HTML
12
star
89

no-branches

πŸ•Š GitHub Action to autoremove all branches
Shell
11
star
90

phpstorm-settings

Code and File Templates for PhpStorm following the PHP ecosystem conventions
PHP
11
star
91

eslint-plugin-no-default-parameters

A plugin that forbids the use of default parameters in functions, methods and constructors.
TypeScript
10
star
92

kotlin-introduction-course

Intro a Kotlin course examples
Kotlin
10
star
93

php-password_refactoring-kata

Ejercicio para practicar refactoring
PHP
10
star
94

csharp-finder_refactoring-kata

πŸ¦ˆπŸ”Incomprehensible Finder Refactoring Kata port for C#
C#
10
star
95

typescript-react_library-vite_template

Template for creating React libraries with TypeScript following best practices: Storybook for documentation, testing, Continuous Integration, and linting
TypeScript
8
star
96

scala-finder_refactoring-kata

Incomprehensible Finder Refactoring Kata Scala
Scala
8
star
97

cqrs-ddd-scala-example-deprecated

Repository moved to:
Scala
7
star
98

ddd_problems-domain_events_errors_handling-course

Examples of how to handle errors when publishing and consuming domain events
Java
7
star
99

css-selectors-best-practices-course

CSS course selector examples
HTML
7
star
100

elgato-key-light-air-gnome-extension

JavaScript
7
star