Skip to content

Latest commit

 

History

History
91 lines (68 loc) · 3.32 KB

README.md

File metadata and controls

91 lines (68 loc) · 3.32 KB

NestJS - Clean Architecture Boilerplate

Version License: MIT

📝 Table of content

👋 Introduction

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.

🚀 Quick Start

Important

To run the backend locally, you need a PostgreSQL database with migrations applied.

Bootstrap the PostgreSQL database

  1. Start PostgreSQL using docker-compose.yaml
docker compose -f docker/docker-compose.yaml up database -d
  1. Run the SQL migrations
pnpm drizzle-kit migrate

Start the API on Your Local Machine

# Run the backend in watch mode
pnpm dev

🌟 Key Features

📬 Outbox Pattern

  • Guaranteed Event Delivery: ensure events are reliably stored and dispatched achieving at-least-once delivery.
  • Concurrency: Leverages REPEATABLE READ isolation and FOR UPDATE SKIP LOCKED to ensure efficient and exclusive message processing, even under high load.
  • NOT_IMPLEMENTED Transaction Safety: Events are saved in the outbox as part of the same database transaction as aggregate updates, ensuring consistency.

🐳 Docker-Ready

  • 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

📂 Project Structure

📁 src/
├── 📁 core/
│ ├── 📁 errors/ # Base error classes such as ResourceNotFound, etc.
│ ├── 📁 primitives/ # Building blocks like Entity, etc.
│ └── 📁 utils/ # Utility functions
│
├── 📁 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/
│ ├── 📁 infrastructure/ # Driver adapters used across multiple bounded-contexts (e.g. GoogleCloudTasks, ...)
│ ├── 📁 use-cases/
│ └── 📄 shared-kernel.module.ts
│
├── 📄 application.module.ts
└── 📄 main.ts