This is a basic NestJS starter template that comes pre-configured with essential features to help developers quickly start building applications with:
- ✅ JWT Authentication
- 👤 User Management
- 🗄️ Database Integration
- 📥 Input/Payload Validation using Joi
- 🔐 Secure Password Hashing using bcrypt
This template is designed to eliminate repetitive setup work and help you focus on building actual business logic.
By cloning this repository, you'll get:
- 🧱 Modular project structure with pre-configured routes, controllers, services
- 🧩 A generic database service that works across schemas like
accountsandusers - 🔐 JWT-based Authentication system for signup and signin flows
- 🔐 bcrypt password hashing for secure password storage and verification
- 📦 Input validation system using the
joipackage- Define validation schemas inside the
validations/folder - Easily customizable error formatting using pipes
- Define validation schemas inside the
- 📄 Swagger Documentation for all APIs including Auth, Users, and Accounts
- 🗃️ Configuration file structure for MongoDB and JWT
- 🔁 Environment-based config support
-
✅ JWT Authentication (signup/signin)
-
🔐 Password hashing with bcrypt
-
👤 User CRUD operations
-
🧱 Modular architecture
-
🧩 Generic database service
-
⚙️ Pre-configured routes and controllers
-
📄 Swagger API documentation
-
📝 Sample configuration file (
sample.config.ts)
Swagger is already set up.
This template uses bcrypt to ensure secure handling of user passwords:
- During signup, passwords are hashed using
bcrypt.hash()before being saved to the database. - During signin, the plain-text password is compared using
bcrypt.compare()against the stored hash.
This ensures user credentials are safely encrypted, following best practices for authentication.
Make sure you have the following installed:
git clone https://github.com/vraj-verma/nestjs-template.gitcd nestjs-templatenpm iSample data
{
"MONGOCONFIG": {
"DATABASE_NAME": "mytestdb",
"PORT": 27017,
"URI": "mongodb://localhost:27017"
},
"JWT_SECRET": "thi$-$hould-be-very-$ecure",
"JWT_EXPIRY": "5d"
};npm run start:dev Runs at: http://localhost:7001
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/signup |
Register new user |
| POST | /auth/signin |
Login user |
{
"name": "Sumit Verma",
"email": "sumit@stackly.in",
"password": "test123"
}
| Method | Endpoint | Description |
|---|---|---|
| GET | /users |
Get all users |
| GET | /users/:id |
Get single user |
| POST | /users |
Create new user |
| PUT | /users/:id |
Update user |
| DELETE | /users/:id |
Delete user |
| Method | Endpoint | Description |
|---|---|---|
| GET | /accounts |
Get account details & users under it |
| PATCH | /accounts |
Update account details |
| DELETE | /accounts |
Delete account |
src/
├── accounts/ # Account-related modules and logic
├── auth/ # Authentication module (signup, signin)
├── constants/ # Application-wide constants
├── db/ # Database configuration and services
├── enums/ # Enum definitions used across the app
├── errors/ # Custom error classes and handlers
├── guards/ # Route guards (e.g., JWT, roles)
├── pipes/ # Pipes for validation, transformation, etc.
├── schema/ # Mongoose or other DB schemas
├── types/ # Global TypeScript types and interfaces
├── users/ # User module (CRUD logic, services, controllers)
├── utils/ # Utility functions/helpers
├── validations/ # Joi validation logic
├── app.controller.ts # Root application controller
├── app.module.ts # Root application module
├── main.ts # Entry point of the application
We welcome contributions to improve this project! Follow the steps below to contribute:
Create a copy of the repository under your own GitHub account.
git checkout -b feature/your-featuregit commit -m "Add your feature"git push origin feature/your-featureGo to your forked repository on GitHub and click on "New Pull Request" to submit your changes for review.