Production-ready NestJS boilerplate with authentication, database, WebSocket, and best practices.
- 🔐 Authentication & Authorization: JWT-based auth with refresh tokens, email verification, password reset
- 👥 User Management: Complete user CRUD with role-based access control (RBAC)
- 📁 File Upload: Local and S3 storage support with validation
- 📧 Email Service: Template-based emails with queue support
- 🔌 WebSocket: Real-time communication with Socket.IO
- 🗄️ Database: PostgreSQL with TypeORM, migrations, and seeding
- ⚡ Caching: Redis integration for performance
- 📝 API Documentation: Auto-generated Swagger/OpenAPI docs
- 🔒 Security: Helmet, rate limiting, input validation
- 📊 Logging: Winston logger with daily rotation
- 🐳 Docker: Development and production Docker setup
- ✅ Testing: Unit, integration, and E2E tests
- 🎨 Code Quality: ESLint, Prettier, Husky pre-commit hooks
├── assets/ # Email templates, static data JSON
├── config/ # Third-party configurations
├── public/ # Static files
├── src/
│ ├── api/ # Business logic modules (auth, users, etc.)
│ ├── common/ # Custom utilities and shared logic
│ ├── event/ # WebSocket gateways
│ ├── lib/ # Built-in modules (database, cache, etc.)
│ ├── schema/ # Database entities
│ ├── seed/ # Database seeds
│ ├── app.module.ts
│ ├── main.ts
│ └── seeder.ts
└── test/ # Test files
- Node.js >= 20.0.0
- PostgreSQL >= 14
- Redis >= 6
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd nestjs-boilerplate- Install dependencies:
npm install- Copy environment file:
cp .env.example .env-
Update
.envwith your configuration -
Run database migrations:
npm run migration:run- Seed the database:
npm run seednpm run devnpm run build
npm run start:proddocker-compose upOnce running, visit: http://localhost:3000/api/docs
# Unit tests
npm run test
# E2E tests
npm run test:e2e
# Test coverage
npm run test:covnpm run dev- Start development server with hot reloadnpm run build- Build for productionnpm run start:prod- Start production servernpm run lint- Run ESLintnpm run format- Format code with Prettiernpm run test- Run unit testsnpm run test:e2e- Run E2E testsnpm run migration:generate- Generate migrationnpm run migration:run- Run migrationsnpm run seed- Seed database
See .env.example for all required and optional environment variables.
MIT