This project is a User Management and Role-Based Access Control (RBAC) backend system used to manage users, authentication, and secure access within an application. It includes features like user login, protected routes, role assignment, and user management. The project is designed with a scalable and modular structure for real-world applications. Future improvements include permissions, audit logs, notifications, and advanced security features.
- TypeScript
- Node.js
- Express.js
- PostgreSQL
- pg (Raw PostgreSQL Driver)
- JWT Authentication
- bcrypt
- Zod Validation
- Winston + Morgan Logging
- User Registration
- User Login
- JWT Token Generation
- Password Hashing using bcrypt
- Protected Routes using JWT Middleware
Create User Get Logged-in User Get All Users Get User By ID Update User Soft Delete User
Create Roles Assign Roles to Users Fetch User Roles RBAC Foundation
Zod Request Validation Error Handling Middleware Request Logging Request ID Tracking Centralized Response Helper
git clone <your-repository-url>
cd user_managementcd backend
pnpm installDownload and install PostgreSQL from: https://www.postgresql.org/download/?utm_source=chatgpt.com
During installation: Remember your PostgreSQL password
Keep the default port as 5432
Open PostgreSQL Shell (psql) or pgAdmin and run:
CREATE DATABASE user_management;Create a .env file inside the backend folder:
PORT=5000
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=your_password
DB_NAME=user_managementcd backend
pnpm run migration:runStart Backend Server
cd backend
pnpm run dev- Node js(v18 or Higher)
- pnpm
- Backend server running locally
Navigate to the frontend directory:
cd frontend
Install dependencies
pnpm install
Start the development server:
pnpm run dev
The application will be available at:
Application Routes
| Route | Description |
|---|---|
| / | Welcome page |
| /users | Displays user data from backend API |
Protected endpoints require a valid JWT token.
For development and testing, store the token in browser local storage:
localStorage.setItem(
"token",
"YOUR_JWT_TOKEN"
);
Verify stored token:
localStorage.getItem("token");The frontend automatically includes the token in API requests when fetching protected resources.