GithubHelp home page GithubHelp logo

gtatorrez / php-ddd-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codelytv/php-ddd-example

0.0 1.0 0.0 1.68 MB

🐘🎯 Hexagonal Architecture + DDD + CQRS applied in PHP using Symfony 4

Home Page: http://codely.tv/screencasts/codigo-acoplado-framework-microservicios-ddd/

License: MIT License

PHP 97.41% Gherkin 1.39% Shell 0.51% Dockerfile 0.16% Makefile 0.51% TSQL 0.02%

php-ddd-example's Introduction

🐘🎯 Hexagonal Architecture, DDD & CQRS in PHP Symfony

codely.tv CodelyTV Courses Symfony 4.2 CircleCI Status

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

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

πŸ› οΈ Environment configuration

  1. Copy the default environment variables: cp .env.dist .env
  2. Modify the environment variables if needed: vim .env
  3. 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

  1. Install PHP dependencies and bring up the project Docker containers with Docker Compose: make build
  2. Go to the API health check page

βœ… Tests execution

  1. Install PHP dependencies if you haven't done so: make deps
  2. 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.

  1. Sync using the Symfony Message Bus
  2. Async using a local file

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:

php-ddd-example's People

Contributors

gabrielfs7 avatar javiercane avatar mangelsnc avatar micperr avatar nidble avatar pana1990 avatar patrick-mota avatar rgomezcasas avatar sdecandelario avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.