REST API built with NestJS, PostgreSQL, TypeORM, and JWT Authentication
A Library Book Management System API built using NestJS, PostgreSQL, and TypeORM with JWT Authentication, Token Blacklist, Logout-All Sessions, and Role-Based Access Control (Admin & User).
This project demonstrates:
- ๐ Secure Authentication
- ๐จโ๐ผ Admin & ๐ค User Roles
- ๐ Book CRUD Operations
- ๐ก Swagger API Documentation
- ๐งช Postman Testing
- โ๏ธ Config Module & Environment Variables
- ๐งฑ Clean Backend Architecture
| Feature | Description |
|---|---|
| Register | User account creation |
| Login | JWT authentication |
| Logout | Blacklist current token |
| Logout All | Logout from all devices |
| Token Blacklist | Stores logged out JWT tokens |
| Scheduler | Removes expired tokens daily |
| Default Admin | Pre-created admin account |
| Guards | Protected routes |
| JWT | Token-based security |
| Feature | Admin | User |
|---|---|---|
| View All Books | โ | โ |
| View Book by ID | โ | โ |
| Create Books | โ | โ |
| Update Books | โ | โ |
| Delete Books | โ | โ |
| Feature | Admin | User |
|---|---|---|
| Register | โ | โ |
| Login | โ | โ |
| View All Users | โ | โ |
| Delete Users | โ | โ |
| Delete Admin | โ | โ |
| Logout | โ | โ |
| Logout-all | โ | โ |
| Technology | Usage |
|---|---|
| NestJS | Backend Framework |
| PostgreSQL | Database |
| TypeORM | ORM |
| JWT | Authentication |
| Swagger | API Documentation |
| Class Validator | DTO Validation |
| Guards | Authorization |
| Middleware | Request Handling |
| Interceptors | Response Control |
| Exception Filters | Error Handling |
| Postman | API Testing |
| Config Module | Environment Config |
src
โ
โโโ auth
โโโ users
โโโ books
โโโ blacklist
โโโ common
โ โโโ guards
โ โโโ decorators
โ โโโ interceptors
โ โโโ filters
โ โโโ middleware
โ
โโโ config
โโโ app.module.ts
โโโ main.ts
Email: admin@library.com
Password: admin123
POST /auth/register
POST /auth/login
POST /auth/logout
POST /auth/logout-all
POST /admin/books
GET /admin/books
GET /admin/books/:id
PATCH /admin/books/:id
DELETE /admin/books/:id
GET /users
GET /users/:id
DELETE /users/admin/:id
GET /users/books
GET /users/books/:id
http://localhost:3000/api
Test all APIs directly in browser.
Use the Postman collection to test all API endpoints easily.
- Login as Admin
- Copy JWT Token
- Add Bearer Token in Authorization
- Test APIs
git clone https://github.com/rocky-rakesh2004/Library-management-system-backend.gitcd Library-management-system-backendnpm installCreate database:
library_db
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=yourpassword
DB_NAME=library_db
JWT_SECRET=librarysecret
JWT_EXPIRES_IN=1d
PORT=3000
npm run start:dev| Service | URL |
|---|---|
| Server | http://localhost:3000 |
| Swagger | http://localhost:3000/api |
- Learn NestJS architecture
- Understand JWT authentication
- Implement role-based authorization
- Work with PostgreSQL and TypeORM
- Build real-world backend APIs
- Prepare for backend developer roles
RAKESH
GitHub: https://github.com/rocky-rakesh2004
If you like this project:
โญ Star the repository ๐ด Fork it ๐ ๏ธ Contribute ๐ฉ Share feedback
Made with โค๏ธ using NestJS