Skip to content

A full-stack RBAC (Role-Based Access Control) configuration tool that allows administrators to manage users, roles, and permissions through a secure dashboard with JWT-based authentication.

Notifications You must be signed in to change notification settings

Pranit-DC/RBAC-admin-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RBAC Admin Dashboard

A production-ready Role-Based Access Control (RBAC) Admin Dashboard built with Next.js, TypeScript, Prisma, and PostgreSQL, featuring secure authentication, fine-grained permission management, and an AI-assisted admin command interface.

This project demonstrates real-world access control design, backend validation, frontend enforcement, and deployment-grade practices.


🧠 What is RBAC? (Explained Simply)

Imagine a school:

  • Students can only enter their classroom
  • Teachers can access all classrooms
  • The Principal can access everything

Instead of giving everyone individual keys, we assign roles, and roles decide what actions are allowed.

That’s RBAC:

  • Users β†’ Roles β†’ Permissions
  • Easy to manage
  • Hard to break
  • Safe by default

🌐 Live Demo

πŸ”— Live Application: https://rbac-admin-tool.vercel.app

Deployed on Vercel with a Neon PostgreSQL database. The demo showcases full RBAC functionality including authentication, role & permission management, and the AI command assistant.


πŸš€ Key Highlights

  • πŸ” Secure JWT authentication with httpOnly cookies
  • 🧩 Modular RBAC system (Users, Roles, Permissions)
  • πŸ€– AI Command Box for natural-language admin actions
  • πŸ›‘οΈ Backend + frontend safety checks (no trust in UI)
  • 🧠 Edge-case handling (self-admin lockout prevention)
  • 🌐 Cloud-ready PostgreSQL (Neon)
  • ⚑ Deployed on Vercel (Production)

πŸ›  Tech Stack

Frontend

  • Next.js 16 (App Router)
  • React 19
  • TypeScript (Strict Mode)
  • TailwindCSS

Backend

  • Next.js API Routes
  • Prisma ORM v7
  • PostgreSQL (Neon)

Security & Auth

  • JWT authentication
  • httpOnly cookies
  • bcrypt password hashing
  • Middleware-based route protection

DevOps

  • Vercel deployment
  • Environment-based configuration
  • Prisma migrations

πŸ“ Project Structure

RBAC-admin-tool/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ auth/          # Authentication endpoints
β”‚   β”‚   β”œβ”€β”€ permissions/   # Permission CRUD
β”‚   β”‚   β”œβ”€β”€ roles/         # Role CRUD + mappings
β”‚   β”‚   └── users/         # User management
β”‚   β”œβ”€β”€ dashboard/         # Protected dashboard pages
β”‚   └── page.tsx           # Landing/login page
β”œβ”€β”€ lib/
β”‚   └── prisma.ts          # Prisma client singleton
β”œβ”€β”€ prisma/
β”‚   β”œβ”€β”€ schema.prisma      # Database schema
β”‚   └── migrations/        # Database migrations
└── middleware.ts          # Auth middleware

🧩 RBAC Design Principles

  • Users never receive permissions directly

  • Permissions are only assigned to roles

  • Users gain access only via roles

  • Admin role protections:

    • Automatically receives new permissions
    • Cannot remove its own admin access
    • Cannot be deleted accidentally

πŸ€– AI Command Assistant (Bonus Feature)

Admins can manage RBAC using natural language, safely.

Example Commands

Create permission users.export
Assign users.read permission to Editor role
Assign Admin role to admin@rbac.com

Delete permission reports.test

Safety Rules

  • No ambiguous commands
  • No implicit role creation
  • No Admin role modification
  • Allowlisted actions only
  • Safe failure (no side effects on uncertainty)

If the AI is unsure β†’ no action is taken


πŸ” Authentication Flow

  1. User logs in with email + password
  2. Password verified using bcrypt
  3. JWT generated and stored in httpOnly cookie
  4. Middleware validates JWT for protected routes
  5. Backend re-checks authorization on every request

UI checks are never trusted alone


πŸ§ͺ Demo Credentials

Email: admin@rbac.com
Password: admin123
Role: Admin

Demo credentials are for testing and portfolio use only


πŸ“‘ API Endpoints

Authentication

  • POST /api/auth/signup
  • POST /api/auth/login
  • GET /api/auth/me
  • POST /api/auth/logout

Permissions

  • GET /api/permissions
  • POST /api/permissions
  • PUT /api/permissions/[id]
  • DELETE /api/permissions/[id]

Roles

  • GET /api/roles
  • POST /api/roles
  • PUT /api/roles/[id]
  • DELETE /api/roles/[id]
  • POST /api/roles/[id]/permissions

Users

  • GET /api/users
  • POST /api/users/[id]/roles
  • GET /api/users/[id]/roles
  • DELETE /api/users/[id]

AI

  • POST /api/ai-command

πŸ—„οΈ Database Schema (Prisma)

model User {
  id         String   @id @default(uuid())
  email      String   @unique
  password   String
  created_at DateTime @default(now())
  user_roles UserRole[]
}

