Domain-Driven Design
Use DDD to make important domain behavior explicit, correctly named, and
protected from infrastructure concerns. Apply it where the domain has enough
business meaning to justify modeling; do not turn simple CRUD or unclear ideas
into ceremony prematurely.
When to Use
Use DDD when the work involves:
- Business rules, invariants, lifecycle transitions, policies, permissions, or
workflows that need durable names.
- Multiple concepts that are easy to confuse without a shared vocabulary.
- Internal logic whose correctness matters beyond a single endpoint, UI screen,
job, or database query.
- Refactoring modules so domain behavior is easier to test and maintain.
- Breaking changes that improve domain clarity and the project does not require
backwards compatibility.
Avoid heavy DDD when:
- The change is a simple adapter, presentation tweak, migration, or one-off
script with little domain behavior.
- The domain language is not yet known; start with simple code and preserve
refactoring room.
- Introducing aggregates, repositories, or events would create abstractions with
no current rule to protect.
For photo/video catalog work, use
digital-asset-management to establish
the media lifecycle vocabulary before choosing bounded contexts or aggregates.
Workflow
Discover the language.
- Extract nouns, verbs, states, roles, and constraints from the user request,
existing tests, docs, logs, UI copy, APIs, and database names.
- Prefer terms used by domain experts and product behavior over technical
convenience names.
- Record ambiguities as questions or assumptions before encoding them.
Find the boundaries.
- Identify the domain and subdomains involved.
- Look for bounded contexts where the same word means different things or
where rules change by workflow, team, product area, or integration.
- Keep context boundaries visible in module names, APIs, tests, and docs when
they affect maintainability.
Choose tactical patterns only where they earn their keep.
- Entity: has identity and continuity across changes.
- Value object: immutable descriptive value whose equality is by value.
- Aggregate: consistency boundary that protects invariants through one root.
- Repository: collection-like access to aggregates, hiding persistence shape.
- Domain service: stateless domain operation that does not belong on one
entity or value object.
- Policy/specification: named decision rule that may vary independently.
- Domain event: fact that something meaningful already happened in the
domain.
Separate domain from delivery and storage.
- Put invariants and decisions in domain types or services, not controllers,
resolvers, UI components, SQL snippets, serializers, or job handlers.
- Let infrastructure translate into and out of domain concepts.
- Keep persistence models separate from domain models when storage shape would
leak or weaken invariants.
- Do not let framework types become part of the core domain API unless the
project intentionally treats them as domain primitives.
Preserve behavior through tests.
- Test invariants, transitions, policies, and domain events at the narrowest
useful level.
- Use integration tests for repository mappings and boundary contracts.
- Prefer behavior names in tests over implementation names.
Implement with the matching mechanics.
- When implementation begins, load the matching language engineering skill and
any data skill needed for persistence, schema, query, or transaction work.
Review And Verification
DDD remains discovery, design, and refactor guidance. For a focused tactical
model audit, load domain-modeling with
code-review and
review-verification-protocol.
Before reporting implementation or refactor work complete, run focused checks for
the changed behavior, invariants, and boundary mappings; then run broader
repository checks when the change warrants them. Report failed or skipped checks
and residual domain, boundary, or migration risk.
Relationship To Architecture Skills
DDD helps define what belongs inside the business-centered core; Hexagonal
Architecture, Clean Architecture, and Onion Architecture help keep that core
isolated from external mechanisms. Load
hexagonal-architecture when domain
modeling turns into decisions about ports, adapters, external actors, or
headless core tests. Load
clean-architecture when use cases,
interactors, presenters, and interface-adapter responsibilities are the main
design issue. Load onion-architecture when
domain/application rings around a protected domain model are the clearest
framing.
- Repositories in DDD are collection-like access to aggregates; in a hexagonal
design they are usually outbound ports implemented by persistence adapters, not
generic database helper layers.
- Application services/use cases orchestrate workflows around domain objects;
they should not absorb invariants that belong on entities, value objects,
aggregates, or domain services.
- These architectures are optional. Keep simple CRUD, one-off scripts, and
immature domains simpler until real boundaries, testability needs, or
infrastructure leakage justify extra layers.
Modeling Guidance
- Make invalid states unrepresentable when the language and type system allow it.
- Name operations after domain actions, not data mutations: prefer
accept_invitation over update_invitation_status when acceptance has rules.
- Keep aggregates small; do not load a whole graph just because objects are
related.
- Use domain events for meaningful facts, not as generic callbacks.
- Let module boundaries follow cohesive behavior, not database tables by
default.
- Refactor toward clearer bounded contexts incrementally when it improves tests,
naming, or ownership.
Ubiquitous Language Checklist
- Domain terms are consistent across code, tests, API names, docs, and UI copy
where they describe the same concept.
- Different meanings use different names, even if legacy code conflates them.
- Public errors and validation messages explain domain rules in user-relevant
language.
- New abstractions protect real invariants or decisions.
- Infrastructure names do not replace domain names in core logic.
Common Pitfalls
- Anemic models: entities that only store data while services or handlers hold
all domain decisions.
- Pattern cargo culting: repositories, events, factories, or aggregates added
before there is behavior for them to protect.
- Leaky persistence: database IDs, joins, or ORM constraints dictating domain
language without a domain reason.
- Over-preserving compatibility: keeping misleading names or boundaries when the
project allows breaking changes and clarity is worth the migration.
1---2name: domain-driven-design3description: Apply Domain-Driven Design to complex business logic and module boundaries. Use when modeling domains, bounded contexts, aggregates, value objects, repositories, domain services, policies, domain events, ubiquitous language, or refactoring toward clearer domain behavior. Do not use for focused audits of an existing domain model; use domain-modeling. Avoid simple CRUD or data-centric work without meaningful domain pressure.4---56# Domain-Driven Design78Use DDD to make important domain behavior explicit, correctly named, and9protected from infrastructure concerns. Apply it where the domain has enough10business meaning to justify modeling; do not turn simple CRUD or unclear ideas11into ceremony prematurely.1213## When to Use1415Use DDD when the work involves:1617- Business rules, invariants, lifecycle transitions, policies, permissions, or18 workflows that need durable names.19- Multiple concepts that are easy to confuse without a shared vocabulary.20- Internal logic whose correctness matters beyond a single endpoint, UI screen,21 job, or database query.22- Refactoring modules so domain behavior is easier to test and maintain.23- Breaking changes that improve domain clarity and the project does not require24 backwards compatibility.2526Avoid heavy DDD when:2728- The change is a simple adapter, presentation tweak, migration, or one-off29 script with little domain behavior.30- The domain language is not yet known; start with simple code and preserve31 refactoring room.32- Introducing aggregates, repositories, or events would create abstractions with33 no current rule to protect.3435For photo/video catalog work, use36[`digital-asset-management`](../digital-asset-management/SKILL.md) to establish37the media lifecycle vocabulary before choosing bounded contexts or aggregates.3839## Workflow40411. Discover the language.42 - Extract nouns, verbs, states, roles, and constraints from the user request,43 existing tests, docs, logs, UI copy, APIs, and database names.44 - Prefer terms used by domain experts and product behavior over technical45 convenience names.46 - Record ambiguities as questions or assumptions before encoding them.47482. Find the boundaries.49 - Identify the domain and subdomains involved.50 - Look for bounded contexts where the same word means different things or51 where rules change by workflow, team, product area, or integration.52 - Keep context boundaries visible in module names, APIs, tests, and docs when53 they affect maintainability.54553. Choose tactical patterns only where they earn their keep.56 - Entity: has identity and continuity across changes.57 - Value object: immutable descriptive value whose equality is by value.58 - Aggregate: consistency boundary that protects invariants through one root.59 - Repository: collection-like access to aggregates, hiding persistence shape.60 - Domain service: stateless domain operation that does not belong on one61 entity or value object.62 - Policy/specification: named decision rule that may vary independently.63 - Domain event: fact that something meaningful already happened in the64 domain.65664. Separate domain from delivery and storage.67 - Put invariants and decisions in domain types or services, not controllers,68 resolvers, UI components, SQL snippets, serializers, or job handlers.69 - Let infrastructure translate into and out of domain concepts.70 - Keep persistence models separate from domain models when storage shape would71 leak or weaken invariants.72 - Do not let framework types become part of the core domain API unless the73 project intentionally treats them as domain primitives.74755. Preserve behavior through tests.76 - Test invariants, transitions, policies, and domain events at the narrowest77 useful level.78 - Use integration tests for repository mappings and boundary contracts.79 - Prefer behavior names in tests over implementation names.80816. Implement with the matching mechanics.82 - When implementation begins, load the matching language engineering skill and83 any data skill needed for persistence, schema, query, or transaction work.8485## Review And Verification8687DDD remains discovery, design, and refactor guidance. For a focused tactical88model audit, load [`domain-modeling`](../domain-modeling/SKILL.md) with89[`code-review`](../code-review/SKILL.md) and90[`review-verification-protocol`](../review-verification-protocol/SKILL.md).9192Before reporting implementation or refactor work complete, run focused checks for93the changed behavior, invariants, and boundary mappings; then run broader94repository checks when the change warrants them. Report failed or skipped checks95and residual domain, boundary, or migration risk.9697## Relationship To Architecture Skills9899DDD helps define what belongs inside the business-centered core; Hexagonal100Architecture, Clean Architecture, and Onion Architecture help keep that core101isolated from external mechanisms. Load102[`hexagonal-architecture`](../hexagonal-architecture/SKILL.md) when domain103modeling turns into decisions about ports, adapters, external actors, or104headless core tests. Load105[`clean-architecture`](../clean-architecture/SKILL.md) when use cases,106interactors, presenters, and interface-adapter responsibilities are the main107design issue. Load [`onion-architecture`](../onion-architecture/SKILL.md) when108domain/application rings around a protected domain model are the clearest109framing.110111- Repositories in DDD are collection-like access to aggregates; in a hexagonal112 design they are usually outbound ports implemented by persistence adapters, not113 generic database helper layers.114- Application services/use cases orchestrate workflows around domain objects;115 they should not absorb invariants that belong on entities, value objects,116 aggregates, or domain services.117- These architectures are optional. Keep simple CRUD, one-off scripts, and118 immature domains simpler until real boundaries, testability needs, or119 infrastructure leakage justify extra layers.120121## Modeling Guidance122123- Make invalid states unrepresentable when the language and type system allow it.124- Name operations after domain actions, not data mutations: prefer125 `accept_invitation` over `update_invitation_status` when acceptance has rules.126- Keep aggregates small; do not load a whole graph just because objects are127 related.128- Use domain events for meaningful facts, not as generic callbacks.129- Let module boundaries follow cohesive behavior, not database tables by130 default.131- Refactor toward clearer bounded contexts incrementally when it improves tests,132 naming, or ownership.133134## Ubiquitous Language Checklist135136- Domain terms are consistent across code, tests, API names, docs, and UI copy137 where they describe the same concept.138- Different meanings use different names, even if legacy code conflates them.139- Public errors and validation messages explain domain rules in user-relevant140 language.141- New abstractions protect real invariants or decisions.142- Infrastructure names do not replace domain names in core logic.143144## Common Pitfalls145146- Anemic models: entities that only store data while services or handlers hold147 all domain decisions.148- Pattern cargo culting: repositories, events, factories, or aggregates added149 before there is behavior for them to protect.150- Leaky persistence: database IDs, joins, or ORM constraints dictating domain151 language without a domain reason.152- Over-preserving compatibility: keeping misleading names or boundaries when the153 project allows breaking changes and clarity is worth the migration.