Skip to main content

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

IdNameDescription
ddd.aggregateAggregateA domain aggregate that groups related entities and value objects
ddd.entityEntityA domain entity with a unique identity
ddd.value-objectValueObjectA value object without identity, defined by its attributes
ddd.commandCommandA command that triggers an action or process in the domain
ddd.domain-serviceDomain serviceA domain service that performs domain operations
ddd.business-eventBusiness eventA business event that represents something that happened in the domain
ddd.business-errorBusiness errorA business error or exception in the domain

Relationships

IdNameDescription
ddd.extendsextendsIndicates that an element extends another element
ddd.triggerstriggersIndicates that one element triggers a business logic element (command or domain service)
ddd.publishespublishesIndicates that a business logic element (command or domain service) publishes a business event
ddd.throwsthrowsIndicates that a business logic element (command or domain service) throws a business error
ddd.containscontainsIndicates 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

  1. Define Aggregates: Create Aggregate elements to group related entities and value objects
  2. Model Entities: Define Entity elements with unique identities within aggregates
  3. Create Value Objects: Model Value Object elements for attributes without identity
  4. Define Commands: Create Command elements that trigger domain actions
  5. Implement Domain Services: Define Domain Service elements for domain operations
  6. Model Business Events: Create Business Event elements for domain occurrences
  7. Document Business Errors: Define Business Error elements for domain exceptions
  8. 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.