model Role {
  id         String   @id @default(uuid())
  name       String   @unique
  created_at DateTime @default(now())
  user_roles UserRole[]
  role_permissions RolePermission[]
}

model Permission {
  id          String   @id @default(uuid())
  name        String   @unique
  description String?
  created_at  DateTime @default(now())
  role_permissions RolePermission[]
}

model UserRole {
  user_id String
  role_id String
  user    User @relation(fields: [user_id], references: [id], onDelete: Cascade)
  role    Role @relation(fields: [role_id], references: [id], onDelete: Cascade)
  @@id([user_id, role_id])
}

model RolePermission {
  role_id       String
  permission_id String
  role          Role       @relation(fields: [role_id], references: [id], onDelete: Cascade)
  permission    Permission @relation(fields: [permission_id], references: [id], onDelete: Cascade)
  @@id([role_id, permission_id])
}

βš™οΈ Local Setup & Installation

1️⃣ Clone the Repository

git clone https://github.com/yourusername/RBAC-admin-tool.git
cd RBAC-admin-tool

2️⃣ Install Dependencies

npm install

3️⃣ Environment Variables

Create a .env file in the root directory:

DATABASE_URL="postgresql://username:password@host:5432/dbname"
JWT_SECRET="your-strong-secret"
GEMINI_API_KEY="your_gemini_api_key"

4️⃣ Generate Prisma Client & Migrate DB

npx prisma generate
npx prisma migrate dev

5️⃣ Start Development Server

npm run dev

Open πŸ‘‰ http://localhost:3000


πŸš€ Deployment (Vercel)

  • Push code to GitHub
  • Import repo into Vercel
  • Add environment variables in Vercel Dashboard
  • Deploy πŸš€

βœ”οΈ Auto-deploy enabled on every push to main


πŸ”’ Security Measures Implemented

  • bcrypt password hashing
  • JWT authentication with httpOnly cookies
  • Backend authorization enforcement
  • Middleware route protection
  • Prisma ORM (SQL injection safe)
  • Admin self-lockout prevention
  • AI command allowlisting
  • Environment-based secrets

Backend never trusts frontend input


🧠 Real-World Edge Cases Handled

  • Prevent deleting last Admin
  • Prevent Admin removing own Admin role
  • Prevent duplicate role/permission assignment
  • Case-insensitive role & permission checks
  • Safe rollback on partial failures
  • AI command ambiguity β†’ no mutation

πŸ›  Development Roadmap (Completed)

This project was built incrementally, following a structured, real-world development workflow.
All phases listed below are fully completed.

Phase 1: Database & Backend Foundation

  • βœ… PostgreSQL setup using Neon
  • βœ… Prisma schema design (Users, Roles, Permissions, mappings)
  • βœ… Database migrations
  • βœ… Environment configuration

Phase 2: Authentication & Security

  • βœ… Signup API with bcrypt password hashing
  • βœ… Login API with JWT-based authentication
  • βœ… httpOnly cookie implementation
  • βœ… Authentication middleware for protected routes
  • βœ… API testing using PowerShell scripts

Phase 3: Core RBAC APIs

  • βœ… Permission CRUD APIs
  • βœ… Role CRUD APIs
  • βœ… Role ↔ Permission mapping
  • βœ… User ↔ Role assignment
  • βœ… Comprehensive API testing

Phase 4: Frontend Dashboard UI

  • βœ… Login & Signup pages with form validation
  • βœ… Dashboard layout with sidebar navigation
  • βœ… Permissions management with CRUD modals
  • βœ… Roles management with permission checkbox assignment
  • βœ… Users management with role assignment
  • βœ… Protected routes
  • βœ… Logout functionality
  • βœ… Clean, consistent UI design (no gradients)

Phase 5: AI Command Assistant (Bonus)

  • βœ… AI command input interface
  • βœ… Natural language intent parsing
  • βœ… Command β†’ RBAC action mapping, such as:
    • Create a role called Manager
    • Assign users.read permission to Editor role
    • Remove admin role from user@email.com
  • βœ… /api/ai-command endpoint
  • βœ… Real-time command execution feedback
  • βœ… Strict safety rules (allowlisting & safe failure)

Phase 6: Polish & Deployment

  • βœ… Centralized error handling
  • βœ… Loading states & user feedback
  • βœ… Responsive UI improvements
  • βœ… Deployment on Vercel
  • βœ… Production testing with real data

🎯 Why This Project Matters

This is not CRUD demo code.

This project demonstrates:

  • Proper RBAC architecture
  • Secure authentication patterns
  • Backend-first authorization
  • TypeScript + Prisma correctness
  • Production debugging & deployment discipline
  • Responsible AI usage in admin systems

Exactly what real engineering teams expect.


πŸ“„ License

MIT License

Feel free to fork, learn, and extend πŸš€

About

A full-stack RBAC (Role-Based Access Control) configuration tool that allows administrators to manage users, roles, and permissions through a secure dashboard with JWT-based authentication.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published