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.
- 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)
- Register (with optional image)
- Login (returns access token)
- Forgot / Reset Password (email-based link with token)
- Change Password (authenticated)
- View own profile
- Update name/email
- Upload/change profile picture
- View all users
- View individual user
- Create, update, or delete users
- Assign roles (user/admin)
- Create a post (with optional image)
- Get all or single post
- Update or delete own posts
- All user and post actions require a valid JWT.
- Admin routes are restricted to
admin
role only. - Global
JwtAuthGuard
andRolesGuard
used.
- Zod-based validation schemas for every request (
body
,params
,query
) - Global Zod Validation Pipe handles schema errors
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
DATABASE_URL=postgresql://USER:PASSWORD@localhost:5432/DATABASE_NAME
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=1d
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
Swagger is available at /docs
after running the project.
Built with care by Vishvjeet Rana