Skip to content

About

🏨 Hostel complaint management system with role-based access for students, wardens and maintenance staff. Report issues, assign the right technician, track every repair from submission to closure, and keep a full history of who did what and when.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

HostelDesk - Hostel Complaint Management System

A full-stack web app where students report hostel issues, wardens manage rooms and assign work, and technicians update the progress of their jobs. Every complaint has an owner, a status and a full history.


React Vite TypeScript Tailwind CSS Framer Motion Recharts

Node.js Express MongoDB Atlas Mongoose

Features Β· Tech Stack Β· Architecture Β· Quick Start Β· API Β· Troubleshooting

πŸ“– Overview

HostelDesk replaces paper registers and WhatsApp messages with a single, accountable workflow for hostel maintenance.

  • πŸŽ“ Students raise a complaint for their room or a shared area and follow it until it is fixed.
  • πŸ§‘β€πŸ’Ό Wardens manage rooms and beds, allocate and transfer students, set priorities and assign the right technician.
  • πŸ”§ Technicians see only the jobs assigned to them, start work, add repair notes and mark jobs resolved.

Every status change is recorded with who did it, in which role and when, so nothing gets lost or disputed.

✨ Features

Feature Details
πŸ” Role-based access Student, Warden and Maintenance roles. Every rule is enforced by the API (role checks plus record ownership), not just hidden in the UI.
πŸ“ Smart complaint forms Category-specific details (for example Wi-Fi network name), stored in a flexible details field.
🎯 Specialty-aware assignment The matching technician (plumbing, electrical, carpentry, IT) is preselected. If none exists, the warden is told which specialty is missing.
πŸ” Reopen flow Students can reopen a resolved complaint with a reason, which sends it back to the warden's Needs assignment tab.
πŸ•“ Full audit history statusHistory records actor, role, timestamp and optional note for every change.
πŸ›οΈ Rooms and beds Allocate, transfer and check out students. Old complaints keep the room they were reported from.
πŸ“Š Analytics Aggregation reports for recurring problems, resolution times and occupancy, shown with Recharts.
⚑ Concurrency safe Optimistic concurrency stops two people overwriting the same complaint.
πŸ”„ Transactional transfers Room transfers run in a MongoDB transaction, so a failure never leaves a student without a bed.
🎨 Polished UI Tailwind CSS with Framer Motion animations and one-click demo logins.

🧰 Tech Stack

Layer Technology Purpose
Frontend React 18, Vite, TypeScript Fast, type-safe single-page app
Styling and motion Tailwind CSS, Framer Motion Responsive design and smooth transitions
Charts Recharts Reports and dashboard visuals
Backend API Node.js, Express 4 REST API, middleware, static hosting in production
Database MongoDB Atlas, Mongoose 8 Documents, indexes, aggregations, transactions
Auth express-session, connect-mongo, bcrypt Cookie sessions stored in MongoDB with hashed passwords

πŸ—οΈ Architecture

flowchart LR
    subgraph Client["πŸ–₯️ Client - React + Vite"]
        UI["Pages<br/>student / warden / maintenance"]
        CTX["Auth and Toast context"]
        API_C["API client"]
        UI --> CTX --> API_C
    end

    subgraph Server["βš™οΈ Server - Express"]
        MW["Middleware<br/>sessions, requireAuth, requireRole"]
        RT["Routes<br/>auth, users, rooms, allocations,<br/>complaints, reports"]
        SV["Services<br/>complaint status workflow"]
        MD["Mongoose models"]
        MW --> RT --> SV --> MD
    end

    subgraph DB["πŸƒ MongoDB Atlas"]
        C1[("users")]
        C2[("rooms")]
        C3[("allocations")]
        C4[("complaints")]
        C5[("sessions")]
    end

    API_C -- "HTTP /api (cookie session)" --> MW
    MD --> C1 & C2 & C3 & C4
    MW -. "connect-mongo" .-> C5
Loading

Complaint lifecycle

