{"id":22284098,"url":"https://github.com/bwaidelich/dcb-example-courses","last_synced_at":"2025-07-28T21:33:18.035Z","repository":{"id":172785175,"uuid":"649639349","full_name":"bwaidelich/dcb-example-courses","owner":"bwaidelich","description":"Simple example for the Dynamic Consistency Boundary pattern described by Sara Pellegrini","archived":false,"fork":false,"pushed_at":"2023-08-30T15:47:24.000Z","size":98,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-13T16:11:11.993Z","etag":null,"topics":["dcb","ddd","domaindrivendesign","dynamicconsistencyboundary","eventsourcing"],"latest_commit_sha":null,"homepage":"","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/bwaidelich.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["bwaidelich"],"custom":["https://www.paypal.me/bwaidelich"]}},"created_at":"2023-06-05T10:11:21.000Z","updated_at":"2024-03-28T12:26:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"26ae146c-0b37-4692-bebf-22879cd0aeeb","html_url":"https://github.com/bwaidelich/dcb-example-courses","commit_stats":null,"previous_names":["bwaidelich/dcb-example","bwaidelich/dcb-example-courses"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwaidelich%2Fdcb-example-courses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwaidelich%2Fdcb-example-courses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwaidelich%2Fdcb-example-courses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwaidelich%2Fdcb-example-courses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bwaidelich","download_url":"https://codeload.github.com/bwaidelich/dcb-example-courses/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227960999,"owners_count":17847824,"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":["dcb","ddd","domaindrivendesign","dynamicconsistencyboundary","eventsourcing"],"created_at":"2024-12-03T16:43:59.369Z","updated_at":"2025-07-28T21:33:18.008Z","avatar_url":"https://github.com/bwaidelich.png","language":"PHP","funding_links":["https://github.com/sponsors/bwaidelich","https://www.paypal.me/bwaidelich"],"categories":[],"sub_categories":[],"readme":"# Dynamic Consistency Boundary Example\n\nSimple example for the Dynamic Consistency Boundary pattern [described by Sara Pellegrini](https://sara.event-thinking.io/2023/04/kill-aggregate-chapter-1-I-am-here-to-kill-the-aggregate.html).\n\nThe purpose of this package is to explore the idea, find potential pitfalls and to spread the word.\n\n**tl;dr** Have a look at the [example script](index.php) or [Behat Tests](tests/Behat) to see this in action.\n\n## Background\n\nDynamic Consistency Boundary (aka DCB) allow to enforce hard constraints in Event-Sourced systems without having to rely on individual Event Streams.\nThis facilitates focussing on the _behavior_ of the Domain Model rather than on its rigid structure. It also allows for simpler architecture and potential\nperformance improvements as multiple projections can act on the same events without requiring synchronization.\n\nRead all about this interesting approach in the blog post mentioned above or watch Saras talk on [YouTube](https://www.youtube.com/watch?v=DhhxKoOpJe0\u0026t=150s) (Italian with English subtitles).\nThis package models the example of this presentation (with a few deviations) using the [wwwision/dcb-eventstore](https://github.com/bwaidelich/dcb-eventstore) package and the [wwwision/dcb-eventstore-doctrine](https://github.com/bwaidelich/dcb-eventstore-doctrine) database adapter.\n\n### Important Classes / Concepts\n\n* [Commands](src%2FCommand) are just a concept of this example package. They implement the [Command Marker Interface](src%2FCommand%2FCommand.php)\n* The [CommandHandler](src/CommandHandler.php) is the central authority, handling and verifying incoming Command\n* It uses in-memory [Projections](src%2FProjection%2FProjection.php) to enforce hard constraints\n* For each command handler a [DecisionModel](src%2FDecisionModel%2FDecisionModel.php) instance is built that contains the state of those in-memory projections and the [AppendCondition](https://github.com/bwaidelich/dcb-eventstore/blob/main/Specification.md#AppendCondition) for new events\n* The [EventSerializer](src%2FEventSerializer.php) can convert [DomainEvent](src%2FEvent%2DDomainEvent.php) instances to writable events, vice versa\n* *Note:* This package contains no Read Model (i.e. classic projections) yet\n\n### Considerations / Findings\n\nI always had the feeling, that the focus on Event Streams is a distraction to Domain-driven design. So I was very happy to come across this concept.\nIn the meantime I have had the chance to test it in multiple real world scenarios, and it works really well for me and simplifies things (in spite of some minor caveats in the current implementation):\n\n* It becomes trivial to enforce constraints involving multiple entities (like in this example).\n* Global uniqueness (aka \"the unique username problem\") can easily be achieved with DCB\n* Consecutive sequences (e.g. invoice number) can be done without reservation patterns and by only reading a single event per constraint check\n* When using composition like in this example, phe in-memory projections are surprisingly small because they focus on a single responsibility\n* ...and more\n\n## Usage\n\nInstall via [composer](https://getcomposer.org):\n\n```shell\ncomposer create-project wwwision/dcb-example-courses\n```\n\nNow you should be able to run the [example script](index.php) via\n\n```shell\nphp dcb-example-courses/index.php\n```\n\nAnd you should get ...no output at all. That's because the example script currently satisfy all constraints.\nTry changing the script to test, that the business rules are actually enforced, for example you could add the line:\n\n```php\n$commandHandler-\u003ehandle(SubscribeStudentToCourse::create(courseId: 'c1', studentId: 's2'));\n```\n\nto the end of the file, which should lead to the following exception:\n\n```\nFailed to subscribe student with id \"s2\" to course with id \"c1\" because a student with that id does not exist\n```\n\nAlternatively, you could have a look at the [Behat Tests](tests/Behat):\n\n## Tests\n\nThis package comes with 16 Behat scenarios covering all business features.\nYou can run the tests via\n\n```shell\ncomposer test:behat\n```\n\n## Acknowledgment\n\nMost of the implementation of these packages are based on the great groundwork done by [Sara Pellegrini](https://sara.event-thinking.io/), so all praise belong to her!\n\n## Contributions\n\nI'm really curious to get feedback on this one.\nFeel free to start/join a [discussion](https://github.com/bwaidelich/dcb-example/discussions), [issues](https://github.com/bwaidelich/dcb-example/issues) or [Pull requests](https://github.com/bwaidelich/dcb-example/pulls).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwaidelich%2Fdcb-example-courses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbwaidelich%2Fdcb-example-courses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwaidelich%2Fdcb-example-courses/lists"}