Domain-Driven Design: From Theory to Practice
DDD aligns code structure with business concepts reducing cognitive load. ## Key Concepts - **Bounded Context** — clear module boundary - **Aggregate** — consistency boundary within a context - **Domain Event** — something that happened in the domain ## Example Aggregate ```typescript class Order { private items: OrderItem[] = []; addItem(product: Product, qty: number) { // invariants enforced here this.items.push(new OrderItem(product, qty)); this.raise(new ItemAddedEvent(product.id)); } } ``` ## Conclusion DDD pays off on complex domains. Avoid it for simple CRUD apps.