Skip to content

About

nest-starter-kit - jwt, entity, typeorm, swagger

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

12 Commits

Folders and files

Repository files navigation

Nest Logo

NestJS Starter Kit

A comprehensive and production-ready NestJS backend solution for modern web applications

NPM Version Package License NPM Downloads

πŸ“‹ Table of Contents

πŸ“– Description

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.

✨ Features

πŸ—οΈ Core Features

  • NestJS Framework - TypeScript-based, scalable backend architecture
  • PostgreSQL + TypeORM - Powerful database integration and ORM support
  • Modular Structure - Clean and maintainable code organization

πŸ” Security

  • 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

πŸ“š API & Documentation

  • Swagger UI - Automatic API documentation and testing interface
  • OpenAPI 3.0 - Standard API specification
  • Interactive Testing - Live API testing through Swagger interface

πŸ›‘οΈ Error Handling & Validation

  • Global Exception Handling - Centralized error management
  • Response Transformation - Standard API response format
  • Validation Pipes - Input data validation
  • Class Validator - DTO-level validation

🌐 Additional Features

  • CORS Support - Cross-origin resource sharing
  • Environment Configuration - Environment-based configuration
  • Logging - Detailed logging system

πŸ›  Tech Stack

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

πŸš€ Installation

Prerequisites

  • Node.js (v22 or higher)
  • PostgreSQL (v17 or higher) OR Docker
  • npm or yarn

PostgreSQL Setup with Docker

  1. Run PostgreSQL with Docker
sudo docker run --name nest-starter-kit -e POSTGRES_USER=username -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres
  1. Access Docker container
docker exec -it nest-starter-kit bash
  1. Connect to PostgreSQL
psql -U username
  1. Create database
CREATE DATABASE nest_db;

Project Setup

  1. Clone the repository
git clone https://github.com/necatiboga/nest-starter-kit
cd nest-starter-kit
  1. Install dependencies
npm install
  1. Set up environment variables
cp .env.example .env
# Edit the .env file with your configuration
  1. Create database (if not using Docker)
# Create database in PostgreSQL
createdb nest-db

▢️ Running the App

# Development mode
npm run start:dev

# Production mode
npm run start:prod

# Debug mode
npm run start:debug

After running the application:

  • API Base URL: http://localhost:3000/api
  • Swagger UI: http://localhost:3000/swagger

πŸ”§ Environment Variables

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=30d

πŸ“š API Documentation

Swagger UI interface is available at http://localhost:3000/swagger

Main Endpoints

Authentication

  • POST /api/auth/register - User registration
  • POST /api/auth/login - User login
  • POST /api/auth/refresh-token - Token refresh
  • POST /api/auth/logout - Logout

Users

  • GET /api/users - Get users list (Admin only)
  • GET /api/users/profile - Get profile information
  • GET /api/users/:id - Get user by id (Admin only)
  • POST /api/users - Create new user (Admin only)
  • PATCH /api/update-profile - Update own profile
  • PATCH /api/users/:id - Update user by id (Admin only)
  • DELETE /api/users/:id - Delete user (Admin only)

πŸ“ Project Structure

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

🀝 Contributing

  1. Fork this repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.

πŸ“ž Contact

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!

About

nest-starter-kit - jwt, entity, typeorm, swagger

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages