Skip to content

cybernazmul/RBACStack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ Universal Full-Stack Admin Dashboard + RBAC

A production-ready, fully-featured admin dashboard template built with React 18, Node.js, and MySQL. Clone it once, configure it in minutes, and ship any client project on top of it β€” without rewriting the core.


πŸ“Έ Screenshots

Login Page

Clean centered card, show/hide password toggle, Zod validation, dark mode ready.

Login Page


Dashboard

KPI cards, AI insights banner, 4 interactive charts (area, bar, line, donut), sortable data table, quick actions, live activity feed, and system status with 90-day uptime history.

Dashboard


User Management β€” Users

Searchable, paginated user table. Add / Edit / Delete with role-based button visibility. Reset password action per user.

Users Page


User Management β€” Roles

Card grid layout. Each card shows user count, permission count, and an expandable permission chip view. Add/edit roles with a permission matrix picker.

Roles Page


User Management β€” Permissions

Role filter chips (Viewer Β· Admin Β· Editor Β· Moderator) with live permission counts. Full-width search with amber highlight. Module cards with toggle switches, progress bars, and Grant all / Revoke all actions. Unsaved changes banner with Save / Discard.

Permissions Page


Audit Logs

Server-side filtered, paginated log table. Filter by module, status, date range. Expandable rows show raw JSON meta. CSV export. Auto-refresh toggle (30 s).

Audit Logs


Collapsible Sidebar

Expands to show label + icon. Collapses to icon-only mode. User Management group shows a flyout submenu in collapsed mode. Active-route detection auto-opens the correct group.

Sidebar Collapsed


✨ Features

Core Template

Feature Detail
RBAC Dynamic role/permission system β€” no hardcoded role names anywhere
JWT Auth Access token (15 min, memory only) + Refresh token (7 days, httpOnly cookie)
Silent refresh Axios interceptor refreshes expired token and retries the original request
Audit logging Every write operation is automatically logged via middleware β€” no manual calls needed
Module system Add a module by editing one config file β€” sidebar, router, API routes, and seed all update automatically
Dark mode System-aware default, persisted to localStorage, smooth transition
Setup script node scripts/setup.js β€” installs deps, migrates DB, seeds data in one command

Dashboard UI

Feature Detail
KPI cards Revenue, Active Users, New Signups, System Uptime with trend indicators
AI Insights Auto-generated insight cards with icon + description
Charts User Growth (area), Traffic Sources (donut), Sales by Region (bar), Login Activity (line) β€” all via Recharts
DataTable Client-side sort, filter, pagination β€” reusable component
Quick Actions 6 shortcut buttons to key pages
System Status Per-service health + 90-day uptime history bar
Auto Refresh Live-polls analytics every 30 s when enabled

Sidebar

Feature Detail
Collapsible Toggle button on edge, smooth CSS transition
Groups Modules can be grouped under a parent (e.g. User Management)
Flyout In collapsed mode, clicking a group opens a fixed flyout submenu
Auto-open Active child route automatically opens its parent group
RBAC-aware Nav items hidden if user lacks the module's primary permission

Permissions Page

Feature Detail
Role chips Filter by role, shows granted permission count badge
Search Real-time filter with amber text highlight, result count
Module cards 2-column grid, progress bar, Grant all / Revoke all per module
Toggle switches Replaces checkboxes, smooth animation
Unsaved changes Accumulates changes, shows count banner, batch-saves on confirm

πŸ› οΈ Tech Stack

Layer Technology Version
Frontend framework React 18
Build tool Vite 5
Styling Tailwind CSS 3
Component library shadcn/ui (Radix primitives) latest
Global state Zustand 4
Server state + cache TanStack React Query 5
Forms React Hook Form + Zod 7 + 3
Charts Recharts 2
Routing React Router 6
Icons Lucide React latest
Toast notifications Sonner latest
HTTP client Axios latest
Backend Node.js + Express 18+ / 4
Database ORM Prisma 5
Database MySQL 8+
Auth JWT (jsonwebtoken + bcryptjs) latest
Validation (backend) Zod 3

πŸ“ Project Structure

