Welcome to the NestJS Boilerplate. This project provides a solid foundation for building scalable and maintainable backend applications with NestJS, following the Clean Architecture. It also integrates concepts from Domain-Driven Design (DDD) to help organize your code around the core business logic.
Important
To run the backend locally, you need a PostgreSQL database with migrations applied.
git clone git@github.com:Gi-jutsu/nestjs-clean-boilerplate.git
cd nestjs-clean-boilerplate
2.1. Start PostgreSQL using docker-compose.yaml
docker compose -f docker/docker-compose.yaml up database -d
2.2. Run the SQL migrations
pnpm drizzle-kit migrate
You can run the backend either locally or with Docker.
pnpm dev
docker compose -f docker/docker-compose.yaml up api -d
- Guaranteed Event Delivery: ensure events are reliably stored and dispatched achieving at-least-once delivery.
- Concurrency: Leverages
REPEATABLE READ
isolation andFOR UPDATE SKIP LOCKED
to ensure efficient and exclusive message processing, even under high load. - Transaction Safety: Events are saved in the outbox as part of the same database transaction as aggregate updates, ensuring consistency.
-
Optimized for Deployments: Multi-stage build keeps the production image lean, reducing network footprint and speeding up deployments.
-
Run Locally: Launch the entire stack (API + Database) with docker-compose.yaml
-
Security: Runs as a non-root user to reduce security risks
📁 src/
├── 📁 identity-and-access/
│ ├── 📁 domain/ # Business logic (e.g. Account, ForgotPasswordRequest ...)
│ ├── 📁 infrastructure/ # Driver adapters (e.g., Jwt, Mailer, etc.)
│ ├── 📁 use-cases/ # Implements business use cases, connecting ports and domains
│ └── 📄 identity-and-access.module.ts
│
├── 📁 shared-kernel/
│ ├── 📁 domain/ # Shared logic and core domain concepts (e.g., AggregateRoot, DomainEvent, Outbox Message, Shared Errors)
│ ├── 📁 infrastructure/ # Driver adapters used across multiple bounded-contexts (e.g. GoogleCloudTasks, ...)
│ ├── 📁 use-cases/
│ ├── 📁 utils/
│ └── 📄 shared-kernel.module.ts
│
├── 📄 application.module.ts
└── 📄 main.ts