DD

Domain-Driven Design

Used in 293 typescript projects (avg ★54)

Details

Language / Topic
typescriptTypeScript
Category
Architecture

Rules

balanced
- Organize code by bounded contexts based on business domains, not technical layers.
- Use rich domain models with behavior (methods) — not anemic data bags with external service logic.
- Use branded types (`type UserId = string & { __brand: 'UserId' }`) to prevent mixing up primitive domain IDs at compile time.
- Define aggregates with invariant enforcement. Only the aggregate root should be accessible externally.
- Use value objects for concepts defined by their attributes (Money, Email, DateRange), not identity.
- Use domain events to communicate between bounded contexts without tight coupling.
- Keep the domain layer pure: no framework imports, no I/O, no side effects.