Complaint lifecycle: Submitted, Assigned, In progress, Resolved, Closed
stateDiagram-v2
    [*] --> Submitted: Student reports issue
    Submitted --> Assigned: Warden assigns technician
    Assigned --> InProgress: Technician starts work
    InProgress --> Resolved: Technician marks resolved
    Resolved --> Closed: Student confirms or warden verifies
    Resolved --> Reopened: Student reopens with reason
    Reopened --> Assigned: Warden reassigns
    Closed --> [*]
Loading

Who talks to whom

sequenceDiagram
    autonumber
    actor S as Student
    actor W as Warden
    actor T as Technician
    participant API as Express API
    participant DB as MongoDB

    S->>API: POST /complaints
    API->>DB: Insert complaint (Submitted)
    W->>API: PATCH /complaints/:id/assign
    API->>DB: Set assignedTo, status Assigned
    T->>API: PATCH /complaints/:id/start
    API->>DB: Status In progress
    T->>API: PATCH /complaints/:id/resolve
    API->>DB: Status Resolved, resolvedAt
    alt Student is satisfied
        S->>API: PATCH /complaints/:id/confirm
        API->>DB: Status Closed
    else Problem persists
        S->>API: PATCH /complaints/:id/reopen (reason)
        API->>DB: Status Reopened
    end
Loading

Data model

