A comprehensive and production-ready NestJS backend solution for modern web applications
- Description
- Features
- Tech Stack
- Installation
- Running the App
- Environment Variables
- API Documentation
- Project Structure
- Contributing
This project is a NestJS-based starter kit that provides a solid foundation for modern web applications. Built with TypeScript, it includes essential features like authentication, authorization, database management, and API documentation.
- NestJS Framework - TypeScript-based, scalable backend architecture
- PostgreSQL + TypeORM - Powerful database integration and ORM support
- Modular Structure - Clean and maintainable code organization
- JWT Authentication - Access & Refresh token system
- Role-Based Authorization - Admin/User role management
- Password Hashing - Secure password storage with Bcrypt
- Guards & Decorators - Endpoint-level security
- Swagger UI - Automatic API documentation and testing interface
- OpenAPI 3.0 - Standard API specification
- Interactive Testing - Live API testing through Swagger interface
- Global Exception Handling - Centralized error management
- Response Transformation - Standard API response format
- Validation Pipes - Input data validation
- Class Validator - DTO-level validation
- CORS Support - Cross-origin resource sharing
- Environment Configuration - Environment-based configuration
- Logging - Detailed logging system
| Category | Technology |
|---|---|
| Framework | NestJS, Express |
| Language | TypeScript |
| Database | PostgreSQL |
| ORM | TypeORM |
| Authentication | JWT, Passport |
| Validation | Class-validator, Class-transformer |
| Documentation | Swagger/OpenAPI |
| Code Quality | ESLint, Prettier |
- Node.js (v22 or higher)
- PostgreSQL (v17 or higher) OR Docker
- npm or yarn
- Run PostgreSQL with Docker
sudo docker run --name nest-starter-kit -e POSTGRES_USER=username -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres- Access Docker container
docker exec -it nest-starter-kit bash- Connect to PostgreSQL
psql -U username- Create database
CREATE DATABASE nest_db;- Clone the repository
git clone https://github.com/necatiboga/nest-starter-kit
cd nest-starter-kit- Install dependencies
npm install- Set up environment variables
cp .env.example .env
# Edit the .env file with your configuration- Create database (if not using Docker)
# Create database in PostgreSQL
createdb nest-db# Development mode
npm run start:dev
# Production mode
npm run start:prod
# Debug mode
npm run start:debugAfter running the application:
- API Base URL:
http://localhost:3000/api - Swagger UI:
http://localhost:3000/swagger
Set up the following variables in your .env file:
# Database Configuration
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USER=your_username
DATABASE_PASSWORD=your_password
DATABASE_NAME=nest-db
# JWT Configuration
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES_IN=1h
JWT_REFRESH_SECRET=your_refresh_secret_key
JWT_REFRESH_EXPIRES_IN=30dSwagger UI interface is available at http://localhost:3000/swagger
POST /api/auth/register- User registrationPOST /api/auth/login- User loginPOST /api/auth/refresh-token- Token refreshPOST /api/auth/logout- Logout
GET /api/users- Get users list (Admin only)GET /api/users/profile- Get profile informationGET /api/users/:id- Get user by id (Admin only)POST /api/users- Create new user (Admin only)PATCH /api/update-profile- Update own profilePATCH /api/users/:id- Update user by id (Admin only)DELETE /api/users/:id- Delete user (Admin only)
src/
βββ common/ # Shared components
β βββ filters/ # Exception filters
β βββ interceptors/ # Response interceptors
β βββ interfaces/ # Common interfaces
βββ config/ # Configuration files
β βββ database/ # Database configuration
βββ modules/ # Application modules
β βββ auth/ # Authentication module
β β βββ decorators/ # Auth decorators
β β βββ dto/ # Data Transfer Objects
β β βββ guards/ # Auth guards
β β βββ strategies/ # Passport strategies
β βββ users/ # Users module
β βββ dto/ # User DTOs
β βββ entities/ # User entity
βββ app.module.ts # Main application module
βββ main.ts # Application entry point
- Fork this repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to open an issue or submit a pull request for any questions or suggestions.
β If you like this project, don't forget to give it a star!