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.
Features Β· Tech Stack Β· Architecture Β· Quick Start Β· API Β· Troubleshooting
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.
| 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. |
| 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 |
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
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 --> [*]
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
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
}
| 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. |
- Node.js 18.18 or newer (Node 20 LTS recommended). Check with
node -v - A free MongoDB Atlas account
git clone https://github.com/LoganthP/HostelDesk.git
cd HostelDesk-
Create a free M0 cluster at cloud.mongodb.com.
-
Database Access β Add New Database User β choose a user name and password. Avoid
@ : / ?in the password, or URL-encode them. -
Network Access β Add IP Address β Add Current IP Address (or
0.0.0.0/0while testing). -
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.
cd server
cp .env.example .env # Windows (PowerShell): copy .env.example .envGenerate 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
.envfile or share the secret. Use a different secret for every deployment.
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 togetherOpen http://localhost:5173 π
Prefer two terminals? Run
npm run devinsideserver/andnpm run devinsideclient/.
| 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 |
Password for all accounts: HostelDesk#Demo26
The password is deliberately unusual. Common passwords like
password123make Chrome show a "password found in a data breach" warning in the middle of a demo.
| Role | |
|---|---|
| π§βπΌ 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.
npm run build # builds client/dist
cd server && npm start # Express serves the API and the React app on :5000Open http://localhost:5000.
If you deploy behind HTTPS, set NODE_ENV=production and COOKIE_SECURE=true.
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
statusHistorywith 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.
| 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.
| 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 |
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 |
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
-
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.mdis a ready-made prompt and checklist covering every button and the clientβserver connection. -
How MongoDB is used, with file references:
docs/MONGODB.md.
- 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.
| 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. |