The Layered Architecture
┌─────────────────────────────────────────────────────────────┐
│ Presentation Layer │
│ React Components / Express Routes & Controllers │
├─────────────────────────────────────────────────────────────┤
│ Application Layer │
│ Services, Use Cases, Orchestration │
├─────────────────────────────────────────────────────────────┤
│ Domain Layer │
│ Entities, Business Rules, Validation │
├─────────────────────────────────────────────────────────────┤
│ Infrastructure Layer │
│ Repositories, Database, External Services │
└─────────────────────────────────────────────────────────────┘
The Dependency Rule: Dependencies point downward only (upper layers depend on lower, never the reverse)
Separation of Concerns & Bounded Contexts
Separation of Concerns: Each module has one responsibility → independent development, testing, maintenance
Bounded Context: A boundary where a particular domain model applies consistently
Sales Context Shipping Context
┌──────────────┐ ┌──────────────┐
│ Customer │ │ Recipient │
│ Order │ │ Shipment │
│ Product │ │ Address │
└──────────────┘ └──────────────┘
│ │
└────── CustomerID ───┘
Same entity (customer) can mean different things in different contexts