How np03cy4s250015-nivss/hostel-management-system works
1. This repository is a two-tier hostel management system: a static browser frontend and a Node.js/Express backend API backed by MySQL. The root index.html is the login entry point, while the actual app views live under frontend/.
2. The frontend is not a framework app; it is plain HTML/CSS/JavaScript. frontend/js/script.js provides shared utilities, and dashboard_admin.js / dashboard_user.js drive the two role-specific dashboards by calling backend endpoints and updating the DOM.
3. The backend is the system boundary for all business rules. backend/server.js wires the Express app, CORS, and CSRF-style request checks, then mounts route modules under /api/auth, /api/data, and /api/payment. All persistent state lives in MySQL, not in the browser.
4. Authentication is JWT-based, with backend/middleware/auth.js enforcing bearer-token access, role checks, and token revocation via an in-memory blacklist on logout. This makes the backend the source of truth for session validity even though the frontend stores the token.
5. The data layer is centralized in backend/config/database.js, which exposes a promise-based MySQL connection pool. The schema in backend/database.sql models the main domain objects: users, students, rooms, notices, complaints, payments, settings requests, and per-user UI preferences.
6. The core operational workflow is student/room management. Admin actions create and update users and student profiles, assign rooms, and maintain room occupancy. Room status is derived from capacity versus current occupancy, so student add/delete/transfer operations ripple into room state updates.
7. The system has two primary user journeys. Admins manage students, rooms, complaints, notices, payment records, and approval workflows; students view their profile, submit complaints, read notices, request setting changes, and pay fees. The same /api/data routes serve both roles, but access is filtered by the auth middleware and user role.
8. Payment handling is isolated in backend/routes/payment.js. It integrates with eSewa, supports initiate/verify flows, and also has success/failure callback endpoints that do not require auth because they are called by the payment provider redirect flow. Admin-only simulation and manual completion endpoints exist for operational testing and reconciliation.
9. Profile images are a separate storage boundary. Uploaded student images are written to backend/users/ and served statically, while the database stores the image URL/path. Replacement and deletion are handled server-side so image lifecycle stays consistent with student records.
10. Preferences and approvals are another distinct subsystem. Theme/view preferences are persisted per user, and sensitive account changes are not applied immediately; they go through settings_change_requests where admins can approve or reject them. That creates an explicit review queue in the data model and UI.
11. Notifications are generated from database state rather than a push service. The frontend polls roughly every 5 seconds for updates to complaints, notices, and payments, which means the architecture is request/response plus polling, not WebSockets or server push.
12. Security and validation are embedded across boundaries: bcrypt for passwords, rate-limited login, parameterized SQL queries, content-type checks for state-changing requests, upload size/type restrictions, and frontend HTML escaping to reduce XSS risk. These controls sit at the API and file-upload boundaries, not in the static frontend alone.
13. The key external dependency is MySQL; the only other integration with architectural impact is eSewa for payments. Everything else—authentication, role enforcement, room allocation, notifications, and preference persistence—is implemented within the app’s own backend and database.
Main entry points: index.js API Router · auth.js Auth Routes · data.js Data Routes · payment.js Payment API
Components 19
Frontend
Static browser app and role dashboards
- Login · Root browser entry point
index.html - Admin UI · Administrative workstation
frontend/dashboard_admin.html - User UI · Student-facing workspace
frontend/dashboard_user.html - Reset Flow · Password recovery and OTP entry
frontend/forgot_password.html - OTP Page · One-time code verification view
frontend/otp_verification.html - Shared JS · Common DOM, fetch, and escaping helpers
frontend/js/script.js - Admin Logic · Admin dashboard data and actions
frontend/js/dashboard_admin.js - User Logic · Student dashboard data and actions
frontend/js/dashboard_user.js
Backend
Express API, auth, and business logic
- Server · Express app bootstrap and middleware wiring
backend/server.js - API Router · Central route aggregation
backend/routes/index.js - Auth Routes · Login, token, and account auth endpoints
backend/routes/auth.js - Data Routes · Role-filtered hostel management endpoints
backend/routes/data.js - Payment API · eSewa initiate, verify, and callbacks
backend/routes/payment.js - Auth Guard · Bearer auth, role checks, blacklist enforcement
backend/middleware/auth.js - MySQL Pool · Promise-based database access layer
backend/config/database.js - OTP Service · One-time password generation and delivery
backend/services/otpService.js
Data
MySQL schema and persistent state
- Schema · Users, rooms, students, notices, complaints, payments, settings
backend/database.sql
Integrations
External payment and runtime services
- User Images · Uploaded student image files
backend/users/.gitkeep - eSewa · External payment gateway
backend/esewa-sandbox-credentials.txt
Connections 21
- Login → Shared JS: loads · Entry page reuses shared browser utilities
- Admin UI → Admin Logic: driven by · Admin UI is controlled by dashboard logic
- User UI → User Logic: driven by · Student UI is controlled by dashboard logic
- Admin Logic → Shared JS: uses · Shared helpers for DOM, fetch, and escaping
- User Logic → Shared JS: uses · Shared helpers for DOM, fetch, and escaping
- Reset Flow → OTP Page: flows to · Password recovery progresses through OTP verification
- Shared JS → Server: calls · Frontend requests backend APIs over HTTP
- Server → API Router: mounts · Server composes the API router tree
- API Router → Auth Routes: exposes · Authentication endpoints
- API Router → Data Routes: exposes · Core hostel management endpoints
- API Router → Payment API: exposes · Payment endpoints and callbacks
- Auth Routes → Auth Guard: protected by · Authenticated flows enforce JWT and roles
- Data Routes → Auth Guard: protected by · Role-gated business endpoints
- Payment API → Auth Guard: partly protected by · Some payment operations require auth, callbacks do not
- Auth Routes → MySQL Pool: reads/writes · User credentials and session-related state
- Data Routes → MySQL Pool: reads/writes · Hostel domain state and workflows
- Payment API → MySQL Pool: reads/writes · Payment records and reconciliation data
- MySQL Pool → Schema: implements · Connection pool persists schema-defined entities
- Data Routes → User Images: stores files · Student image upload lifecycle
- Payment API → eSewa: integrates with · Payment initiation and verification
- Auth Routes → OTP Service: uses · Password reset and verification codes