Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 2 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 (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-22T14:22:25.000Z (about 2 months ago)
- Last Synced: 2024-11-22T14:23:16.099Z (about 2 months ago)
- Topics: api, docker, environment, mysql, nestjs, nginx, nodejs, postgresql, scalable-architecture, typescript
- Language: TypeScript
- Homepage:
- Size: 96.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π NestJS Modular Project Starter (Updated with Docker and Setup Guide)
Welcome to the **NestJS Modular Project Starter**! π This boilerplate is enhanced with **Docker**, **Docker Compose**, and **Profile-based configuration** for maximum flexibility and scalability. With a clean folder structure, this project is perfect for building enterprise-grade 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
β β βββ 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
β β βββ utils/ # Helper functions
β βββ configs/ # Configuration files
β β βββ database.config.ts # Database configurations
β β βββ app.config.ts # General app configurations
β βββ core/ # Core functionalities
β β βββ database/ # Database module
β β βββ logger/ # Logging system
β β βββ core.module.ts # Core module
β βββ main.ts # Entry point of the application
βββ docker-compose.yml # Docker Compose configuration
βββ .env # Environment variables
```---
## β¨ Features
- **Docker & Profiles**: Use Docker Compose profiles to toggle between **MySQL** and **PostgreSQL** with a single command.
- **Modular Design**: Each feature is encapsulated in its module, making the app highly scalable and maintainable.
- **Reusable Components**: Shared decorators, pipes, filters, and utilities for streamlined development.
- **Environment-based Configuration**: Easily switch between development, staging, and production environments.
- **Extensible Core**: Add custom functionalities like logging and caching with ease.
- **Nginx Integration**: Ready for performance improvements, SSL, and load balancing.---
## π οΈ Setup and Run the Project
Follow these steps to set up and run the project:
---
### **1οΈβ£ Clone the Repository**
```bash
git clone https://github.com/afsh7n/nestStart.git
cd nestStart
```---
### **2οΈβ£ Install Dependencies (Optional for Local Development)**
If youβre running the project locally (without Docker):
```bash
npm install
```---
### **3οΈβ£ Configure Environment Variables**
Create a `.env` file in the project root. Here's an example:```plaintext
# ========================
# General Configuration
# ========================
PORT=3000 # Application port
NODE_ENV=development # Environment: development, production, or staging# ========================
# 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=Detailed API documentation for My Awesome API # Description of the API
SWAGGER_VERSION=2.0 # API version for Swagger
SWAGGER_PATH=api/docs # URL path for Swagger UI
SWAGGER_BEARER_AUTH=true # Enable bearer authentication in Swagger```
---
### **4οΈβ£ Run the Project with Docker**
The project is pre-configured to use Docker Compose for running the app along with the database.#### **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**
- The app will be available at:
- App (direct): [http://localhost:3000](http://localhost:3000)
- Via Nginx: [http://localhost](http://localhost)- You can test database connections using tools like `pgAdmin` (PostgreSQL) or `MySQL Workbench`.
---
### **6οΈβ£ Run Locally (Optional)**
If youβre not using Docker and want to run the app locally:
1. Install a database (e.g., MySQL or PostgreSQL) and configure `.env` accordingly.
2. Run the app in development mode:
```bash
npm run start:dev
```
3. For production:
```bash
npm run build
npm run start:prod
```---
## π― Usage
### π Adding a New Module
1. Create a folder under `src/modules/`:
```plaintext
src/modules/new-module/
```
2. Add `controllers/`, `services/`, `entities/`, etc., as needed.
3. Register the module in `app.module.ts`:
```typescript
import { NewModule } from './modules/new-module/new.module';
@Module({
imports: [NewModule],
})
export class AppModule {}
```---
## π³ Docker Overview
- **Nginx**: Serves as a reverse proxy for the app and is ready for SSL integration.
- **App Service**: Runs the NestJS application inside a Node.js container.
- **MySQL**: Configured with a custom Dockerfile and `my.cnf` for database needs.
- **PostgreSQL**: Includes an `init.sql` file to set up the database dynamically using environment variables.---
## π§βπ» Contributing
We welcome contributions from the community! π€
Feel free to:
- Submit a pull request π
- Report issues π
- Share feedback π¬---
## π To-Do List
- [ ] Add unit and integration tests π§ͺ
- [ ] Configure CI/CD pipelines βοΈ
- [ ] Add support for GraphQL π
- [ ] Extend the logger for analytics π
- [ ] Set up Nginx for SSL and caching optimization π---
## π License
This project is licensed under the [MIT License](LICENSE).
Feel free to use and modify it as needed!---
## π€© Final Thoughts
With this setup guide, you can run the project both locally and via Docker with ease. If you like this project, please give it a β on [GitHub](https://github.com/your-repo).
Happy coding! π»β¨---
### π Let's Build Something Amazing Together!
![Happy Coding GIF](https://media.giphy.com/media/xT0xeMA62E1XIlup68/giphy.gif)
---
This updated README now includes a clear setup guide for both local development and Docker-based workflows, making it simple for new developers to get started! π