Vishvjeet-Rana / nestjs-psql-api-project

Repository from Github https://github.comVishvjeet-Rana/nestjs-psql-api-projectRepository from Github https://github.comVishvjeet-Rana/nestjs-psql-api-project

NestJS Blog API

A scalable and type-safe RESTful API for a blogging platform built using NestJS, PostgreSQL, and Prisma. This backend includes modular features like authentication, user management, profile handling, post CRUD, image upload, validation, and error handling.


πŸš€ Tech Stack

  • Backend Framework: NestJS (TypeScript)
  • Database: PostgreSQL with Prisma ORM
  • Validation: Zod + Global Pipes
  • Authentication: JWT (Access Token)
  • File Uploads: Multer (local disk storage)
  • API Docs: Swagger (auto-generated)
  • Error Handling: Global Filters (HTTP, Zod, Prisma)

πŸ“‚ Features

βœ… Authentication

  • Register (with optional image)
  • Login (returns access token)
  • Forgot / Reset Password (email-based link with token)
  • Change Password (authenticated)

πŸ‘€ User Profile

  • View own profile
  • Update name/email
  • Upload/change profile picture

πŸ§‘β€πŸ’Ό Admin

  • View all users
  • View individual user
  • Create, update, or delete users
  • Assign roles (user/admin)

✍️ Blog Posts

  • Create a post (with optional image)
  • Get all or single post
  • Update or delete own posts

πŸ›‘οΈ Protected Routes

  • All user and post actions require a valid JWT.
  • Admin routes are restricted to admin role only.
  • Global JwtAuthGuard and RolesGuard used.

πŸ§ͺ Validation

  • Zod-based validation schemas for every request (body, params, query)
  • Global Zod Validation Pipe handles schema errors

πŸ“ Project Structure

nestjs-psql-api-project/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ auth/          # Auth module (login/register/reset)
β”‚   β”œβ”€β”€ user/          # Admin-only user mgmt
β”‚   β”œβ”€β”€ profile/       # Profile update & view
β”‚   β”œβ”€β”€ post/          # Post CRUD
β”‚   β”œβ”€β”€ common/        # DTOs, filters, pipes, interceptors
β”‚   β”œβ”€β”€ prisma/        # Prisma client + service
β”‚   └── main.ts        # App entry point

πŸ” Environment Variables

DATABASE_URL=postgresql://USER:PASSWORD@localhost:5432/DATABASE_NAME
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=1d

πŸ“¦ Setup & Run

git clone https://github.com/Vishvjeet-Rana/nestjs-psql-api-project.git
cd nestjs-psql-api-project
npm install

# setup db
npx prisma migrate dev --name init
npx prisma generate

# start dev server
npm run start:dev

πŸ“‘ API Documentation

Swagger is available at /docs after running the project.


πŸ§‘ Author

Built with care by Vishvjeet Rana

About


Languages

Language:TypeScript 98.5%Language:JavaScript 1.5%