A full-stack web application with JWT authentication, role-based access control (Admin/User), and a real-time activity tracking system.
| Layer | Technology |
|---|---|
| Backend | Node.js, Express.js |
| Database | MongoDB + Mongoose ODM |
| Auth | JWT (JSON Web Tokens) + bcryptjs |
| Frontend | React.js 18, React Router v6 |
| Styling | Custom CSS (design system) |
| HTTP | Axios with interceptors |
| Toasts | react-hot-toast |
task-manager/
βββ backend/
β βββ config/
β β βββ db.js # MongoDB connection
β βββ controllers/
β β βββ authController.js # Register, Login, GetMe
β β βββ taskController.js # User CRUD for tasks
β β βββ adminController.js # Admin APIs
β βββ middleware/
β β βββ auth.js # protect + adminOnly middleware
β β βββ errorHandler.js # Global error handler
β β βββ validate.js # express-validator rules
β βββ models/
β β βββ User.js # User schema (role, status, bcrypt)
β β βββ Task.js # Task schema
β β βββ ActivityLog.js # Activity tracking schema
β βββ routes/
β β βββ authRoutes.js # /api/auth/*
β β βββ taskRoutes.js # /api/tasks/*
β β βββ adminRoutes.js # /api/admin/*
β βββ services/
β β βββ activityService.js # Reusable logActivity()
β βββ utils/
β β βββ response.js # sendSuccess / sendError helpers
β β βββ seeder.js # Seeds admin user
β βββ .env.example
β βββ package.json
β βββ server.js # Express app entry point
β
βββ frontend/
βββ public/
β βββ index.html
βββ src/
βββ components/
β βββ common/
β βββ Layout.js # Sidebar + content wrapper
β βββ Modal.js # Reusable modal dialog
β βββ ProtectedRoute.js # Route guard component
β βββ Sidebar.js # Navigation with role-based links
βββ context/
β βββ AuthContext.js # Global auth state (useAuth hook)
βββ pages/
β βββ auth/
β β βββ LoginPage.js
β β βββ RegisterPage.js
β βββ user/
β β βββ DashboardPage.js # Stats + recent tasks
β β βββ TasksPage.js # Full CRUD tasks
β βββ admin/
β βββ AdminDashboard.js # Analytics + charts
β βββ UserManagementPage.js
β βββ TaskMonitorPage.js
β βββ ActivityLogsPage.js
βββ services/
β βββ api.js # Axios instance + all API calls
βββ App.js # Router + routes
βββ index.css # Design system styles
βββ index.js
- Node.js v16+
- MongoDB (local or Atlas)
- Git
git clone https://github.com/YOUR_USERNAME/task-manager.git
cd task-managercd backend
# Install dependencies
npm install
# Create environment file
cp .env.example .envEdit .env with your values:
PORT=5000
NODE_ENV=development
MONGODB_URI=mongodb://localhost:27017/task_manager
JWT_SECRET=your_super_secret_key_here
JWT_EXPIRE=7d
# Admin seed credentials
ADMIN_NAME=Super Admin
ADMIN_EMAIL=admin@taskmanager.com
ADMIN_PASSWORD=Admin@123456# Seed the admin user
npm run seed
# Start development server
npm run devBackend runs at: http://localhost:5000
cd ../frontend
# Install dependencies
npm install
# Start React app
npm startFrontend runs at: http://localhost:3000
The React app proxies
/apirequests tohttp://localhost:5000automatically (via"proxy"inpackage.json).
| Role | Password | |
|---|---|---|
| Admin | admin@taskmanager.com | Admin@123456 |
Register new accounts through the
/registerpage (all new accounts default to "User" role).
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /register |
β | Register new user |
| POST | /login |
β | Login and get JWT |
| GET | /me |
β | Get current user info |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | / |
β | Get own tasks (filterable) |
| POST | / |
β | Create new task |
| GET | /:id |
β | Get one task |
| PUT | /:id |
β | Update own task |
| DELETE | /:id |
β | Delete own task |
Query Params for GET /tasks: ?status=pending&priority=high&search=keyword
| Method | Endpoint | Description |
|---|---|---|
| GET | /analytics |
Dashboard analytics |
| GET | /users |
All users (filterable) |
| PUT | /users/:id/status |
Activate/deactivate user |
| DELETE | /users/:id |
Delete user + their tasks |
| GET | /tasks |
All tasks (filterable) |
| DELETE | /tasks/:id |
Delete any task |
| GET | /activity-logs |
Full activity log |
curl -X POST http://localhost:5000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"name":"Jane Doe","email":"jane@example.com","password":"pass1234"}'curl -X POST http://localhost:5000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"admin@taskmanager.com","password":"Admin@123456"}'curl -X POST http://localhost:5000/api/tasks \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{"title":"My first task","priority":"high","status":"pending"}'curl http://localhost:5000/api/tasks \
-H "Authorization: Bearer YOUR_TOKEN_HERE"curl http://localhost:5000/api/admin/users \
-H "Authorization: Bearer ADMIN_TOKEN_HERE"curl http://localhost:5000/api/admin/analytics \
-H "Authorization: Bearer ADMIN_TOKEN_HERE"Request β protect middleware β adminOnly middleware (admin routes)
β
Verify JWT token
β
Find user in DB
β
Check user status (active/inactive)
β
Attach req.user β route handler
| Field | Type | Details |
|---|---|---|
| name | String | required, max 50 chars |
| String | unique, lowercase | |
| password | String | hashed with bcrypt (select:false) |
| role | Enum | "user" | "admin" |
| status | Enum | "active" | "inactive" |
| lastLogin | Date | updated on login |
| Field | Type | Details |
|---|---|---|
| title | String | required, max 100 chars |
| description | String | optional, max 500 chars |
| status | Enum | pending / in-progress / completed |
| priority | Enum | low / medium / high |
| dueDate | Date | optional |
| user | ObjectId | ref to User |
| Field | Type | Details |
|---|---|---|
| user | ObjectId | ref to User |
| action | Enum | LOGIN, TASK_CREATED, etc. |
| description | String | Human-readable summary |
| resourceId | ObjectId | Affected resource (optional) |
| resourceType | Enum | "Task" | "User" | null |
| ipAddress | String | Client IP for audit |
# 1. Create and switch to new branch
git checkout -b feature/role-based-access
# 2. Add all files
git add .
# 3. Commit with clear message
git commit -m "feat: implement role-based task management with admin dashboard"
# 4. Push to GitHub
git push origin feature/role-based-access
# 5. Open Pull Request on GitHub
# β Compare: feature/role-based-access β main
# β Add description, screenshots
# β Request review- JWT Authentication (Register/Login)
- Role-based access (Admin/User)
- User schema with status (Active/Inactive)
- Protected routes (backend middleware)
- Admin: View/Delete/Update users
- Admin: View/Delete all tasks
- User: CRUD own tasks only
- Activity Log System (login, task events)
- React protected routes (ProtectedRoute)
- Admin sidebar (admin links hidden from users)
- Analytics dashboard (counts, charts)
- Responsive design
- Global error handling
- Input validation
- Password hashing (bcrypt)
- Environment variables
- Reusable components (Modal, Layout, Sidebar)
- Toast notifications
# Frontend
cd frontend && npm run build
# Backend (set NODE_ENV=production in .env)
cd backend && npm startMongoDB connection error:
- Make sure MongoDB is running:
mongodor check MongoDB Atlas URI
Port already in use:
- Change
PORTin.envor kill the process using the port
JWT errors:
- Ensure
JWT_SECRETis the same across restarts - Check token expiry (
JWT_EXPIRE=7d)
CORS errors:
- Backend allows
http://localhost:3000by default - Update the
corsconfig inserver.jsfor production URLs