As developers, we often face challenges in building maintainable and scalable backend systems. Questions like:
- How do I manage multiple modules efficiently?
- Whatβs the best way to integrate Docker for database switching?
- How can I auto-generate API documentation while ensuring security?
To address these challenges, Iβve created a NestJS Starter Template that streamlines backend development. Itβs packed with features like modular design, Docker integration, JWT authentication, and Swagger documentation.
What is This Template About?
This starter template is designed for developers who want to hit the ground running with NestJS, a progressive Node.js framework. It includes:
- Scalable Modular Architecture: Each feature is encapsulated, making the codebase clean and maintainable.
- Pre-configured Docker Setup: Switch between MySQL and PostgreSQL with ease.
- Swagger Documentation: Automatically generated and interactive API docs.
- JWT Authentication: Secure authentication out of the box.
- Environment-based Configuration: Centralized management for development, staging, and production.
Key Features
1οΈβ£ Modular Design
The template uses a feature-based folder structure:
src/
βββ modules/
β βββ auth/ # Authentication module
β βββ user/ # User module
βββ common/ # Shared utilities (e.g., decorators, pipes)
βββ configs/ # Environment configurations
βββ core/ # Core functionalities (e.g., database, logger)
2οΈβ£ Dockerized Development
Whether you prefer MySQL or PostgreSQL, the setup is pre-configured:
# Run with MySQL
docker-compose -f docker-compose.mysql.yml up --build
Run with PostgreSQL
docker-compose -f docker-compose.postgres.yml up --build
3οΈβ£ JWT Authentication
The starter comes with:
- Register Route: Sign up new users.
- Login Route: Authenticate and receive a JWT.
- Protected Routes: Access only with a valid token.
4οΈβ£ Swagger Integration
API documentation is auto-generated with Swagger, accessible at /api/docs
.
How to Get Started
Step 1: Clone the Repository
git clone
cd nestStarthttps://github.com/your-repo/nestStart.git
Step 2: Configure Environment Variables
# General Configuration
PORT=3000
NODE_ENV=development
Database Configuration
DB_TYPE=postgres
DB_HOST=postgres
DB_PORT=5432
DB_USERNAME=admin
DB_PASSWORD=password
DB_NAME=my_database
JWT Configuration
JWT_SECRET=my_super_secret_key
JWT_EXPIRES_IN=1h
Step 3: Run the Application
# Using Docker
docker-compose -f docker-compose.postgres.yml up --build
Or run locally
npm install
npm run start:dev
Endpoints
- POST /auth/register: Register a new user.
- POST /auth/login: Authenticate and get a JWT.
- GET /users: View all users (requires authentication).
Whatβs Next?
I plan to enhance the template with:
- Advanced logging and analytics
- GraphQL support
- Unit and integration tests
Conclusion
This starter template is my contribution to the developer community. Itβs open-source, flexible, and ready for production. Whether you're building an API for a startup or managing an enterprise-grade application, this template will save you hours of setup time.
Iβd love to hear your feedback. What features would you like to see added? Letβs connect and build something amazing together. π»β¨
Feel free to use and customize this article for your LinkedIn post. Let me know if you need further adjustments! π
Top comments (0)