name: domain-driven-design description: This skill should be used when designing software architecture, modeling domains, reviewing code for DDD compliance, identifying bounded contexts, designing aggregates, or discussing strategic and tactical DDD patterns. Provides comprehensive Domain-Driven Design principles, axioms, heuristics, and anti-patterns for building maintainable, domain-centric software systems.
Domain-Driven Design (DDD) is an approach to software development that centers the design on the core business domain. This skill provides principles, patterns, and heuristics for both strategic design (system boundaries and relationships) and tactical design (code-level patterns).
Software exists to solve domain problems. Technical decisions serve the domain, not vice versa. When technical elegance conflicts with domain clarity, domain clarity wins.
The ubiquitous language shapes how teams think about the domain. Ambiguous language creates ambiguous software. Invest heavily in precise terminology.
Explicit boundaries (bounded contexts) allow teams to evolve independently. The cost of integration is worth the benefit of isolation.
No model captures all domain complexity. Accept that models simplify reality. Refine models continuously as understanding deepens.
| Pattern | Purpose | Key Heuristic |
|---|---|---|
| Bounded Context | Define linguistic/model boundaries | One team, one language, one model |
| Context Map | Document context relationships | Make implicit integrations explicit |
| Subdomain | Classify domain areas by value | Core (invest), Supporting (adequate), Generic (outsource) |
| Ubiquitous Language | Shared vocabulary | If experts don't use the term, neither should code |
For detailed strategic patterns, consult references/strategic-patterns.md.
| Pattern | Purpose | Key Heuristic |
|---|---|---|
| Entity | Identity-tracked object | "Same identity = same thing" regardless of attributes |
| Value Object | Immutable, identity-less | Equality by value, always immutable, self-validating |
| Aggregate | Consistency boundary | Small aggregates, reference by ID, one transaction = one aggregate |
| Domain Event | Record state changes | Past tense naming, immutable, contains all relevant data |
| Repository | Collection abstraction | One per aggregate root, domain-focused interface |
| Domain Service | Stateless operations | When logic doesn't belong to any single entity |
| Factory | Complex object creation | When construction logic is complex or variable |
For detailed tactical patterns, consult references/tactical-patterns.md.
Does this thing have a lifecycle and identity that matters?
├─ YES → Is identity based on an ID (not attributes)?
│ ├─ YES → Entity
│ └─ NO → Reconsider; might be Value Object with natural key
└─ NO → Value Object
Is this logic stateless?
├─ NO → Does it belong to a single aggregate?
│ ├─ YES → Method on the aggregate/entity
│ └─ NO → Reconsider aggregate boundaries
└─ YES → Does it coordinate multiple aggregates?
├─ YES → Application Service
└─ NO → Does it represent a domain concept?
├─ YES → Domain Service
└─ NO → Infrastructure Service
Do different stakeholders use different language for this?
├─ YES → Separate bounded context
└─ NO → Does a different team own this?
├─ YES → Separate bounded context
└─ NO → Would a separate model reduce complexity?
├─ YES → Consider separation (but weigh integration cost)
└─ NO → Keep in current context
| Anti-Pattern | Description | Fix |
|---|---|---|
| Anemic Domain Model | Entities with only getters/setters | Move behavior into domain objects |
| Big Ball of Mud | No clear boundaries | Identify bounded contexts |
| Smart UI | Business logic in presentation layer | Extract domain layer |
| Database-Driven Design | Model follows database schema | Model follows domain, map to database |
| Leaky Abstractions | Infrastructure concerns in domain | Dependency inversion, ports and adapters |
| God Aggregate | One aggregate does everything | Split by invariant boundaries |
| Premature Abstraction | Abstracting before understanding | Concrete first, abstract when patterns emerge |
For detailed anti-patterns and remediation, consult references/anti-patterns.md.
When implementing DDD in a codebase:
strategic-patterns.md - Detailed strategic DDD patterns including bounded contexts, context maps, subdomain classification, and ubiquitous languagetactical-patterns.md - Detailed tactical DDD patterns including entities, value objects, aggregates, domain events, repositories, and servicesanti-patterns.md - Common DDD anti-patterns, how to identify them, and remediation strategiesTo search references for specific topics:
grep -i "bounded context" references/grep -i "aggregate" references/grep -i "value object" references/