Skip to content

priyanshur0410/task-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

⚑ TaskFlow β€” Role-Based Task Management System

A full-stack web application with JWT authentication, role-based access control (Admin/User), and a real-time activity tracking system.


🧱 Tech Stack

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

πŸ“ Project Structure

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

πŸš€ Quick Start

Prerequisites

  • Node.js v16+
  • MongoDB (local or Atlas)
  • Git

1. Clone the Repository

git clone https://github.com/YOUR_USERNAME/task-manager.git
cd task-manager

2. Backend Setup

cd backend

# Install dependencies
npm install

# Create environment file
cp .env.example .env

Edit .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 dev

Backend runs at: http://localhost:5000


3. Frontend Setup

cd ../frontend

# Install dependencies
npm install

# Start React app
npm start

Frontend runs at: http://localhost:3000

The React app proxies /api requests to http://localhost:5000 automatically (via "proxy" in package.json).


πŸ” Default Login Credentials

Role Email Password
Admin admin@taskmanager.com Admin@123456

Register new accounts through the /register page (all new accounts default to "User" role).


πŸ“‘ API Reference

Auth Routes β€” /api/auth

Method Endpoint Auth Description
POST /register ❌ Register new user
POST /login ❌ Login and get JWT
GET /me βœ… Get current user info

Task Routes β€” /api/tasks

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

Admin Routes β€” /api/admin (Admin only)

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

πŸ§ͺ Sample API Tests (with curl)

Register

curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"name":"Jane Doe","email":"jane@example.com","password":"pass1234"}'

Login

curl -X POST http://localhost:5000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"admin@taskmanager.com","password":"Admin@123456"}'

Create Task (with token)

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"}'

Get All Tasks

curl http://localhost:5000/api/tasks \
  -H "Authorization: Bearer YOUR_TOKEN_HERE"

Admin: Get All Users

curl http://localhost:5000/api/admin/users \
  -H "Authorization: Bearer ADMIN_TOKEN_HERE"

Admin: Analytics

curl http://localhost:5000/api/admin/analytics \
  -H "Authorization: Bearer ADMIN_TOKEN_HERE"

πŸ”’ Authorization Flow

Request β†’ protect middleware β†’ adminOnly middleware (admin routes)
            ↓
     Verify JWT token
            ↓
     Find user in DB
            ↓
     Check user status (active/inactive)
            ↓
     Attach req.user β†’ route handler

πŸ—„οΈ MongoDB Schemas

User

Field Type Details
name String required, max 50 chars
email String unique, lowercase
password String hashed with bcrypt (select:false)
role Enum "user" | "admin"
status Enum "active" | "inactive"
lastLogin Date updated on login

Task

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

ActivityLog

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

βš™οΈ Git Workflow (Assignment Requirements)

# 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

βœ… Features Checklist

  • 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

πŸ“¦ Build for Production

# Frontend
cd frontend && npm run build

# Backend (set NODE_ENV=production in .env)
cd backend && npm start

πŸ› οΈ Troubleshooting

MongoDB connection error:

  • Make sure MongoDB is running: mongod or check MongoDB Atlas URI

Port already in use:

  • Change PORT in .env or kill the process using the port

JWT errors:

  • Ensure JWT_SECRET is the same across restarts
  • Check token expiry (JWT_EXPIRE=7d)

CORS errors:

  • Backend allows http://localhost:3000 by default
  • Update the cors config in server.js for production URLs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors