Git Product home page Git Product logo

ddd-cqrs-example's Introduction

About

This is an example of implementation and my vision of practical CQRS, DDD, ADR, hexagonal architecture and directory structure. Project has entities Task and User. All UI is the REST endpoints.

What is done

  • Hexagonal Architecture (Ports directory for external endpoints)
  • CQRS (based on symfony messenger component command/query buses with middlewares)
  • DDD: directory structure (used sensiolabs-de/deptrac to control layers dependencies)
  • DDD: core bounded context
  • DDD: domain events implementation
  • DDD: example of specification in User entity that requires a db query

To do

  • Add another bounded context
  • Add anti-corruption layer for interaction between contexts

My assumptions

  • I placed entities public getters and private setters into the traits with *GS suffix to make entities a little bit clear (phpstorm tracks fine all references to entity classes) anyway you can put getters with setters in the same class
  • Unfortunately mysql has a poor performance with primary uuids. Of course prefer application generated uuid if database supports them.

How to install the project

  • bash setup_env.sh dev - to setup .env.local docker/.env
  • make dc_up - docker-compose up
  • make setup_dev - composer install, migrations and so on
  • make run php bin/console app:create-user - create a user
  • http://127.0.0.1:888/api/doc https://127.0.0.1:444/api/doc - api doc

Some words about docker

In project is used workplace container for code manipulations, CI or building. It was created for preventing of pollution of working containers (php-fpm) of unused in request, building tools like nodejs, composer, dev libs and so on. Also was created a local user based on host machine user PUID PGID to resolve conflicts with file permissions.

make dev - jump into workplace container

CI

make dev
//in container execute
make analyze

Implementation

Used symfony messenger component to create transactional command bus, query bus and event bus. Query model represented by DTOs. Domain and Command layers are covered by unit tests.

├── Core (Core bounded context)
│   ├── Application
│   │   ├── Command
│   │   │   ├── AuthToken
│   │   │   ├── Task
│   │   │   └── User
│   │   ├── Query
│   │       └── Task
│   ├── Domain
│   │   └── Model
│   │       ├── Task
│   │       └── User
│   ├── Infrastructure
│   │   └── Repository
│   └── Ports
│       ├── Cli
│       └── Rest
└── Shared
    ├── Domain
    └── Infrastructure

ddd-cqrs-example's People

Contributors

ferrius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ddd-cqrs-example's Issues

Separate the domain model and persistence layer

Hi,

I have a design-related question, As I know about DDD and some sources I read, most people indicate separations between domain and persistence (or infrastructure in general). Most people use Doctrine ORM when they consider the DDD approach in PHP, domain models (or Entities) are a part of domain, so they have no idea about persistence.

Let's imagine we have an Author domain model that publishes posts, I thought below code:

class Post
{
    public function __construct(
        protected Author $author,
        protected PostTitle $title,
        protected PostContent $content,
        protected DateTimeImmutable $publishedAt
    ) {}
}

class Author
{
    public function __construct(
        protected AuthorEmail $email,
        protected array $posts = []
    ) {}

    public function publishNewPost(Post $post)
    {
        $this->posts []= $posts;
    }
}

I fact, what I want is I could use the Post and Author classes as domain models without any persistence concern (doctrine annotations/ArrayCollection class/...). I'd like to separate Doctrine's entity from domain models and I don't know what should I do. Could you help me, please?

On macos x `setup_env.sh` fails because of different `sed` behavior

On macosx (zsh) setup_envs.sh fails with error

sed: 1: ".env.local": invalid command code .

In this SO https://stackoverflow.com/questions/19456518/invalid-command-code-despite-escaping-periods-using-sed recommended to add '' -e after sed -i in case when sed commandd fails on period (like .env.local I suppose).

I fixed this in this way (for all sed's) and this working wor me:

sed -i '' -e "s/^APP_ENV=.*/APP_ENV=${APP_ENV}/g" .env.local && \
...

Can you test it on linux and apply patch if it also works fine?

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.