nest-boiler
v1.0.3
Published
CLI tool to generate production-ready NestJS boilerplate with database, Redis, worker, WebSocket, and Docker support
Downloads
418
Maintainers
Readme
NestJS Boilerplate Generator CLI
🚀 CLI tool to generate production-ready NestJS boilerplate projects with complete database, Redis, Worker, WebSocket, and Docker support.
✨ Features
- 🗄️ Database Support: MySQL, PostgreSQL, MongoDB, MongoDB Replica Set
- TypeORM for SQL databases with migration support
- Mongoose for MongoDB
- Data Source configuration
- Base Entity classes (BaseTimeEntity, BaseIncrementEntity, BaseUuidEntity)
- 🔴 Redis Configuration: Integrated Redis cache with cache-manager
- ⚙️ Worker Queue: Bull Queue with separate bootstrap, Redis global config
- 🔌 WebSocket: Socket.IO gateway with separate bootstrap
- 🐳 Docker Support: Dockerfile + docker-compose.yml with profiles
- Multi-stage builds (builder, production, development)
- Database admin tools (pgAdmin, phpMyAdmin, Mongo Express)
- Health checks for all services
- Production-ready configuration
- ✅ Validation: class-validator and class-transformer
- 📝 Logging: Winston logger with daily rotation and separate log files
- 📚 API Documentation: Swagger/OpenAPI integration
- 🔄 TypeScript: Full TypeScript support with proper types
- 🎨 Code Quality: ESLint, Prettier pre-configured
- 🛡️ Error Handling: Global exception filters and custom exceptions
- 🔍 Interceptors: Request logging, response transformation
📦 Installation
Global installation (Recommended)
npm install -g nestjs-boilerplate-generatorUsing npx (No installation required)
npx nestjs-boilerplate-generator new my-projectInstall from source
git clone https://github.com/yourusername/nestjs-boilerplate-generator.git
cd nestjs-boilerplate-generator
npm install
npm link🚀 Usage
Create a new project
nestjs-gen new my-projector if not installed globally:
node bin/cli.js new my-projectProject generation process
The CLI will ask you the following questions:
Choose database:
- MySQL
- PostgreSQL
- MongoDB
- MongoDB Replica Set
- None
Add Redis config? (Yes/No)
Add Worker (Bull Queue)? (Yes/No)
Add WebSocket? (Yes/No)
Add Docker (Dockerfile + docker-compose.yml)? (Yes/No)
After creating the project
cd my-project
npm install
npm run start:dev📁 Generated project structure
my-project/
├── src/
│ ├── common/
│ │ ├── config/
│ │ │ ├── database.config.ts # Database config
│ │ │ ├── redis.config.ts # Redis config
│ │ │ └── logger.config.ts # Winston logger config
│ │ ├── constants/ # Application constants
│ │ ├── decorators/ # Custom decorators
│ │ ├── entities/
│ │ │ └── base.entity.ts # Base entities (SQL only)
│ │ ├── enums/ # Enums
│ │ ├── exceptions/ # Custom exceptions
│ │ ├── filters/ # Exception filters
│ │ ├── interceptors/ # Request/Response interceptors
│ │ ├── logger/ # Logger utilities
│ │ └── response/ # Response DTOs
│ ├── migrations/ # TypeORM migrations (SQL only)
│ ├── websocket/ # WebSocket module (if selected)
│ │ ├── websocket.module.ts
│ │ └── websocket.gateway.ts
│ ├── worker/ # Worker module (if selected)
│ │ └── worker.module.ts
│ ├── app.controller.ts
│ ├── app.service.ts
│ ├── app.module.ts # Main app module
│ ├── bootstrap.websocket.ts # WebSocket bootstrap (if selected)
│ ├── bootstrap.worker.ts # Worker bootstrap (if selected)
│ ├── data-source.ts # TypeORM data source (SQL only)
│ └── main.ts # Main API bootstrap
├── logs/ # Winston logs (auto-created)
│ ├── api/ # API logs
│ ├── socket/ # Socket logs
│ └── worker/ # Worker logs
├── Dockerfile # Multi-stage Dockerfile (if selected)
├── docker-compose.yml # Docker Compose config (if selected)
├── .dockerignore # Docker ignore file (if selected)
├── DOCKER_README.md # Docker documentation (if selected)
├── WORKER_README.md # Worker documentation (if selected)
├── .env
├── eslint.config.mjs
├── .gitignore
├── .prettierrc
├── nest-cli.json
├── package.json
├── tsconfig.json
├── tsconfig.build.json
└── README.md🔧 Configuration
All configurations are stored in the .env file:
MySQL/PostgreSQL
DB_HOST=localhost
DB_PORT=3306 # or 5432 for PostgreSQL
DB_USERNAME=root
DB_PASSWORD=
DB_DATABASE=nestjsMongoDB
MONGODB_URI=mongodb://localhost:27017/nestjs
MONGODB_REPLICA_SET=rs0 # If using Replica SetRedis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0Docker (When Docker is selected)
Environment variables will be automatically configured for Docker:
- Database hosts changed to service names (postgres, mysql, mongo, redis)
- Passwords set to default
your_secure_password(should be changed) - Admin tool credentials added automatically
Example with PostgreSQL + Docker:
# PostgreSQL Configuration (Docker)
DB_HOST=postgres
DB_PORT=5432
DB_USERNAME=nestjs
DB_PASSWORD=your_secure_password
DB_DATABASE=nestjs
# PostgreSQL Docker Configuration
POSTGRES_USER=nestjs
POSTGRES_PASSWORD=your_secure_password
POSTGRES_DB=nestjs
# pgAdmin
[email protected]
PGADMIN_DEFAULT_PASSWORD=admin📝 Scripts
The generated project will have these scripts:
Main API Scripts
npm run start # Start the application
npm run start:dev # Start in development mode with watch mode
npm run start:prod # Start in production mode
npm run build # Build project
npm run test # Run unit tests
npm run test:e2e # Run e2e tests
npm run lint # Lint code
npm run format # Format code with PrettierWebSocket Scripts (Only when WebSocket is selected)
WebSocket runs on a separate server (port 3001):
npm run start:socket # Start WebSocket server
npm run start:socket:dev # Start WebSocket in development mode
npm run start:socket:prod # Start WebSocket in production modeWorker Scripts (Only when Worker is selected)
Worker runs in background (does not expose HTTP port):
npm run start:worker # Start Worker process
npm run start:worker:dev # Start Worker in development mode
npm run start:worker:prod # Start Worker in production modeDocker Scripts (Only when Docker is selected)
Docker Compose with profiles for development and production:
# Development stack (with database admin tools)
docker-compose --profile dev up -d
# Production stack
docker-compose --profile prod up -d
# Start specific services
docker-compose up postgres redis -d
# Stop all services
docker-compose down
# View logs
docker-compose logs -f
# Rebuild images
docker-compose build --no-cacheMigration Scripts (Only for SQL databases)
If you select MySQL or PostgreSQL, the following scripts will be added:
npm run migration:generate # Generate migration from entities
npm run migration:run # Run migrations
npm run migration:revert # Revert the most recent migration🔍 Feature Details
Database Integration
- MySQL/PostgreSQL:
- Uses TypeORM with auto configuration
- Data Source configuration for migrations
- Automatic migration scripts
- Type-safe with TypeScript
- MongoDB:
- Uses Mongoose with connection string support
- Supports Replica Set configuration
Redis
- Integrated with
@nestjs/cache-manager - Redis client version 4.6.0
- Global cache module
- Type-safe with
@types/cache-manager - Easy to use in any service
Worker (Bull Queue)
- Runs separately: Separate bootstrap (
bootstrap.worker.ts) - Does not expose HTTP: Only processes jobs, no HTTP endpoint
- Redis Global: Redis config pre-configured for all queues
- Winston Logger: Integrated logging with LogModule.WORKER
- Type-safe with
@types/bull - Ready for background job processing
- Can create multiple queues and processors
- Automatic retry and failure handling
- Job progress tracking
WebSocket
- Runs separately: Separate bootstrap (
bootstrap.websocket.ts) - Winston Logger: Integrated logging with LogModule.SOCKET
- Socket.IO gateway version 4.7.2
- CORS enabled
- Event-driven architecture
- Connection/Disconnection handling
- Real-time bidirectional communication
Validation & Transformation
- class-validator: Validate DTOs and request data
- class-transformer: Transform plain objects to class instances
- Auto validation with NestJS pipes
📦 Installed Dependencies
Core Dependencies (Always included)
@nestjs/common,@nestjs/core,@nestjs/platform-express@nestjs/config- Configuration managementreflect-metadata,rxjsclass-validator,class-transformer- Validation & transformation
Database Dependencies (Optional)
MySQL:
@nestjs/typeorm,typeorm,mysql2dotenv- Environment variables
PostgreSQL:
@nestjs/typeorm,typeorm,pgdotenv- Environment variables
MongoDB:
@nestjs/mongoose,mongoose
Redis & Worker Dependencies (Optional)
@nestjs/cache-manager,cache-manager,cache-manager-redis-storeredis- Redis client@nestjs/bull,bull- Queue management@types/cache-manager,@types/bull- TypeScript types
WebSocket Dependencies (Optional)
@nestjs/websockets,@nestjs/platform-socket.iosocket.io- WebSocket library
Development Dependencies
@nestjs/cli,@nestjs/schematics,@nestjs/testingtypescript,ts-node,ts-loadereslint,prettier- Code qualityjest,ts-jest,supertest- Testing
🤝 Contributing
Contributions, issues, and feature requests are welcome!
📄 License
MIT
👤 Author
Your Name
Made with ❤️ using NestJS
