Welcome to the NestJS Modular Project Starter! π This boilerplate is designed to kickstart your NestJS applications with a highly modular architecture, Docker support, Profile-based configuration, and Swagger documentation. It's perfect for developers aiming to build enterprise-grade, scalable, and maintainable applications.
Hereβs an overview of the full project structure:
project-root/
βββ docker/
β βββ nginx/ # Nginx configuration and Dockerfile
β βββ mysql/ # MySQL configuration and Dockerfile
β βββ postgres/ # PostgreSQL configuration and Dockerfile
β βββ app/ # Application-specific Dockerfile
βββ src/
β βββ modules/ # All feature modules
β β βββ user/ # Example: User module
β β β βββ controllers/ # Handles HTTP requests
β β β βββ services/ # Business logic
β β β βββ repositories/# Database interactions
β β β βββ entities/ # Database models
β β β βββ dtos/ # Data Transfer Objects
β β β βββ interfaces/ # TypeScript interfaces
β β β βββ user.module.ts # Main module file
β β βββ auth/ # Example: Authentication module
β β βββ controllers/ # Auth-related routes
β β βββ services/ # Authentication logic
β β βββ strategies/ # Auth strategies (e.g., JWT)
β β βββ guards/ # Route protection
β β βββ auth.module.ts
β βββ common/ # Shared utilities and functionalities
β β βββ decorators/ # Custom decorators
β β βββ filters/ # Exception filters
β β βββ pipes/ # Validation pipes
β β βββ enums/ # Shared enums (e.g., status codes, Swagger settings)
β β βββ utils/ # Helper functions
β βββ configs/ # Configuration files
β β βββ database.config.ts # Database configurations
β β βββ app.config.ts # General app configurations
β β βββ swagger.config.ts # Swagger-specific configurations
β β βββ jwt.config.ts # JWT configurations
β βββ core/ # Core functionalities
β β βββ database/ # Database module
β β βββ logger/ # Logging system
β β βββ swagger/ # Swagger setup
β β βββ core.module.ts # Core module
β βββ main.ts # Entry point of the application
βββ docker-compose.mysql.yml # Docker Compose for MySQL
βββ docker-compose.postgres.yml # Docker Compose for PostgreSQL
βββ .env # Environment variables
βββ .dockerignore # Docker ignore rules
βββ .gitignore # Git ignore rules
βββ package.json # Project dependencies and scripts
- Dockerized Development: Pre-configured with Docker and Docker Compose for easy setup and deployment.
- Multiple Databases: Switch between MySQL and PostgreSQL seamlessly using environment variables.
- Swagger Integration: Auto-generated API documentation with built-in support for bearer authentication.
- Environment-based Configuration: Centralized configuration management for different environments (development, production, staging).
- Reusable Components: Shared decorators, filters, pipes, and utilities for a streamlined codebase.
- Authentication Ready: JWT-based authentication module with guards and strategies.
- Modular Design: Clean separation of concerns with fully encapsulated modules.
- Nginx Integration: Acts as a reverse proxy, ready for SSL, caching, and load balancing.
git clone https://github.com/afsh7n/nestStart.git
cd nestStart
If you plan to run the project locally:
npm install
Create a .env
file in the project root. Hereβs a sample configuration:
# ========================
# General Configuration
# ========================
PORT=3000 # Application port
NODE_ENV=development # Environment: development, production, or staging
PREFIX_API=api
# ========================
# Database Configuration
# ========================
DB_TYPE=postgres # Database type: mysql or postgres
DB_HOST=postgres # Database host (service name in Docker)
DB_PORT=5432 # Database port
DB_USERNAME=admin # Database username
DB_PASSWORD=password # Database password
DB_NAME=my_database # Database name
# ========================
# Swagger Configuration
# ========================
SWAGGER_TITLE=My Awesome API # Title of the Swagger documentation
SWAGGER_DESCRIPTION=API Documentation for My Awesome API # Description of the API
SWAGGER_VERSION=1.0 # API version for Swagger
SWAGGER_PATH=api/docs # URL path for Swagger UI
SWAGGER_BEARER_AUTH=true # Enable bearer authentication in Swagger
# ========================
# JWT Configuration
# ========================
JWT_SECRET=my_super_secret_key
JWT_EXPIRES_IN=1h
docker-compose -f docker-compose.mysql.yml up --build
docker-compose -f docker-compose.postgres.yml up --build
- Swagger UI: http://localhost/api/docs
- App Direct Access: http://localhost:3000
- Set up a local database (e.g., MySQL or PostgreSQL) and update
.env
accordingly. - Run the app:
npm run start:dev
- GET /users: Get the list of users (protected route; requires login).
- POST /users: Add a new user (for testing purposes).
- POST /auth/register: Register a new user.
- POST /auth/login: Login with username and password to obtain a JWT.
We welcome contributions! Feel free to:
- Submit pull requests π
- Report bugs π
- Suggest new features β¨
- Nginx: Acts as a reverse proxy for the application.
- App Service: Runs the NestJS application inside a Node.js container.
- MySQL/PostgreSQL: Database services are dynamically set up using
.env
.
This project is licensed under the MIT License. You are free to use, modify, and distribute.
Thank you for using this starter template! If you find it useful, please β the repository and share it with others.
Happy coding! π»β¨