Skip to content
/ nestStart Public template

πŸš€ A scalable and modular NestJS starter with 🐳 Docker, 🐘 PostgreSQL, 🐬 MySQL, and 🌍 environment-based configurations for modern app development.

Notifications You must be signed in to change notification settings

afsh7n/nestStart

Repository files navigation

πŸš€ NestJS Modular Project Starter (Enhanced with Docker, Swagger, and Configurations)

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.


πŸ“‚ Project Structure

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

✨ Features

  • 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.

πŸ› οΈ Setup and Run the Project

1️⃣ Clone the Repository

git clone https://github.com/afsh7n/nestStart.git
cd nestStart

2️⃣ Install Dependencies

If you plan to run the project locally:

npm install

3️⃣ Configure Environment Variables

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

4️⃣ Run with Docker

For MySQL:

docker-compose -f docker-compose.mysql.yml up --build

For PostgreSQL:

docker-compose -f docker-compose.postgres.yml up --build

5️⃣ Access the Application


6️⃣ Run Locally (Without Docker)

  1. Set up a local database (e.g., MySQL or PostgreSQL) and update .env accordingly.
  2. Run the app:
    npm run start:dev

πŸ”— API Endpoints

User Module

  • GET /users: Get the list of users (protected route; requires login).
  • POST /users: Add a new user (for testing purposes).

Auth Module

  • POST /auth/register: Register a new user.
  • POST /auth/login: Login with username and password to obtain a JWT.

πŸ“‹ Contributing

We welcome contributions! Feel free to:

  • Submit pull requests πŸš€
  • Report bugs 🐞
  • Suggest new features ✨

🐳 Docker Overview

  • 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.

πŸ“œ License

This project is licensed under the MIT License. You are free to use, modify, and distribute.


🀩 Final Thoughts

Thank you for using this starter template! If you find it useful, please ⭐ the repository and share it with others.
Happy coding! πŸ’»βœ¨

About

πŸš€ A scalable and modular NestJS starter with 🐳 Docker, 🐘 PostgreSQL, 🐬 MySQL, and 🌍 environment-based configurations for modern app development.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published