Skip to content

VormicLab/nestjs-starter

Repository files navigation

NestJS Boilerplate

A production-ready NestJS boilerplate with TypeORM, PostgreSQL, Redis, BullMQ, and comprehensive email system.

πŸš€ Quick Start

Prerequisites

  • Node.js v18 or higher
  • PostgreSQL running locally
  • Redis running locally
  • npm (included with Node.js)

One-Command Setup

npm run setup:full

This single command will:

  • βœ… Check Node.js and npm versions
  • βœ… Install all dependencies
  • βœ… Create required directories
  • βœ… Build the project
  • βœ… Set up the database (migrations + seeds)

Manual Setup (Step by Step)

1. Initial Setup

npm run setup

2. Configure Environment

Update your .env file with proper configuration:

# Database
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=your_db_username
DB_PASSWORD=your_db_password
DB_DATABASE=your_db_name

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379

# JWT
JWT_SECRET=your_jwt_secret

# Mail Configuration
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USER=your_email@gmail.com
MAIL_PASS=your_app_password

3. Database Setup

npm run setup:db

4. Start Development Server

npm run start:dev

πŸ“‹ Available Scripts

Development

Script Description
npm run start:dev Start development server with hot reload
npm run start:debug Start with debugging enabled
npm run build Build the project
npm run clean Clean build artifacts

Code Quality

Script Description
npm run lint Lint and auto-fix code
npm run lint:check Check linting without fixing
npm run format Format code with Prettier
npm run format:check Check formatting without fixing
npm run precommit Run all checks before commit

Database

Script Description
npm run migration:generate --name=migration-name Generate new migration
npm run migration:run Run pending migrations
npm run migration:revert Revert last migration
npm run migration:show Show migration status
npm run seed:generate --name=seed-name Generate new seed
npm run seed:run Run seed scripts

Testing

Script Description
npm run test Run unit tests
npm run test:watch Run tests in watch mode
npm run test:cov Run tests with coverage
npm run test:e2e Run end-to-end tests

Setup & Maintenance

Script Description
npm run setup Initial project setup
npm run setup:db Database setup only
npm run setup:full Complete setup (setup + db)
npm run clean:install Clean and reinstall dependencies

πŸ—οΈ Project Structure

src/
β”œβ”€β”€ common/                 # Shared entities and repositories
β”œβ”€β”€ config/                 # Configuration files
β”œβ”€β”€ constants/              # Application constants
β”œβ”€β”€ decorators/             # Custom decorators
β”œβ”€β”€ exceptions/             # Custom exceptions
β”œβ”€β”€ filters/                # Exception filters
β”œβ”€β”€ guards/                 # Route guards
β”œβ”€β”€ interceptors/           # Response interceptors
β”œβ”€β”€ middleware/             # Custom middleware
β”œβ”€β”€ modules/                # Feature modules
β”‚   β”œβ”€β”€ auth/              # Authentication module
β”‚   β”œβ”€β”€ profile/           # User profile module
β”‚   β”œβ”€β”€ queue/             # Queue management
β”‚   └── user/              # User management
β”œβ”€β”€ pipes/                  # Validation pipes
β”œβ”€β”€ redis/                  # Redis configuration
β”œβ”€β”€ routes.ts              # Route definitions
β”œβ”€β”€ shared/                 # Shared services
β”œβ”€β”€ templates/              # Email templates
β”œβ”€β”€ types/                  # TypeScript type definitions
└── utils/                  # Utility functions

πŸ”§ Features

Core Features

  • βœ… NestJS Framework - Modern Node.js framework
  • βœ… TypeORM - Type-safe database ORM
  • βœ… PostgreSQL - Robust relational database
  • βœ… Redis - Caching and session storage
  • βœ… BullMQ - Background job processing
  • βœ… JWT Authentication - Secure token-based auth
  • βœ… Email System - Comprehensive email handling
  • βœ… Validation - Request validation with class-validator
  • βœ… Swagger - API documentation
  • βœ… Rate Limiting - Request throttling
  • βœ… Security - Helmet, CORS, compression

Email System

  • βœ… Multiple Templates - Handlebars-based templates
  • βœ… Queue Processing - Background email sending
  • βœ… Multiple Recipients - Send to admin and user simultaneously
  • βœ… Development Mode - Console output for testing

Database

  • βœ… Migrations - Version-controlled schema changes
  • βœ… Seeds - Sample data population
  • βœ… Repository Pattern - Clean data access layer
  • βœ… Entity Relationships - Proper database relationships

🌐 API Endpoints

Authentication

  • POST /auth/register - User registration
  • POST /auth/login - User login
  • POST /auth/refresh - Refresh token

Profile

  • GET /profile - Get user profile
  • PUT /profile - Update user profile

Queue/Email

  • Email jobs are processed automatically via BullMQ
  • Templates: get-in-touch, get-in-touch-confirmation, welcome-email

πŸ” Default Credentials

Email: admin@mail.com
Password: defaultPass123!

πŸ“ Environment Variables

Create a .env file based on .env.example:

# Application
NODE_ENV=development
PORT=4000

# Database
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=password
DB_DATABASE=nestjs_boilerplate

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379

# JWT
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRES_IN=7d

# Mail Configuration
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USER=your-email@gmail.com
MAIL_PASS=your-app-password
MAIL_FROM_NAME=Your App Name
MAIL_FROM_EMAIL=noreply@yourapp.com
MAIL_TO_NAME=Admin
MAIL_TO_EMAIL=admin@yourapp.com

πŸš€ Deployment

Production Build

npm run build
npm run start:prod

Docker (Optional)

# Build image
docker build -t nestjs-boilerplate .

# Run container
docker run -p 4000:4000 nestjs-boilerplate

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

πŸ“„ License

This project is licensed under the UNLICENSED License.

πŸ†˜ Troubleshooting

Common Issues

  1. Database Connection Failed

    • Ensure PostgreSQL is running
    • Check database credentials in .env
    • Verify database exists
  2. Redis Connection Failed

    • Ensure Redis is running
    • Check Redis configuration in .env
  3. Build Errors

    • Run npm run clean
    • Check Node.js version (18+)
    • Build again
  4. Migration Errors

    • Check database connection
    • Verify migration files are valid
    • Run npm run migration:show to check status

Getting Help

  • Check the logs for detailed error messages
  • Ensure all prerequisites are installed
  • Verify environment configuration
  • Check database and Redis connections

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors