ddd-architecture
Skill29 starsChanged 2 months agoMITView on GitHub
Domain-Driven Design for complex business domains. Use when deciding whether DDD is warranted, defining bounded contexts, aggregates, entities and value objects, applying CQRS or domain events, or organizing a domain layer.
In this repository25 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- agent-lanesSkill
- angular-3d-scene-crafterSkill
- angular-frontend-patternsSkill
- angular-gsap-animation-crafterSkill
- execute-phase-gated-taskSkill
- extract-and-relocate-angular-component-featureSkill
- fleet-orchestrationSkill
- humanize-librarySkill
- impeccableSkill
- nestjs-backend-patternsSkill
- nestjs-deploymentSkill
- nx-workspace-architectSkill
- orchestrationSkill
- ptah-cli-usageSkill
- resilient-nestjs-patternsSkill
- saas-platform-patternsSkill
- saas-workspace-initializerSkill
- skill-creatorSkill
- technical-content-writerSkill
- tribunalSkill
- typesafe-aiSkill
- ui-ux-designerSkill
- video-showcaseSkill
- webhook-architectureSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
If this skill is invoked from saas-workspace-initializer Step a2, the Round 1 discovery answers (jobs-to-be-done, candidate domains, MVP …
- Very specific: line 98
Read references/entities-aggregates.md for the full pattern — the Entity and EntityId base classes, the invariant guards, and the …
- Very specific: line 121
Read references/value-objects.md for the ValueObject base class and further worked examples (Email, Address, DateRange, Percentage).
- Distinctive: line 137
Before implementing DDD, assess with user:
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Domain-Driven Design Architecture
Strategic and tactical DDD patterns for NestJS + Angular applications.
When to Engage User
DDD is highly context-dependent. ALWAYS discuss with user before implementing.
If this skill is invoked from saas-workspace-initializer Step a2, the Round 1 discovery answers (jobs-to-be-done, candidate domains, MVP scope) are already available — use them and do not re-ask the equivalent questions below. Ask only what those answers leave open.
Discovery Questions
- Domain Complexity
- "What are your core business entities and their relationships?"
- "Which operations are most critical to get right?"
- "Are there complex business rules or validations?"
- Bounded Contexts
- "Are there distinct business areas that use different terminology?"
- "Which teams will own which parts of the system?"
- "Do you have existing systems that define boundaries?"
- Scale & Performance
- "Which read operations are most frequent?"
- "Are there operations that need eventual consistency?"
- "Do you need audit trails for business operations?"
DDD Building Blocks
| Concept | Purpose | Example |
| Entity | Identity + lifecycle | User, Order, Product |
| Value Object | Attributes, no identity | Money, Address, Email |
| Aggregate | Consistency boundary | Order + OrderItems |
| Domain Event | Record what happened | OrderPlaced, UserRegistered |
| Repository | Persistence abstraction | OrderRepository |
| Domain Service | Cross-aggregate logic | PaymentProcessor |
Project Structure
libs/
├── [domain]/
│ ├── domain/ # Core domain logic
│ │ └── src/lib/
│ │ ├── entities/ # Entities and aggregates
│ │ ├── value-objects/ # Value objects
│ │ ├── events/ # Domain events
│ │ ├── services/ # Domain services
│ │ └── repositories/ # Repository interfaces
│ │
│ ├── application/ # Use cases / application services
│ │ └── src/lib/
│ │ ├── commands/ # Command handlers
│ │ ├── queries/ # Query handlers
│ │ └── services/ # Application services
│ │
│ ├── infrastructure/ # Technical implementations
│ │ └── src/lib/
│ │ ├── persistence/ # Repository implementations
│ │ ├── messaging/ # Event publishing
│ │ └── external/ # External service adapters
│ │
│ └── feature/ # Controllers / presenters
│ └── src/lib/
│ └── controllers/Entity Pattern
An entity has identity, a private constructor reached through factories, and
business methods that guard their own invariants. It extends a shared Entity
base that supplies identity equality and the domain-event buffer:
export class Order extends Entity<OrderId> {
private constructor(
id: OrderId,
private _customerId: CustomerId,
) {
super(id);
}
static create(customerId: CustomerId): Order; // new, raises OrderCreated
static reconstitute(data: OrderData): Order; // rehydrate, raises nothing
addItem(productId: ProductId, qty: number, unitPrice: Money): void;
place(): void; // rejects an empty order
get total(): Money; // derived, never stored
}Read references/entities-aggregates.md for
the full pattern — the Entity and EntityId base classes, the invariant
guards, and the aggregate-root rules. Do not hand-roll a base class from this
sketch; the reference version is the one to copy.
Value Object Pattern
A value object has no identity — two instances with equal contents are equal. It
is immutable, validates in its constructor, and returns new instances from every
operation. It extends a shared ValueObject base that supplies structural
equality:
export class Money extends ValueObject<{ amount: number; currency: string }> {
static of(amount: number, currency?: string): Money; // throws if negative
static zero(currency?: string): Money;
add(other: Money): Money; // all three reject a currency mismatch
subtract(other: Money): Money;
multiply(factor: number): Money;
}Read references/value-objects.md for the
ValueObject base class and further worked examples (Email, Address,
DateRange, Percentage).
Decision Matrix: When to Use DDD
| Scenario | Recommendation |
| Simple CRUD | Skip DDD, use basic services |
| Medium complexity | Use tactical patterns (entities, value objects) |
| Complex domain | Full DDD with bounded contexts |
| Multiple teams | Bounded contexts essential |
| High consistency needs | Aggregates + domain events |
Complexity Assessment
Before implementing DDD, assess with user:
□ Do entities have complex lifecycles? (draft → approved → fulfilled)
□ Are there business rules that span multiple entities?
□ Do different parts of the system use different terminology?
□ Is there a need for audit trails or event sourcing?
□ Will multiple teams work on different parts?Score:
- 0-1: Simple services sufficient
- 2-3: Tactical DDD patterns
- 4-5: Full strategic DDD
References
Load for detailed implementation:
- entities-aggregates.md - Entity and aggregate patterns
- value-objects.md - Value object implementations
- cqrs-pattern.md - Command/Query separation
- domain-events.md - Event-driven patterns
- repository-pattern.md - Persistence abstraction
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

