Skip to content

MOHAMED-MUHNI/service-request-management-system

Repository files navigation

🚚 Service Request Management System

A complete, production-ready full-stack application for managing service requests with real-time analytics, assignment scheduling, and comprehensive admin dashboard.

πŸ“‹ Internship Test Project - Built as an assessment for Octick Pvt Ltd. All requirements completed with production deployment.

Node.js React MySQL Docker Deploy License


🎯 Assignment Completion Status

This project was built as an internship technical assessment. All requirements completed successfully.

βœ… Core Requirements (100%)

  • βœ… Customer trip request submission form
  • βœ… Coordinator admin panel with authentication
  • βœ… Status management (pending β†’ approved/rejected/scheduled)
  • βœ… Driver & vehicle assignment with scheduling
  • βœ… Search requests by customer name or phone
  • βœ… Daily analytics (request count for last 7 days)

βœ… Technical Requirements (100%)

  • βœ… REST API with CRUD operations (Create, Read, Update, Delete)
  • βœ… Input validation with clear error messages
  • βœ… Correct HTTP status codes (200, 201, 400, 404, 500)
  • βœ… Pagination on admin list endpoint
  • βœ… /api/analytics/dashboard endpoint for statistics
  • βœ… Seed data (7 drivers, 7 vehicles)
  • βœ… Consistent JSON error shape with message and errors fields

βœ… Frontend Requirements (100%)

  • βœ… Responsive customer form with client-side validation
  • βœ… Friendly error messages & success states
  • βœ… Admin authentication system
  • βœ… Requests table with status filter & inline actions
  • βœ… Analytics chart (bar chart for daily requests)
  • βœ… Modal for scheduling with driver/vehicle dropdowns
  • βœ… Loading states throughout application
  • βœ… Clean, readable components

βœ… Quality Gates (100%)

  • βœ… Clear commit history (50+ commits with descriptive messages)
  • βœ… Unit tests (backend/src/tests/unit.test.js)
  • βœ… API tests (backend/src/tests/api.test.js)
  • βœ… Logging middleware (method, path, status, duration)
  • βœ… .env.example files with safe defaults
  • βœ… npm scripts for easy setup (npm run dev, npm start)
  • βœ… Comprehensive documentation

🌟 Stretch Goals Completed (2/4)

  • βœ… Production Deployment - Live demo on Render.com
  • βœ… Docker Compose - Full containerization setup
  • ❌ Role-based access control (coordinator/viewer)
  • ❌ Live updates via WebSockets/SSE

⏱️ Development Timeline

  • Time Spent: ~12 hours over 5 days
  • Commit Count: 50+ commits
  • Lines of Code: Backend (~2,500), Frontend (~1,800)

πŸ“‹ Table of Contents

πŸ“š Documentation

🎯 Lost in too many docs?
πŸ‘‰ Start here: docs/WHICH_FILE_TO_READ.md - Quick guide to find what you need!

Essential Docs:

πŸ“ View all documentation β†’


🌐 Live Demo

πŸš€ Live Application Deployed!

Access the demo at:

Demo Credentials:

Username: admin
Password: admin123

⚠️ Note: Free tier services may take 30-60 seconds to wake up after inactivity.

πŸ“– Full Documentation: See docs/ folder for detailed guides.


✨ Features

Customer Portal

  • βœ… Submit service requests with validation
  • βœ… Multiple service types (Package Delivery, Furniture Moving, etc.)
  • βœ… Real-time form validation
  • βœ… Success notifications

Admin Dashboard

  • βœ… Secure JWT authentication
  • βœ… Real-time analytics & statistics
  • βœ… 7-day service requests chart
  • βœ… Service request management (CRUD)
  • βœ… Advanced filtering and search
  • βœ… Pagination support
  • βœ… Assignment scheduling
  • βœ… Status tracking workflow
  • βœ… Driver and vehicle management

Technical Features

  • βœ… RESTful API with MVC architecture
  • βœ… MySQL database with proper indexing
  • βœ… JWT authentication & authorization
  • βœ… Request/Response logging
  • βœ… Error handling middleware
  • βœ… Unit and API tests
  • βœ… Docker containerization
  • βœ… Responsive design
  • βœ… Production-ready configuration

πŸ›  Tech Stack

Backend

  • Node.js (v18+) - Runtime environment
  • Express.js (v4.18) - Web framework
  • MySQL (v8.0) - Database
  • JWT - Authentication
  • Bcrypt - Password hashing
  • Winston - Logging
  • Jest & Supertest - Testing

Frontend

  • React (v18.2) - UI library
  • React Router - Navigation
  • Axios - HTTP client
  • Recharts - Data visualization
  • CSS3 - Styling (responsive)

DevOps

  • Docker & Docker Compose - Containerization
  • Nginx - Reverse proxy
  • ESLint & Prettier - Code quality
  • Nodemon - Development

πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   React SPA     β”‚
β”‚  (Frontend)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
    HTTP/REST
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Express API   β”‚
β”‚   (Backend)     β”‚
β”‚  - Controllers  β”‚
β”‚  - Middleware   β”‚
β”‚  - Routes       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
      MySQL
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  MySQL Database β”‚
β”‚  - Users        β”‚
β”‚  - Requests     β”‚
β”‚  - Assignments  β”‚
β”‚  - Drivers      β”‚
β”‚  - Vehicles     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

MVC Pattern

Model (Database) ──> Controller (Business Logic) ──> View (React Components)
                              β”‚
                         Middleware
                     (Auth, Logging, Error)

πŸ“¦ Prerequisites

Required

  • Node.js v18 or higher
  • npm v9 or higher
  • MySQL v8.0 or higher
  • Git

Optional (for Docker deployment)

  • Docker v20+
  • Docker Compose v2+

πŸš€ Quick Start

Option 1: Docker (Recommended)

# Clone the repository
git clone <repository-url>
cd internTask

# Start all services
docker-compose up -d

# Wait 30 seconds for database initialization
# Access the application:
# - Customer Portal: http://localhost:3000
# - Admin Dashboard: http://localhost:3000/admin/login
# - Backend API: http://localhost:5000/api

Option 2: Local Development

# Clone and install
git clone <repository-url>
cd internTask
npm run install:all

# Set up environment variables
cp .env.example .env
cd backend && cp .env backend/.env
cd ../frontend && cp .env frontend/.env

# Start MySQL (ensure it's running)
# Update backend/.env with your MySQL credentials

# Run migrations and seed data
cd backend
npm run migrate
npm run seed

# Start development servers (from root)
npm run dev

# Access:
# - Frontend: http://localhost:3000
# - Backend: http://localhost:5000

πŸ“₯ Installation

Step 1: Clone Repository

git clone <repository-url>
cd internTask

Step 2: Install Dependencies

# Install all dependencies
npm run install:all

# Or install individually
npm install              # Root
cd backend && npm install
cd ../frontend && npm install

Step 3: Environment Configuration

Create .env files:

backend/.env

NODE_ENV=development
PORT=5000

DB_HOST=localhost
DB_PORT=3306
DB_USER=admin
DB_PASSWORD=admin123
DB_NAME=service_requests_db

JWT_SECRET=your_super_secret_jwt_key_change_in_production
JWT_EXPIRES_IN=24h

CORS_ORIGIN=http://localhost:3000

frontend/.env

REACT_APP_API_URL=http://localhost:5000/api

Step 4: Database Setup

# Ensure MySQL is running
# Login to MySQL and create database (optional - migration does this)
mysql -u root -p
CREATE DATABASE service_requests_db;
EXIT;

# Run migrations
cd backend
npm run migrate

# Seed sample data
npm run seed

πŸƒ Running the Application

Development Mode

# Option 1: Run both frontend and backend
npm run dev

# Option 2: Run separately
# Terminal 1 - Backend
cd backend
npm run dev

# Terminal 2 - Frontend
cd frontend
npm start

Production Mode

# Build frontend
cd frontend
npm run build

# Start backend in production
cd backend
NODE_ENV=production npm start

Using Docker

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

# Rebuild and start
docker-compose up --build -d

Using Makefile

# View all commands
make help

# Install dependencies
make install

# Run development
make dev

# Run migrations
make migrate

# Seed database
make seed

# Run tests
make test

# Docker commands
make docker-up
make docker-down

πŸ§ͺ Testing

Run All Tests

cd backend
npm test

Run Tests with Coverage

npm test -- --coverage

Run Specific Tests

# Unit tests only
npm test -- unit.test.js

# API tests only
npm test -- api.test.js

Test Results

  • Unit tests cover utility functions (password hashing, JWT)
  • API tests cover authentication and service request endpoints
  • Coverage reports generated in backend/coverage/

πŸ“š API Documentation

Base URL

http://localhost:5000/api

Authentication

Login

POST /api/auth/login
Content-Type: application/json

{
  "username": "admin",
  "password": "admin123"
}

Response: 200 OK
{
  "token": "eyJhbGc...",
  "user": {
    "id": 1,
    "username": "admin",
    "email": "[email protected]",
    "role": "admin"
  }
}

Register

POST /api/auth/register
Content-Type: application/json

{
  "username": "newuser",
  "password": "password123",
  "email": "[email protected]"
}

Service Requests

Create Request (Public)

POST /api/service-requests
Content-Type: application/json

{
  "customer_name": "John Doe",
  "customer_email": "[email protected]",
  "customer_phone": "555-1234",
  "service_type": "Package Delivery",
  "pickup_address": "123 Main St",
  "delivery_address": "456 Oak Ave",
  "preferred_date": "2024-12-01",
  "special_instructions": "Handle with care"
}

Get All Requests (Protected)

GET /api/service-requests?page=1&limit=10&status=pending&search=john
Authorization: Bearer <token>

Get Request by ID (Protected)

GET /api/service-requests/:id
Authorization: Bearer <token>

Update Request (Protected)

PUT /api/service-requests/:id
Authorization: Bearer <token>
Content-Type: application/json

{
  "status": "completed"
}

Update Status (Protected)