dashboard/
β”œβ”€β”€ frontend/                        # React + Vite app
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   β”œβ”€β”€ axiosClient.js       # Axios instance + auth interceptors
β”‚   β”‚   β”‚   └── tokenStore.js        # In-memory access token (no localStorage)
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ charts/              # UserGrowth, LoginActivity, RoleDistribution, ModuleUsage
β”‚   β”‚   β”‚   β”œβ”€β”€ common/              # KPICard, DataTable, Badge, Modal, ConfirmDialog,
β”‚   β”‚   β”‚   β”‚                        #   StatCard, PageHeader, SystemStatus, QuickActions
β”‚   β”‚   β”‚   └── layout/              # AppLayout, Sidebar (collapsible + groups), Topbar
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   β”œβ”€β”€ app.config.js        # Branding, theme, API URL, pagination
β”‚   β”‚   β”‚   └── modules.config.js    # Module definitions (sidebar, routes, permissions)
β”‚   β”‚   β”œβ”€β”€ guards/
β”‚   β”‚   β”‚   β”œβ”€β”€ AuthGuard.jsx        # Redirect to /login if unauthenticated
β”‚   β”‚   β”‚   └── PermissionGuard.jsx  # Hide/show based on permission name
β”‚   β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”‚   β”œβ”€β”€ useDebounce.js
β”‚   β”‚   β”‚   └── usePermission.js     # Returns boolean from permission store
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/                # LoginPage
β”‚   β”‚   β”‚   β”œβ”€β”€ audit-logs/          # AuditLogsPage
β”‚   β”‚   β”‚   β”œβ”€β”€ dashboard/           # DashboardPage (full featured)
β”‚   β”‚   β”‚   β”œβ”€β”€ permissions/         # PermissionsPage (redesigned)
β”‚   β”‚   β”‚   β”œβ”€β”€ roles/               # RolesPage + RoleFormModal
β”‚   β”‚   β”‚   β”œβ”€β”€ settings/            # SettingsPage (profile, password, theme)
β”‚   β”‚   β”‚   └── users/               # UsersPage + UserFormModal
β”‚   β”‚   β”œβ”€β”€ router/index.jsx         # Dynamic routes from modules.config
β”‚   β”‚   β”œβ”€β”€ stores/
β”‚   β”‚   β”‚   β”œβ”€β”€ authStore.js         # User, isAuthenticated, isLoading, init/login/logout
β”‚   β”‚   β”‚   β”œβ”€β”€ permissionStore.js   # Permission list + hasPermission()
β”‚   β”‚   β”‚   └── uiStore.js           # Dark mode, sidebar collapsed state
β”‚   β”‚   └── utils/
β”‚   β”‚       β”œβ”€β”€ exportCsv.js
β”‚   β”‚       └── formatDate.js        # formatDate, formatDateTime, formatRelativeTime
β”‚   β”œβ”€β”€ .env                         # VITE_API_URL (empty = use Vite proxy)
β”‚   β”œβ”€β”€ .env.example
β”‚   β”œβ”€β”€ vite.config.js               # Proxy /api β†’ localhost:5001
β”‚   └── tailwind.config.js
β”‚
β”œβ”€β”€ backend/                         # Node.js + Express API
β”‚   β”œβ”€β”€ prisma/
β”‚   β”‚   β”œβ”€β”€ schema.prisma            # User, Role, Permission, RolePermission,
β”‚   β”‚   β”‚                            #   RefreshToken, AuditLog
β”‚   β”‚   └── seed.js                  # Seeds roles, permissions, admin user
β”‚   └── src/
β”‚       β”œβ”€β”€ app.js                   # Express app entry point
β”‚       β”œβ”€β”€ config/
β”‚       β”‚   └── modules.config.js    # Mirror of frontend modules config
β”‚       β”œβ”€β”€ middleware/
β”‚       β”‚   β”œβ”€β”€ auth.middleware.js   # JWT verification β†’ req.user
β”‚       β”‚   β”œβ”€β”€ permission.middleware.js  # requirePermission() factory
β”‚       β”‚   └── audit.middleware.js  # Auto-logs all write operations
β”‚       β”œβ”€β”€ modules/
β”‚       β”‚   β”œβ”€β”€ analytics/           # 5 aggregation endpoints for dashboard charts
β”‚       β”‚   β”œβ”€β”€ audit-logs/          # Paginated log query + CSV export
β”‚       β”‚   β”œβ”€β”€ auth/                # Login, refresh, logout, forgot/reset password
β”‚       β”‚   β”œβ”€β”€ permissions/         # Permission list + role-permission matrix
β”‚       β”‚   β”œβ”€β”€ roles/               # Role CRUD + toggle permission endpoint
β”‚       β”‚   └── users/               # User CRUD + /me self-service endpoints
β”‚       └── routes/index.js          # Auto-loads module routes from modules.config
β”‚
β”œβ”€β”€ scripts/
β”‚   └── setup.js                     # One-command project setup
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ GETTING_STARTED.md
β”‚   β”œβ”€β”€ ADDING_A_MODULE.md
β”‚   β”œβ”€β”€ RBAC_GUIDE.md
β”‚   β”œβ”€β”€ CONFIG_REFERENCE.md
β”‚   └── DEPLOYMENT.md
β”œβ”€β”€ package.json                     # Root: npm run setup / npm run dev
└── Promot.md                        # Master AI prompt file (10 build prompts)

