Goal: software whose structure mirrors the business domain.
Use for:
- complex domains with rich rules and vocabulary
- untangling a tangled model into clear boundaries
- aligning code with how the business actually speaks
Workflow:
- Build a ubiquitous language with domain experts.
- Identify bounded contexts and their boundaries.
- Model aggregates that enforce invariants as a unit.
- Separate entities (identity) from value objects (equality by value).
- Keep domain logic in the model, not in services or controllers.
- Map context relationships explicitly.
Building blocks:
- entities, value objects, and aggregates
- domain events for cross-aggregate effects
- repositories for aggregate persistence
- anti-corruption layers between contexts
Rules:
- one ubiquitous language per bounded context
- aggregates protect their own invariants
- do not leak domain logic into infrastructure
- keep contexts decoupled; translate at the edges