erDiagram
    USERS ||--o{ COMPLAINTS : "reports"
    USERS ||--o{ COMPLAINTS : "assigned to"
    USERS ||--o{ ALLOCATIONS : "has"
    ROOMS ||--o{ ALLOCATIONS : "hosts"

    USERS {
        ObjectId _id
        string name
        string email UK
        string passwordHash
        string role
        string specialization
        boolean isActive
    }
    ROOMS {
        ObjectId _id
        string block
        number floor
        string roomNumber
        array beds
    }
    ALLOCATIONS {
        ObjectId studentId
        ObjectId roomId
        string bedLabel
        string status
        date startDate
        date endDate
        string endReason
    }
    COMPLAINTS {
        ObjectId studentId
        object location
        string category
        object details
        string priority
        string status
        ObjectId assignedTo
        array statusHistory
        array notes
        date createdAt
        date resolvedAt
    }
Loading

πŸ”‘ Roles and Permissions

Role Can do
πŸŽ“ Student View current room, roommates and room history. Submit complaints for their room or a shared area. Track only their own complaints. Confirm a repair or reopen with a reason.
πŸ§‘β€πŸ’Ό Warden Manage rooms and beds. Allocate, transfer and check out students. Review all complaints, set priorities, assign or reassign technicians, close verified complaints, manage staff accounts and view reports.
πŸ”§ Maintenance See only jobs assigned to them. Start work, add repair notes and mark resolved.

πŸš€ Quick Start

1. Prerequisites

  • Node.js 18.18 or newer (Node 20 LTS recommended). Check with node -v
  • A free MongoDB Atlas account

2. Clone the repository

git clone https://github.com/LoganthP/HostelDesk.git
cd HostelDesk

3. Set up MongoDB Atlas (about 5 minutes)

  1. Create a free M0 cluster at cloud.mongodb.com.

  2. Database Access β†’ Add New Database User β†’ choose a user name and password. Avoid @ : / ? in the password, or URL-encode them.

  3. Network Access β†’ Add IP Address β†’ Add Current IP Address (or 0.0.0.0/0 while testing).

  4. Connect β†’ Drivers β†’ copy the connection string:

    mongodb+srv://<user>:<password>@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority
    

The app creates the database (hostel_cms), collections and indexes by itself.

4. Configure the backend

cd server
cp .env.example .env        # Windows (PowerShell): copy .env.example .env

Generate a random session secret. Run this command and copy the 96-character output:

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

Edit server/.env and paste the generated value as SESSION_SECRET:

MONGODB_URI=mongodb+srv://<user>:<password>@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority
DB_NAME=hostel_cms
SESSION_SECRET=<paste-the-generated-secret-here>
PORT=5000
NODE_ENV=development
COOKIE_SECURE=false

πŸ”’ Never commit your .env file or share the secret. Use a different secret for every deployment.

5. Install, seed and run

From the project root:

npm run install:all     # installs root, server and client packages
npm run seed            # loads demo rooms, users and complaints (resets the database!)
npm run dev             # starts API on :5000 and React on :5173 together

Open http://localhost:5173 πŸŽ‰

Prefer two terminals? Run npm run dev inside server/ and npm run dev inside client/.

Available scripts

Command What it does
npm run install:all Installs root, server and client dependencies
npm run seed Resets and fills the database with demo data
npm run dev Runs API (:5000) and React (:5173) together
npm run build Builds the client into client/dist
npm start Starts the production server
npm run test:api --prefix server Runs the 34-check API smoke test

πŸ‘€ Demo Accounts

Password for all accounts: HostelDesk#Demo26

The password is deliberately unusual. Common passwords like password123 make Chrome show a "password found in a data breach" warning in the middle of a demo.

Role Email
πŸ§‘β€πŸ’Ό Warden [email protected]
πŸ”§ Maintenance (plumbing) [email protected]
πŸ”§ Maintenance (electrical) [email protected]
πŸ”§ Maintenance (carpentry) [email protected]
πŸ”§ Maintenance (IT support / Wi-Fi) [email protected]
πŸŽ“ Student in Room A101 [email protected]
πŸŽ“ Student in Room A101 (has a resolved repair to confirm) [email protected]
πŸŽ“ Student in Room B101 [email protected]
πŸŽ“ Student without a room [email protected]

The login page has one-click demo buttons for Student, Warden, Plumber, Electrician, IT support and Carpenter. The plumber starts with an active job (Shower drain is clogged) waiting to be started, and the pest-control complaint shows what happens when no specialist exists.

🏭 Production Build (single origin)

npm run build                      # builds client/dist
cd server && npm start             # Express serves the API and the React app on :5000

Open http://localhost:5000.

If you deploy behind HTTPS, set NODE_ENV=production and COOKIE_SECURE=true.

πŸ”„ Complaint Workflow Rules

  • Submitted β†’ Assigned β†’ In progress β†’ Resolved β†’ Closed
  • Reopen (student, from Resolved, reason required) β†’ Reopened β†’ warden reassigns β†’ Assigned.
  • Close happens when the student confirms, or the warden verifies.
  • Every change is recorded in statusHistory with who, which role, when and an optional note.
  • Documents use optimistic concurrency, so two people editing the same complaint at once get a clear "refresh and try again" message instead of overwriting each other.

πŸ—„οΈ Database Design

Collection Key fields Notes
users name, email (unique), passwordHash, role, specialization, isActive One collection for all three roles.
rooms block, floor, roomNumber, beds[{label}] Beds embedded; unique (block, roomNumber).
allocations studentId, roomId, bedLabel, status, startDate, endDate, endReason Full history kept. Partial unique indexes: one active allocation per student, one per (roomId, bedLabel).
complaints studentId, location (snapshot), category, details, priority, status, assignedTo, statusHistory[], notes[], createdAt, resolvedAt Location is stored as reported, so it stays correct after the student moves.
sessions managed by connect-mongo Login sessions, expire after 7 days.

Transfers run inside a MongoDB transaction (Atlas clusters support this), so a failed move leaves the student's original allocation intact. On a local standalone MongoDB without transactions, the API falls back to a compensating rollback.

πŸ“Š Aggregation reports (/api/reports/...)

Endpoint What it shows
by-category-block Complaints grouped by hostel block and category (recurring problems)
resolution-time Average, fastest and slowest hours from createdAt to resolvedAt, per category
occupancy Bed counts per block compared with active allocations ($lookup into allocations)
summary Dashboard counters

πŸ“‘ API Reference

All routes live under /api. Responses are JSON; errors look like { "message": "..." }.

Method Route Who
POST /auth/register Β· /auth/login Β· /auth/logout public
GET /auth/me signed in
GET POST PATCH /users Β· /users/technicians Β· /users/:id warden
GET /rooms/blocks signed in
GET POST PATCH DELETE /rooms Β· /rooms/available-beds Β· /rooms/:id warden
GET /allocations/me student
GET POST /allocations Β· /allocations/student/:id Β· /allocations/transfer Β· /allocations/checkout warden
GET /complaints (filters: status, category, priority, block, q, assignedTo) Β· /complaints/:id role-scoped
POST /complaints student
PATCH /complaints/:id/assign Β· /complaints/:id/close warden
PATCH /complaints/:id/start Β· /complaints/:id/resolve assigned technician
POST /complaints/:id/notes warden or assigned technician
PATCH /complaints/:id/confirm Β· /complaints/:id/reopen owning student
GET /reports/summary Β· /reports/by-category-block Β· /reports/resolution-time Β· /reports/occupancy warden
GET /health public

πŸ“ Project Structure

hostel-complaint-management-system/
β”œβ”€β”€ package.json              # root scripts: install:all, dev, seed, build, start
β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ .env.example
β”‚   └── src/
β”‚       β”œβ”€β”€ server.js         # connects to Atlas, builds indexes, starts Express
β”‚       β”œβ”€β”€ app.js            # middleware, sessions, routes, serves client/dist
β”‚       β”œβ”€β”€ seed.js           # demo data
β”‚       β”œβ”€β”€ config/           # env loading + DB connection
β”‚       β”œβ”€β”€ models/           # User, Room, Allocation, Complaint (Mongoose)
β”‚       β”œβ”€β”€ routes/           # auth, users, rooms, allocations, complaints, reports
β”‚       β”œβ”€β”€ services/         # complaint status workflow
β”‚       β”œβ”€β”€ middleware/       # requireAuth / requireRole, error handler
β”‚       └── utils/            # HTTP helpers, transaction helper
└── client/
    β”œβ”€β”€ vite.config.ts        # proxies /api β†’ http://localhost:5000
    └── src/
        β”œβ”€β”€ lib/              # API client, types, constants, formatters
        β”œβ”€β”€ context/          # auth + toast providers
        β”œβ”€β”€ components/       # layout, UI kit, modals, timeline
        └── pages/            # student/, warden/, maintenance/ + shared pages

πŸ§ͺ Testing

  • API smoke test (34 checks): with the API running on a freshly seeded database, run:

    npm run test:api --prefix server
  • Full manual QA: docs/QA_PROMPT.md is a ready-made prompt and checklist covering every button and the client–server connection.

  • How MongoDB is used, with file references: docs/MONGODB.md.

Quick behaviour checklist

  • Duplicate bed allocation: allocate two students to the same bed β†’ second request gets 409 That bed is already occupied.
  • Unauthorized complaint access: open another student's complaint URL β†’ 403. A technician opening a job not assigned to them β†’ 403.
  • Reopening: resolve a complaint, reopen it as the student β†’ it returns to the warden's Needs assignment tab and the reopen reason appears in the history.

πŸ’‘ You can inspect the collections in MongoDB Compass with the same connection string.

πŸ› οΈ Troubleshooting

Problem Fix
Could not connect to MongoDB / timeout Add your IP in Atlas β†’ Network Access. Check user name and password. URL-encode special characters (@ β†’ %40).
Missing environment variable(s) Create server/.env from .env.example.
Frontend shows "Can't reach the server" Make sure the API is running on port 5000 (npm run dev from the root starts both).
Port 5000 is already in use Change PORT in server/.env and the proxy target in client/vite.config.ts. On macOS, AirPlay Receiver uses port 5000, so turn it off or use 5050.
Logged out after every refresh in production over plain HTTP Keep COOKIE_SECURE=false unless you serve over HTTPS.
Want to start over npm run seed resets all data.

About

🏨 Hostel complaint management system with role-based access for students, wardens and maintenance staff. Report issues, assign the right technician, track every repair from submission to closure, and keep a full history of who did what and when.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages