Implement DDD-based architecture with domain, application, infrastructure, and API layers. Includes user/role management with authentication, RBAC permissions, audit logging, Liquibase migrations, and test suite.
6.1 KiB
DDD Implementation Skill
A Claude Code skill that acts as a Senior DDD Developer, implementing domain-driven code following Clean Architecture principles.
What This Skill Does
This skill helps you implement DDD code that follows established patterns and rules:
✅ Aggregates - With proper invariant enforcement and Result types ✅ Entities - Child entities within aggregates ✅ Value Objects - Immutable, self-validating ✅ Use Cases - In application layer with proper error handling ✅ Repositories - Interfaces in domain, implementations in infrastructure ✅ Domain Events - For cross-aggregate communication
When to Use This Skill
Use /ddd-implement when:
- You have a domain model designed (from
/ddd-model) - You need to implement specific aggregates, entities, or value objects
- You want code that follows DDD rules automatically
- You need proper error handling (Result types for Java, errors for Go)
- You want layer boundaries respected
Don't use this skill for:
- Domain modeling and design (use
/ddd-modelinstead) - Generic coding tasks (use default Claude Code)
- Non-DDD projects
Usage Examples
Implement an Aggregate
/ddd-implement --lang=java "Implement Order aggregate with addLineItem, removeLineItem, and cancel methods"
The skill will:
- Create the aggregate in
domain/order/ - Add proper invariants (e.g., "Cannot modify cancelled order")
- Use Result types for error handling
- Implement sealed interfaces for errors
- Add domain events (OrderCreated, OrderCancelled, etc.)
Implement a Use Case
/ddd-implement --lang=go "Implement PlaceOrder use case that creates an order and reserves inventory"
The skill will:
- Create use case in
application/order/ - Use repository interfaces (not implementations)
- Handle errors properly
- Return DTOs (not domain objects)
- Add transaction boundaries if needed
Implement a Repository
/ddd-implement --lang=java "Implement PostgreSQL repository for Order aggregate"
The skill will:
- Create implementation in
infrastructure/order/persistence/ - Implement the domain interface
- Add exception boundary (catch SQL exceptions → return domain errors)
- Map between domain model and database schema
Implement from Existing File
/ddd-implement internal/domain/account/account.go
The skill will:
- Detect language from file extension
- Read existing code
- Suggest improvements or complete partial implementations
- Follow established patterns in the file
What Makes This Skill Different
Enforces DDD Rules Automatically
The skill knows and enforces:
- Aggregate boundaries (no direct aggregate-to-aggregate references)
- Invariant documentation and enforcement
- Entity equality (ID-based only)
- Value Object immutability
- Repository patterns (interface in domain, impl in infrastructure)
- Layer dependencies (domain has no external deps)
Language-Aware
For Java:
- Uses Result<E, T> types (no exceptions from domain/application)
- Uses sealed interfaces for errors
- Uses pattern matching with switch expressions
- Uses static imports for Failure/Success
- Follows Java 21+ conventions
For Go:
- Uses error return values
- Uses pointer receivers for aggregates/entities
- Uses value receivers for value objects
- Uses sentinel errors and custom error types
- Follows Uber Go Style Guide
Error Handling Built-In
The skill automatically:
- Returns Result types (Java) or errors (Go)
- Creates layer-specific error types
- Adds exception boundaries at infrastructure layer
- Logs errors appropriately (ERROR/WARN/INFO levels)
- Prevents silent failures
How It Works
- Analyzes your request - Determines what to implement (aggregate, use case, etc.)
- Detects language - From flags, file extensions, or project structure
- Loads rules - DDD rules, error handling, style guides for your language
- Generates code - Following templates and patterns
- Validates - Checks against DDD rules before completion
Architecture
/ddd-implement
├── SKILL.md # Skill manifest (loaded by Claude Code)
├── system-prompt.md # Core instructions for the implementation agent
├── README.md # This file
└── examples/
├── go-example.md # Example session in Go
└── java-example.md # Example session in Java
The system-prompt.md references rules from the ddd-model skill:
ddd-model/rules/ddd-rules.md- Core DDD patternsddd-model/rules/error-handling.md- Error handling strategyddd-model/languages/{lang}/style-guide.md- Language conventionsddd-model/languages/{lang}/templates/- Code templates
Workflow: Modeling → Implementation
1. Design with /ddd-model
↓ (identifies aggregates, entities, invariants)
2. Implement with /ddd-implement
↓ (generates code following rules)
3. Review with /review (or code review)
↓ (validates DDD principles)
4. Iterate
Examples
See detailed examples in:
Rules Reference
This skill enforces rules from:
- DDD Rules: ddd-model/rules/ddd-rules.md
- Clean Architecture: ddd-model/rules/clean-arch.md
- Error Handling: ddd-model/rules/error-handling.md
- Java Style: ddd-model/languages/java/style-guide.md
- Go Style: ddd-model/languages/go/style-guide.md
Contributing
To improve this skill:
- Add examples - Real-world implementation sessions in
examples/ - Refine rules - Update
system-prompt.mdbased on experience - Add templates - Language-specific templates in
ddd-model/languages/{lang}/templates/ - Document patterns - Special patterns in
ddd-model/rules/
Related Skills
- ddd-model - For domain modeling and design
- review - For code review with DDD principles (if available)