PATCH /api/service-requests/:id/status
Authorization: Bearer <token>
Content-Type: application/json

{
  "status": "completed"
}

Assignments

Create Assignment (Protected)

POST /api/assignments
Authorization: Bearer <token>
Content-Type: application/json

{
  "request_id": 1,
  "driver_id": 1,
  "vehicle_id": 1,
  "scheduled_date": "2024-12-01T10:00:00"
}

Get All Assignments (Protected)

GET /api/assignments?page=1&limit=10
Authorization: Bearer <token>

Analytics

Get Dashboard Stats (Protected)

GET /api/analytics/dashboard
Authorization: Bearer <token>

Response:
{
  "totalRequests": 25,
  "pendingRequests": 5,
  "completedRequests": 15,
  "activeAssignments": 3,
  "availableDrivers": 4,
  "availableVehicles": 3
}

Get Requests by Day (Protected)

GET /api/analytics/requests-by-day?days=7
Authorization: Bearer <token>

Response:
[
  { "date": "2024-11-20", "count": 3 },
  { "date": "2024-11-21", "count": 5 },
  ...
]

Status Codes

  • 200 - Success
  • 201 - Created
  • 400 - Bad Request (validation error)
  • 401 - Unauthorized (missing/invalid token)
  • 404 - Not Found
  • 500 - Internal Server Error

🚒 Deployment

Render.com Deployment (Recommended)

✨ Complete deployment guide available in RENDER_DEPLOYMENT.md

Quick overview:

  1. Set up free MySQL database (Aiven)
  2. Deploy backend to Render
  3. Deploy frontend to Render
  4. Update README with live demo links

Total Cost: $0/month (Free tier) Deployment Time: 30-45 minutes


Docker Deployment

  1. Build and Start
docker-compose up -d --build
  1. Environment Variables Update docker-compose.yml with production values

  2. Access Application

Manual Deployment

Backend (Node.js)

cd backend
npm ci --production
npm run migrate
npm run seed
NODE_ENV=production npm start

Frontend (React)

cd frontend
npm ci
npm run build
# Serve the 'build' folder with Nginx/Apache

Environment Variables (Production)

NODE_ENV=production
DB_HOST=your-db-host
JWT_SECRET=change-this-to-random-secure-string
CORS_ORIGIN=https://your-domain.com

Nginx Configuration

server {
    listen 80;
    server_name your-domain.com;

    location / {
        root /path/to/frontend/build;
        try_files $uri /index.html;
    }

    location /api {
        proxy_pass http://localhost:5000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

πŸ”§ Troubleshooting

Database Connection Issues

Problem: Can't connect to MySQL

Solution:

# Check MySQL is running
systemctl status mysql   # Linux
brew services list       # macOS

# Test connection
mysql -u admin -p

# Verify credentials in backend/.env

Port Already in Use

Problem: Port 3000 or 5000 already in use

Solution:

# Find and kill process (Linux/macOS)
lsof -ti:3000 | xargs kill -9
lsof -ti:5000 | xargs kill -9

# Windows
netstat -ano | findstr :3000
taskkill /PID <PID> /F

Docker Issues

Problem: Containers won't start

Solution:

# Clean up Docker
docker-compose down -v
docker system prune -a

# Rebuild
docker-compose build --no-cache
docker-compose up -d

Migration Errors

Problem: Migration fails

Solution:

# Drop database and retry
mysql -u admin -p
DROP DATABASE service_requests_db;
EXIT;

# Re-run migration
cd backend
npm run migrate
npm run seed

Frontend Build Errors

Problem: npm run build fails

Solution:

# Clear cache and reinstall
cd frontend
rm -rf node_modules package-lock.json
npm install
npm run build

πŸ“Š Database Schema

Tables

users

  • id (PK)
  • username (unique)
  • password_hash
  • email (unique)
  • role (admin/user)
  • created_at, updated_at

service_requests

  • id (PK)
  • customer_name
  • customer_email
  • customer_phone
  • service_type
  • pickup_address
  • delivery_address
  • preferred_date
  • special_instructions
  • status (pending/assigned/in_progress/completed/cancelled)
  • created_at, updated_at

drivers

  • id (PK)
  • name
  • phone
  • email
  • license_number (unique)
  • status (available/assigned/off_duty)
  • created_at, updated_at

vehicles

  • id (PK)
  • model
  • plate_number (unique)
  • year
  • capacity
  • status (available/in_use/maintenance)
  • created_at, updated_at

assignments

  • id (PK)
  • request_id (FK)
  • driver_id (FK)
  • vehicle_id (FK)
  • scheduled_date
  • status (scheduled/in_progress/completed/cancelled)
  • created_at, updated_at

πŸ” Default Credentials

Username: admin
Password: admin123

⚠️ Change these credentials in production!

πŸ“ License

This project is licensed under the ISC License.

πŸ‘¨β€πŸ’» Author

Developed as a demonstration of full-stack development skills.

πŸ™ Acknowledgments

  • Express.js community
  • React community
  • MySQL team
  • Docker team

Need Help? Check the Troubleshooting section or create an issue.

Happy Coding! πŸš€