AgentSkillsCN

Ddd

DDD

SKILL.md

Domain-Driven Design Skill

Reference for domain modeling concepts from Eric Evans' "Domain-Driven Design: Tackling Complexity in the Heart of Software."

Activation Triggers

Use this skill when discussing:

  • Domain modeling and ubiquitous language
  • Bounded contexts and context mapping
  • Entities vs value objects
  • Aggregates and aggregate roots
  • Repository and factory patterns
  • Domain events and event storming
  • Anti-corruption layers

Quick Reference

Strategic DDD Patterns

PatternPurposeWhen to Use
Bounded ContextDefine clear boundariesDifferent teams, different models
Ubiquitous LanguageShared vocabularyAlways within a context
Context MapShow relationshipsMultiple bounded contexts
Anti-Corruption LayerProtect from external modelsIntegrating legacy/external systems

Tactical DDD Patterns

PatternCharacteristicsIdentity
EntityMutable, lifecycle, identity mattersHas unique ID
Value ObjectImmutable, no identity, equality by attributesNo ID needed
AggregateConsistency boundary, transactional unitHas aggregate root
Domain EventSomething that happened, immutableNamed in past tense

Building Blocks

BlockResponsibility
EntityModel with identity and lifecycle
Value ObjectDescribe characteristics
AggregateEnforce invariants, transactional boundary
RepositoryPersist and retrieve aggregates
FactoryComplex object creation
Domain ServiceStateless domain operations
Application ServiceOrchestrate use cases
Domain EventCapture something that happened

Context Mapping Relationships

RelationshipDescription
PartnershipTwo teams cooperate
Shared KernelShared subset of model
Customer-SupplierUpstream/downstream dependency
ConformistDownstream conforms to upstream
Anti-Corruption LayerTranslate between models
Open Host ServicePublished API for many consumers
Published LanguageWell-documented interchange format
Separate WaysNo integration

Aggregate Design Rules

  1. Protect invariants - Aggregate root enforces all rules
  2. Design for consistency - One aggregate per transaction
  3. Reference by identity - Don't hold direct references to other aggregates
  4. Use eventual consistency - Between aggregates, not within
  5. Keep aggregates small - Focused on true invariants

Entity vs Value Object Decision

code
Does identity matter beyond its attributes?
├── YES → Entity (e.g., User, Order, Product)
└── NO → Value Object (e.g., Address, Money, DateRange)

Will instances be shared?
├── YES → Entity (needs identity for references)
└── NO → Value Object (can be replaced/copied)

Directory Structure

code
ddd/
├── SKILL.md
├── strategic/
│   ├── ubiquitous-language.md
│   ├── bounded-contexts.md
│   ├── context-mapping.md
│   └── anti-corruption-layer.md
├── tactical/
│   ├── entities.md
│   ├── value-objects.md
│   ├── aggregates.md
│   ├── domain-services.md
│   └── domain-events.md
├── patterns/
│   ├── repositories.md
│   ├── factories.md
│   └── specifications.md
└── practices/
    ├── event-storming.md
    └── model-exploration.md

Usage Examples

Modeling a Domain

code
Question: "How should I model orders?"

Consider:
1. Define Ubiquitous Language - See strategic/ubiquitous-language.md
2. Identify Entities vs Value Objects - See tactical/
3. Find Aggregates - See tactical/aggregates.md
4. Design Repositories - See patterns/repositories.md

Integrating Systems

code
Question: "How do I integrate with legacy system?"

Consider:
- Define Bounded Context boundary
- Use Anti-Corruption Layer
- Map contexts with Context Map

Based on concepts from "Domain-Driven Design" by Eric Evans.