{"id":18056290,"url":"https://github.com/monteiro/ddd-bundle","last_synced_at":"2025-04-11T02:07:17.607Z","repository":{"id":211951537,"uuid":"730347601","full_name":"monteiro/ddd-bundle","owner":"monteiro","description":"Every class you need to start applying DDD to your project the easy way.","archived":false,"fork":false,"pushed_at":"2023-12-23T15:39:41.000Z","size":85,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T02:07:11.822Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/monteiro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-11T18:15:46.000Z","updated_at":"2024-01-10T09:36:51.000Z","dependencies_parsed_at":"2023-12-23T09:39:42.093Z","dependency_job_id":null,"html_url":"https://github.com/monteiro/ddd-bundle","commit_stats":null,"previous_names":["monteiro/ddd-bundle"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monteiro%2Fddd-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monteiro%2Fddd-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monteiro%2Fddd-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monteiro%2Fddd-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/monteiro","download_url":"https://codeload.github.com/monteiro/ddd-bundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248328167,"owners_count":21085261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-31T01:14:33.857Z","updated_at":"2025-04-11T02:07:17.574Z","avatar_url":"https://github.com/monteiro.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DDD-Bundle\n\n\n## Introduction\n\nWhen I started to learn about DDD, I found a lot of information about the theory, but not a lot of examples.\nI decided to create this bundle to show how I would implement a DDD application using Symfony. \n\nIt is very easy to be purist and decouple everything, but I think it is important to find the right balance between the power\nof the framework, and the decoupling of the application.\n\nWhat we want to achieve with this bundle?\n\n- How to publish domain events inside your entities (can be doctrine entities or not). We want to use doctrine to avoid having to implement our own hydrators.\n- How to consume domain events in a different context (e.g. another microservice or the same service). The mindset\nchanges when you start on your application using domain events. You want to react to those domain events.\n- Have interfaces for domain events that will allow to save them in the database (following the outbox pattern).\n- Have a separated repository that will use this bundle to test all the behavior in a realtime application.\n\n## Install\n\nIn order to install we need to execute the following commands:\n\n```bash\ncomposer require monteiro/ddd-bundle\nbin/console make:migration\nbin/console doctrine:migrations:migrate\n```\nThe migration is needed because we will create the \"event_store\" table which will store all the events published by the entities.\n\n## Usage\n\n### Publishing domain events\n\nWhen we save a change in an entity, normally we notify other services or handlers that something happened.\nWe save the event in the database in an event store table, and then we publish the event to the message bus.\n\nThe console command used to publish the domain events to the message bus (e.g. rabbitmq, kafka, doctrine, etc) is:\n\n```bash\nbin/console ddd:domain:events:publish\n```\n\n### Consuming domain events\n\nIn order to consume domain events published by other services, you need to create a handler.\nThe best component for this will be the messenger component. You can create a handler to be consumed for the domain event.\n\nExample of a messenger.yaml configuration:\n\n```yaml\nframework:\n    messenger:        \n        default_bus: command.bus\n        buses:\n            command.bus:\n                middleware:\n                  - doctrine_transaction\n            event.bus:\n                # the 'allow_no_handlers' middleware allows to have no handler                \n                default_middleware: allow_no_handlers\n        transports:          \n            async: '%env(MESSENGER_TRANSPORT_DSN)%'\n            failed: 'doctrine://default?queue_name=failed'\n            sync: 'sync://'\n\n        routing:\n            App\\RentCar\\Domain\\Model\\Car\\CarWasCreated: async\n            App\\RentCar\\Domain\\Model\\Customer\\CustomerWasCreated: async\n            App\\RentCar\\Domain\\Model\\Reservation\\ReservationWasCreated: async\n            App\\RentCar\\Domain\\Model\\Reservation\\ReservationWasCancelled: async\n```\n\n## Demo project\n\nYou can try out the demo project: https://github.com/monteiro/rent-car-ddd\nWhich uses the bundle and has some common DDD pattern examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonteiro%2Fddd-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmonteiro%2Fddd-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonteiro%2Fddd-bundle/lists"}