domain-driven-design
4
总安装量
2
周安装量
#54316
全站排名
安装命令
npx skills add https://github.com/svngoku/coding-agents-skills --skill domain-driven-design
Agent 安装分布
opencode
2
amp
1
kimi-cli
1
codex
1
github-copilot
1
antigravity
1
Skill 文档
Domain-Driven Design Skill
Apply DDD to build software that reflects deep understanding of the business domain.
Quick Reference
| Task | Reference |
|---|---|
| Bounded contexts, subdomains, context maps | strategic-design.md |
| Entities, value objects, aggregates, repositories | tactical-design.md |
| Hexagonal, CQRS, Event Sourcing, Clean Architecture | architecture-patterns.md |
| Event Storming facilitation & documentation | event-storming.md |
| Python implementations (Pydantic, SQLAlchemy, FastAPI) | python-patterns.md |
| TypeScript implementations (NestJS, TypeORM, Prisma) | typescript-patterns.md |
| DDD code review criteria | code-review.md |
Core Workflow
1. Identify the Task Type
Designing new system? â Start with strategic design, then tactical Refactoring existing code? â Assess current state, identify bounded contexts, refactor incrementally Generating scaffolding? â Determine patterns needed, generate code Event Storming? â Follow facilitation guide Code review? â Apply DDD checklist
2. Strategic Before Tactical
Always establish strategic design first:
- Identify subdomains (Core, Supporting, Generic)
- Define bounded contexts and their boundaries
- Map context relationships (upstream/downstream, conformist, ACL, etc.)
- Establish ubiquitous language per context
3. Select Architecture Pattern
Choose based on domain complexity and requirements:
| Pattern | When to Use |
|---|---|
| Layered | Simple CRUD, low complexity |
| Hexagonal | Need to isolate domain from infrastructure |
| Clean Architecture | Complex business rules, multiple delivery mechanisms |
| CQRS | Different read/write models, complex queries |
| Event Sourcing | Audit trail required, temporal queries, event-driven |
Patterns can be combined (e.g., Hexagonal + CQRS + Event Sourcing).
4. Apply Tactical Patterns
Select tactical building blocks based on needs:
| Building Block | Purpose |
|---|---|
| Entity | Identity matters, mutable, lifecycle |
| Value Object | Defined by attributes, immutable, no identity |
| Aggregate | Consistency boundary, transactional unit |
| Domain Service | Stateless operations spanning multiple aggregates |
| Repository | Collection-like interface for aggregate persistence |
| Domain Event | Record of something significant that happened |
| Factory | Complex object creation logic |
| Specification | Encapsulated business rules for querying/validation |
5. Implementation Guidelines
General principles:
- Domain layer has ZERO infrastructure dependencies
- Depend on abstractions (interfaces/protocols), not concretions
- One aggregate = one repository = one transaction
- Aggregates reference other aggregates by ID only
- Validate invariants within aggregate boundaries
- Use domain events for cross-aggregate communication
Language selection:
- Read python-patterns.md for Python with Pydantic, SQLAlchemy, FastAPI
- Read typescript-patterns.md for TypeScript with NestJS, TypeORM, Prisma
Project Structure Template
src/
âââ domain/ # Pure domain logic (no dependencies)
â âââ model/ # Entities, Value Objects, Aggregates
â âââ service/ # Domain Services
â âââ event/ # Domain Events
â âââ repository/ # Repository interfaces (ports)
â âââ specification/ # Business rule specifications
âââ application/ # Use cases, orchestration
â âââ command/ # Command handlers (write)
â âââ query/ # Query handlers (read)
â âââ dto/ # Data transfer objects
â âââ service/ # Application services
âââ infrastructure/ # External concerns
â âââ persistence/ # Repository implementations
â âââ messaging/ # Event bus, message queue
â âââ external/ # Third-party integrations
âââ interface/ # Delivery mechanisms
âââ api/ # REST/GraphQL controllers
âââ cli/ # Command-line interface
âââ event/ # Event consumers
Anti-Patterns to Avoid
- Anemic Domain Model: Entities with only getters/setters, logic in services
- God Aggregate: Too many entities in one aggregate
- Shared Kernel Abuse: Overusing shared code between contexts
- Infrastructure Leak: Database concerns in domain layer
- Missing Ubiquitous Language: Technical terms instead of domain terms
- Aggregate Reference by Object: Should reference by ID only
- Transaction Across Aggregates: Violates consistency boundaries
When NOT to Use DDD
DDD adds complexity. Avoid for:
- Simple CRUD applications
- Technical/infrastructure projects without complex business logic
- Prototypes or throwaway code
- Teams unfamiliar with the domain (learn domain first)
Use DDD when:
- Complex, evolving business logic
- Long-lived systems requiring maintainability
- Multiple teams working on related domains
- Domain experts available for collaboration