Domain-Driven Design Profile
Overview
Tactical DDD patterns for domain modeling. Includes Aggregates, Entities, Value Objects, Commands, Domain Services, Business Events, and Business Errors.
The Domain Driven Design (DDD) approach is a collection of rules and guidelines in order to model large and complex systems. Modelling refers to the representation of a real-world situation in which it is possible to visualize relationships and actions between different substances. Thus, making the ideation process and, later, the implementation process less painful and more organized by avoiding errors and misunderstandings.
In the DDD approach, the focus is on the core domain and the domain logic. A model is a distilled form of domain knowledge, assumptions, rules and choices. The DDD approach is also helpful in the implementation phase as it offers patterns and principals for building well-organized and delicate systems. Additionally, it provides a mutual way of communication between experts in different fields by defining a ubiquitous language within pre-specified contexts which are called bounded contexts.
A main concept of DDD is ubiquitous language. Ubiquitous language is a language structured around the domain model and is used by all team members. Bounded contexts refer to a group with similar characteristics that act in a similar way. In one system there could be more than one bounded context and these contexts can communicate with each other. A context map is an overview of several bounded contexts, their relationships and interfaces.
Model elements
| Id | Name | Description |
|---|---|---|
ddd.aggregate | Aggregate | A domain aggregate that groups related entities and value objects |
ddd.entity | Entity | A domain entity with a unique identity |
ddd.value-object | ValueObject | A value object without identity, defined by its attributes |
ddd.command | Command | A command that triggers an action or process in the domain |
ddd.domain-service | Domain service | A domain service that performs domain operations |
ddd.business-event | Business event | A business event that represents something that happened in the domain |
ddd.business-error | Business error | A business error or exception in the domain |
Relationships
| Id | Name | Description |
|---|---|---|
ddd.extends | extends | Indicates that an element extends another element |
ddd.triggers | triggers | Indicates that one element triggers a business logic element (command or domain service) |
ddd.publishes | publishes | Indicates that a business logic element (command or domain service) publishes a business event |
ddd.throws | throws | Indicates that a business logic element (command or domain service) throws a business error |
ddd.contains | contains | Indicates that an element contains another element |
Usage
Use Cases
The Domain-Driven Design profile can be used for (examples):
- Modeling complex business domains: Break down complex business logic into aggregates, entities, and value objects that reflect the ubiquitous language
- Defining bounded contexts: Clearly separate different domain contexts and their models to manage complexity in large systems
- Capturing domain events: Model business events that represent significant occurrences in the domain for event-driven architectures
- Designing command-driven workflows: Define commands that trigger business operations and their resulting events
- Implementing domain services: Model domain logic that doesn't naturally fit within entities or value objects
- Establishing ubiquitous language: Create a shared vocabulary between domain experts and developers through explicit domain modeling
- Managing business rules and errors: Document business constraints, validations, and error conditions within the domain model
- Facilitating domain-driven refactoring: Identify and refactor domain concepts to better align with business needs and reduce technical debt
Step-by-step guide
- Define Aggregates: Create Aggregate elements to group related entities and value objects
- Model Entities: Define Entity elements with unique identities within aggregates
- Create Value Objects: Model Value Object elements for attributes without identity
- Define Commands: Create Command elements that trigger domain actions
- Implement Domain Services: Define Domain Service elements for domain operations
- Model Business Events: Create Business Event elements for domain occurrences
- Document Business Errors: Define Business Error elements for domain exceptions
- Link Relationships: Use relationship types to connect elements (extends, triggers, publishes, throws, contains)
Reference
For the complete profile definition, see the ddd-profile-1.0.0.yaml file.