How fedi-dayeg/complete-nestjs-boilerplate works
1. System shape
This is a NestJS v11 backend boilerplate organized as a modular monolith. The top-level flow is: HTTP request enters main.ts, passes through request middleware/guards/interceptors, routes through router/, then into feature modules under src/modules, which delegate to services and repositories.
2. Application bootstrap and cross-cutting pipeline
src/app and src/main.ts define the core application bootstrap, global filters, and shared app-level DTOs/interfaces. The request pipeline is heavily standardized through middleware in src/common/request and response/exception handling in src/common/response and src/app/filters, so most endpoints share the same logging, validation, timeout, CORS, compression, request-id, and localized error/response behavior.
3. Module routing and endpoint boundaries
The src/router layer splits the API by audience: public, shared, user, admin, and system routes. Feature modules expose controllers in matching scopes, such as *.public.controller.ts, *.shared.controller.ts, *.admin.controller.ts, and *.system.controller.ts, which makes the access boundary explicit in the architecture.
4. Feature modules as the main business boundary
The domain is split into independent feature modules: auth, user, role, policy, session, device, api-key, term-policy, notification, feature-flag, activity-log, health, country, hello, password-history. Each module usually contains its own controllers, service, repository, DTOs, enums, guards, utils, and docs, keeping business logic local to the module.
5. Security and identity stack
Authentication is stateful and layered: JWT access/refresh strategies, Redis-backed session handling, API key guards, role guards, policy/ability guards, feature-flag guards, and term-policy acceptance checks. The auth, user, role, policy, session, device, and api-key modules work together to enforce who can call which route and under what device/session state.
6. Persistence and data access
Database access is abstracted behind repository classes in each module and a shared src/common/database layer. The project uses Prisma with MongoDB as the primary persistence engine; the README calls out replica-set requirements for transactions. This layering means controllers never talk to Prisma directly, and database-specific concerns are isolated from feature services.
7. Caching, sessions, and async work
Redis is used as shared infrastructure for caching and stateful session-related concerns, via src/common/cache and src/common/redis. Background processing is handled by BullMQ in src/queues, with queue processors and decorators forming the async job boundary for tasks like notification delivery or other deferred work.
8. External integrations
The main external services are AWS S3, AWS SES, Firebase, and Sentry. AWS S3 is used for file storage and presigned upload flows; SES handles email delivery; Firebase appears to support push notification delivery; Sentry provides error and performance monitoring. These integrations are wrapped in src/common/aws, src/common/firebase, and the notification/health modules rather than being embedded in feature controllers.
9. Notification and template rendering
Notifications are a separate subsystem with processors for email and push, a central notification service, and Handlebars templates under src/modules/notification/templates. This creates a pipeline from business event → notification processor/service → channel-specific delivery → AWS SES/Firebase, with templates and user settings managed within the module.
10. File and content handling
File upload and content-presign concerns are standardized in src/common/file and are used by modules like term-policy. CSV parsing/validation pipes, extension checks, and presign DTOs indicate the system supports controlled file intake rather than ad hoc uploads, with S3 as the backing store.
11. Health, observability, and runtime safety
src/modules/health exposes system checks for database, Redis, AWS S3/SES, and Sentry connectivity, while request-level middleware tracks request ID and response time. There is also structured logging support in src/common/logger and localized messages under src/languages/en, so operational visibility and user-facing errors are first-class concerns.
12. Configuration, documentation, and delivery
Configuration is centralized in src/configs, with environment-driven behavior for auth, AWS, database, logging, feature flags, sessions, and documentation. Swagger/OpenAPI is built in, but the README notes docs can be disabled in production mode. The repo also includes Docker, docker-compose, GitHub Actions CI, Prisma schema, seed/migration modules, and test scaffolding, showing it is designed for repeatable deployment and environment setup.
Main entry points: router.module.ts Router · app.module.ts App module · common.module.ts Common module · database.module.ts Database
Components 26
Bootstrap
Application entry, root module, config, and global filters
- main.ts · Nest application bootstrap
src/main.ts - App module · Wires global filters and application composition
src/app/app.module.ts - Configs · Environment-driven configuration surface
src/configs/index.ts - Global filters · HTTP and validation exception shaping
src/app/filters/app.http.filter.ts
Request Edge
HTTP pipeline, routing, and response shaping
- Request stack · Middleware, guards, pipes, and request lifecycle hooks
src/common/request/request.module.ts - Response stack · Standardized response and cache/file interceptors
src/common/response/interceptors/response.interceptor.ts - Router · Audience-based route modules
src/router/router.module.ts
Shared Infra
Common services and cross-cutting utilities
- Common module · Shared infrastructure composition
src/common/common.module.ts - Database · Prisma-backed persistence layer
src/common/database/database.module.ts - Redis cache · Caching and session-related shared state
src/common/cache/cache.module.ts - AWS · S3 storage and email wrappers
src/common/aws/aws.module.ts - Firebase · Push notification integration
src/common/firebase/firebase.module.ts - Logger · Structured logging support
src/common/logger/logger.module.ts
Feature Modules
Business modules and their route scopes
- User · Profiles, account state, and user workflows
src/modules/user/user.module.ts - Auth · JWT login, refresh, and two-factor flows
src/modules/auth/auth.module.ts - Role · Roles and ability data
src/modules/role/role.module.ts - Policy · Ability rules and policy guards
src/modules/policy/policy.module.ts - Session · User sessions and device-linked state
src/modules/session/session.module.ts - Device · Device ownership and refresh tracking
src/modules/device/device.module.ts - API key · X-API-key authentication boundary
src/modules/api-key/api-key.module.ts - Term policy · Policy content and acceptance flows
src/modules/term-policy/term-policy.module.ts - Notification · Email and push notification pipeline
src/modules/notification/notification.module.ts - Feature flags · Runtime flag checks and admin management
src/modules/feature-flag/feature-flag.module.ts
Connections 39
- main.ts → App module: bootstraps · Creates and configures the Nest application
- App module → Configs: loads · Reads environment-specific settings
- App module → Global filters: installs · Registers global exception filters
- App module → Common module: imports · Wires shared infrastructure
- App module → Router: mounts · Connects route composition to the app
- App module → Request stack: applies · Installs the request pipeline
- App module → Response stack: applies · Installs standardized response handling
- Common module → Database: includes · Prisma database layer
- Common module → Redis cache: includes · Redis layer
- Common module → AWS: includes · Cloud storage and email wrappers
- Common module → Firebase: includes · Push integration wrapper
- Common module → Logger: includes · Logging support
- Router → User: routes · User-scoped endpoints
- Router → Auth: routes · Authentication endpoints
- Router → Role: routes · Role management endpoints
- Router → Policy: routes · Authorization endpoints
- Router → Session: routes · Session endpoints
- Router → Device: routes · Device endpoints
- Router → API key: routes · API key endpoints
- Router → Term policy: routes · Term policy endpoints
- Router → Notification: routes · Notification endpoints
- Router → Feature flags: routes · Feature flag endpoints
- Router → Health: routes · Health endpoints
- Auth → Session: issues · Login creates or refreshes session state
- Auth → Device: binds · Tracks device context during auth
- Auth → User: validates · Authenticates against user identity
- User → Database: persists · Reads and writes user data
- Role → Database: persists · Stores role and ability data
- Policy → Role: derives · Builds authorization from roles
- Notification → Queues: enqueues · Defers delivery work to jobs
- Notification → AWS: sends · Uses SES and storage helpers
- Notification → Firebase: pushes · Uses Firebase for push delivery
- Term policy → AWS: stores · Uses presigned file/content flows
- Feature flags → Database: persists · Stores flag definitions and state
- Health → Database: checks · Verifies database connectivity
- Health → Redis cache: checks · Verifies Redis connectivity
- Health → AWS: checks · Verifies AWS connectivity
- Health → Logger: reports · Surfaces runtime diagnostics
- Migration → Database: seeds · Populates initial database state