Layer Diagram
┌─────────────────────────────────────────────────────────────┐
│ PRESENTATION │
│ HTTP handlers, controllers, access guards, mappers │
│ CAN import: All inner layers │
├─────────────────────────────────────────────────────────────┤
│ INFRASTRUCTURE │
│ Implementations, Persistence, External │
│ CAN import: BC ports, domain (VOs, aggregates), shared │
├─────────────────────────────────────────────────────────────┤
│ ORCHESTRATIONS │
│ Compositions, Workflows, Projections │
│ CAN import: BC ports + use cases │
├─────────────────────────────────────────────────────────────┤
│ BOUNDED CONTEXTS │
│ Domain + Use Cases + Ports │
│ CAN import: Shared only (NO frameworks, NO env vars) │
├─────────────────────────────────────────────────────────────┤
│ SHARED │
│ Read Models, Enums, Generated Clients │
└─────────────────────────────────────────────────────────────┘
Dependencies flow INWARD →
Dependency Rules
| Layer | Can Import |
|---|---|
| Presentation | Infrastructure, Orchestrations, Bounded Contexts, Shared |
| Infrastructure | BC ports, domain (VOs, aggregates), Shared |
| Orchestrations | BC ports + use cases, Shared |
| Bounded Contexts | Shared only |
| Shared | Nothing (leaf layer) |
Request Flow
HTTP Request
│
▼
Handler ─────────────────► Extracts event, generates ExecutionContext
│
▼
Controller ──────────────► Validates, authorizes, maps
│
▼
Use Case / Orchestration ► Business logic
│
▼
Outbound Port Implementation
│
▼
Persistence / External ──► Database or API call
│
▼
Response bubbles back up
Folder Structure
Module-Based
packages/backend/
├── modules/{module}/
│ ├── bounded-contexts/{bc}/
│ │ ├── app/
│ │ │ ├── ports/inbound/
│ │ │ │ ├── queries/
│ │ │ │ └── commands/
│ │ │ ├── ports/outbound/
│ │ │ └── use-cases/
│ │ │ ├── queries/
│ │ │ └── commands/
│ │ ├── domain/
│ │ │ ├── aggregates/
│ │ │ ├── events/
│ │ │ └── services/
│ │ ├── infra/
│ │ │ ├── outbound-adapters/
│ │ │ ├── persistence/
│ │ │ ├── external-systems/
│ │ │ ├── schemas/
│ │ │ └── config/
│ │ └── presentation/
│ │ ├── bootstrap/
│ │ └── http/
│ ├── orchestrations/{orchestration}/
│ │ ├── app/
│ │ ├── infra/
│ │ └── presentation/
│ └── shared/
│ ├── infra/
│ ├── app/
│ └── domain/
└── shared/
├── infra/
├── app/
└── domain/
Simple
packages/backend/
├── bounded-contexts/{bc}/
│ ├── app/
│ ├── domain/
│ ├── infra/
│ └── presentation/
├── orchestrations/{orchestration}/
│ ├── app/
│ ├── infra/
│ └── presentation/
└── shared/
├── infra/
├── app/
└── domain/