Backend Architecture
NestJS modules, database, scheduler, real-time communication, and external integrations in the server.
Module Structure
The backend is a NestJS 11 application running on Bun, organized into Clean Architecture / DDD layers:
| Layer | Responsibility |
|---|---|
api/ | oRPC procedures, REST controllers, public REST surface, DTOs |
application/ | CQRS commands & handlers, queries, services, sagas, middleware |
domain/ | Entities, value objects, repository interfaces, domain events |
infrastructure/ | Database, Redis, BullMQ, AI, email, secrets, repository impls |
modules/ | NestJS module wiring (imports application/, provides DI) |
shared/ | Base entities, AsyncLocalStorage contexts, mediator, errors |
Dependencies point inward: api → application → domain ← infrastructure. NestJS DI wires
everything at the module level. Writes flow through the CQRS command bus; reads call
services directly. Sagas coordinate cross-aggregate flows with compensation.