https://github.com/afsh7n/neststart
π A scalable and modular NestJS starter with π³ Docker, π PostgreSQL, π¬ MySQL, and π environment-based configurations for modern app development.
https://github.com/afsh7n/neststart
api docker environment mysql nestjs nginx nodejs postgresql scalable-architecture typescript
Last synced: 4 months ago
JSON representation
π A scalable and modular NestJS starter with π³ Docker, π PostgreSQL, π¬ MySQL, and π environment-based configurations for modern app development.
- Host: GitHub
- URL: https://github.com/afsh7n/neststart
- Owner: afsh7n
- Created: 2024-11-22T13:09:13.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-11-23T01:16:25.000Z (7 months ago)
- Last Synced: 2025-01-23T07:11:17.543Z (5 months ago)
- Topics: api, docker, environment, mysql, nestjs, nginx, nodejs, postgresql, scalable-architecture, typescript
- Language: TypeScript
- Homepage:
- Size: 217 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π 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:
```plaintext
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**
```bash
git clone https://github.com/afsh7n/nestStart.git
cd nestStart
```---
### **2οΈβ£ Install Dependencies**
If you plan to run the project locally:
```bash
npm install
```---
### **3οΈβ£ Configure Environment Variables**
Create a `.env` file in the project root. Hereβs a sample configuration:```plaintext
# ========================
# 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:**
```bash
docker-compose -f docker-compose.mysql.yml up --build
```#### **For PostgreSQL:**
```bash
docker-compose -f docker-compose.postgres.yml up --build
```---
### **5οΈβ£ Access the Application**
- **Swagger UI**: [http://localhost/api/docs](http://localhost/api/docs)
- **App Direct Access**: [http://localhost:3000](http://localhost:3000)---
### **6οΈβ£ Run Locally (Without Docker)**
1. Set up a local database (e.g., MySQL or PostgreSQL) and update `.env` accordingly.
2. Run the app:
```bash
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](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! π»β¨