πŸš€ Getting Started

Prerequisites

Requirement Version
Node.js 18 or higher
MySQL 8 or higher
npm 9 or higher

macOS users: Port 5000 is used by AirPlay Receiver. This project uses port 5001 for the backend. If you need to change it, update backend/.env β†’ PORT= and frontend/vite.config.js β†’ target:.


1. Clone & Install

git clone https://github.com/yourteam/admin-template.git my-project
cd my-project

# Remove template git history and start fresh
rm -rf .git
git init && git add . && git commit -m "initial: from admin-template v1.0"

2. Configure the Database

Open backend/.env (copy from .env.example if it doesn't exist):

DATABASE_URL=mysql://root:your-password@localhost:3306/admin_db
JWT_ACCESS_SECRET=<generate a 64-char random string>
JWT_REFRESH_SECRET=<generate a different 64-char random string>
JWT_ACCESS_EXPIRY=15m
JWT_REFRESH_EXPIRY=7d
PORT=5001
CLIENT_URL=http://localhost:5173
NODE_ENV=development

Generate secrets:

node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

3. Run Setup (One Command)

node scripts/setup.js

This automatically:

  1. βœ“ Checks Node.js version
  2. βœ“ Copies .env.example β†’ .env for both frontend and backend
  3. βœ“ Runs npm install in frontend/ and backend/
  4. βœ“ Generates Prisma client
  5. βœ“ Runs database migrations
  6. βœ“ Seeds default roles, permissions, and admin user

4. Start Development

npm run dev

This starts both servers concurrently:

Server URL
Frontend (Vite) http://localhost:5173
Backend (Express) http://localhost:5001

5. Login

Open http://localhost:5173 and sign in with:

Field Value
Email admin@admin.com
Password Admin@1234

πŸ” Default Roles & Permissions

Role Access
Admin Full access to all modules and actions
Editor View + Create + Edit on most modules. No delete, no role management
Viewer Read-only (.view permissions only)
Moderator View + Edit on most modules

Permissions follow the module.action naming convention:

users.view     users.create    users.edit      users.delete    users.reset_password
roles.view     roles.create    roles.edit      roles.delete
permissions.view               permissions.edit
logs.view      logs.export
settings.view  settings.edit
analytics.view

βž• Adding a New Module

Adding a module touches one config file β€” everything else wires up automatically.

# Step 1: Add to modules.config.js (frontend + backend)
{
  key: 'products',
  label: 'Products',
  icon: 'Package',
  path: '/products',
  core: false,
  permissions: ['products.view', 'products.create', 'products.edit', 'products.delete'],
}

# Step 2: Create 3 frontend files
frontend/src/pages/products/
  β”œβ”€β”€ productsApi.js       # Axios wrappers
  β”œβ”€β”€ ProductsPage.jsx     # Table + search + pagination
  └── ProductFormModal.jsx # Add/Edit form (React Hook Form + Zod)

# Step 3: Create 4 backend files
backend/src/modules/products/
  β”œβ”€β”€ products.schema.js     # Zod validation
  β”œβ”€β”€ products.service.js    # Prisma queries
  β”œβ”€β”€ products.controller.js # HTTP handlers
  └── products.routes.js     # Express routes + middleware

# Step 4: Add Prisma model + migrate
cd backend
npx prisma migrate dev --name add_products

# Step 5: Seed new permissions
npm run seed

See docs/ADDING_A_MODULE.md for the full guide with complete working code.


🧩 Sidebar Group Configuration

To group modules under a collapsible parent in the sidebar:

// modules.config.js β€” add group: 'key' to any module
{ key: 'users',       group: 'user-management', ... }
{ key: 'roles',       group: 'user-management', ... }
{ key: 'permissions', group: 'user-management', ... }

// Sidebar.jsx β€” define the group label and icon
const GROUP_META = {
  'user-management': {
    label: 'User Management',
    icon: 'UsersRound',
  },
}

The sidebar automatically:

  • Renders a collapsible section for the group
  • Opens it when a child route is active
  • Shows a flyout submenu in collapsed mode

πŸ”§ Configuration Reference

frontend/src/config/app.config.js

export const appConfig = {
  appName: 'Admin Dashboard',  // Sidebar header + browser tab
  appLogo: '/logo.svg',
  theme: {
    primaryColor: '#3b82f6',   // Change accent color per project
    darkMode: false,            // Default theme
  },
  pagination: { defaultPageSize: 10 },
  api: {
    baseUrl: '',                // Empty = use Vite proxy (recommended in dev)
                                // Set to https://api.yourdomain.com in production
  },
}

frontend/.env

VITE_API_URL=          # Leave empty in dev (Vite proxy handles it)
                       # Set to https://api.yourdomain.com in production
VITE_APP_NAME=Admin Dashboard

🚒 Deployment

Frontend β†’ Vercel / Netlify

# Build
cd frontend && npm run build

# Set environment variable in Vercel/Netlify dashboard:
VITE_API_URL=https://your-api-domain.com

Add frontend/public/_redirects for Netlify SPA routing:

/* /index.html 200

Backend β†’ VPS (PM2 + Nginx)

npm install -g pm2
pm2 start backend/src/app.js --name admin-api
pm2 save && pm2 startup

Production .env checklist:

NODE_ENV=production
JWT_ACCESS_SECRET=<64-char random>    # NOT the dev default
JWT_REFRESH_SECRET=<64-char random>   # Different from access secret
DATABASE_URL=mysql://user:pass@host/db
CLIENT_URL=https://your-frontend.com

See docs/DEPLOYMENT.md for full Nginx config and SSL setup.


πŸ“– Documentation

File Description
docs/GETTING_STARTED.md Prerequisites, clone, setup, common errors
docs/ADDING_A_MODULE.md Step-by-step with full working code example
docs/RBAC_GUIDE.md How to guard pages, buttons, and API endpoints
docs/CONFIG_REFERENCE.md Every config field documented with examples
docs/DEPLOYMENT.md Vercel, Netlify, VPS, PM2, Nginx, SSL
Promot.md Master AI prompt file β€” 10 prompts that built this template

πŸ—οΈ Development Workflow

Every new project follows this exact sequence:

Plan β†’ Configure β†’ Setup β†’ Database β†’ Backend β†’ Frontend
     β†’ Permissions β†’ Dashboard β†’ QA β†’ Deploy

Every new module follows:

Config β†’ Database β†’ Backend β†’ Frontend β†’ Permissions β†’ Test

Golden rule: Never skip phases. Building out of order breaks the template's assumptions.


🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Commit your changes: git commit -m 'add: my feature'
  4. Push: git push origin feature/my-feature
  5. Open a Pull Request

πŸ“„ License

MIT License β€” free for personal and commercial use.


Built with React 18 Β· Tailwind CSS Β· shadcn/ui Β· Node.js Β· Express Β· MySQL Β· Prisma Auth: JWT Β· State: Zustand Β· Charts: Recharts Β· Forms: React Hook Form + Zod

About

Production-ready full-stack admin dashboard with RBAC, JWT auth, audit logs, and modular architecture (React + Node + MySQL).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages