Skip to content

abidmaqbool20/nestjs-sql-backend

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient, scalable, and maintainable server-side applications.

NPM Version Package License NPM Downloads CircleCI Discord


Description

This repository provides a production-ready NestJS backend boilerplate intended for real-world, scalable applications.

The architecture emphasizes:

  • clear separation of concerns,
  • strong configuration management,
  • safe database migrations,
  • background job processing,
  • CLI tooling,
  • caching,
  • notifications,
  • and environment-based execution.

The application supports PostgreSQL and MySQL, with the active database selected at runtime via environment variables.


Features

  • JWT Authentication (Passport-JWT)
  • Global Exception Handling
  • Centralized Logging Layer
  • Helper Utilities Module
  • API Rate Limiting
  • Request Validation (class-validator)
  • Encryption and Decryption Utilities
  • PostgreSQL & MySQL support (runtime switchable)
  • TypeORM with Migration-first workflow
  • Roles & Permissions (RBAC)
  • Users, Roles, Permissions modules with migrations
  • Database Seeder implementation
  • CRUD operations on User module
  • Redis Cache
  • Node Cache
  • API Documentation (Swagger)
  • Standardized API Response Layer
  • Email sending (Handlebars templates)
  • Email & Web Push Notifications
  • Bull Queue Management
  • Background Jobs
  • Auto-discovered CLI Commands
  • Postman API Collection

Installation

Install project dependencies:

npm install

Environment Setup (Required)

Before running the application, you must create an environment file. Create .env.development

cp .env.example .env.development

Generating VAPID Keys (Web Push Notifications)

Web Push Notifications require VAPID public/private keys.

Generate them using:

npx web-push generate-vapid-keys

Example output:

Public Key: BExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Private Key: 6Vxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Add these values to your .env.development file:

VAPID_PUBLIC_KEY=your_public_key_here VAPID_PRIVATE_KEY=your_private_key_here

Running the Application

Development mode

npm run start

Watch mode (recommended during development)

npm run start:dev

Production mode

npm run start:prod

Database Setup

Run Migrations (Required)

This step creates all database tables.

npm run migration:run

Seed Initial Data: Seed default data such as roles and permissions:

npm run seed

⚠️ Important: Migrations must be executed before seeding.

CLI Commands

The project includes a dynamic CLI system. All commands are auto-discovered from the src/cli/commands directory.

List available commands

npm run cli -- --help

List Bull queues

npm run cli list-queues

Empty a queue

npm run cli empty-queue default all

API Documentation

Swagger documentation is available at:

http://localhost:5001/api

Author

Abid Maqbool

License

This project is licensed under the MIT License.

About

Nest JS Jump Start - API Development - Backend Development - Postgres or MySQL

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published