Built with MERN Stack (MongoDB, Express.js, React, Node.js)
- π Overview
- β¨ Features
- π οΈ Tech Stack
- ποΈ Project Architecture
- π Quick Start
- π Detailed Setup
- π API Documentation
- π₯ User Roles & Permissions
- π§ͺ Testing
- π Deployment
- π€ Contributing
NHMS is a comprehensive digital solution for hostel management in academic institutions, specifically designed to address the inefficiencies of manual processes at NUST (National University of Science and Technology).
At NUST, complaints and requests are often registered manually, leading to:
- π Long queues and crowded service centers
- β±οΈ Extended wait times, especially during holidays
- π Paper-based processes prone to errors
- π Slow routing and response times
- ποΈ Lack of transparency in request status
NHMS streamlines hostel management through:
- π₯οΈ Self-service digital platform for request submissions
- β‘ Faster routing with automated workflows
- π± Real-time tracking of complaints and requests
- π¨βπΌ Role-based dashboards for different user types
- π Integrated room management with availability tracking
- JWT-based authentication with secure password hashing
- Role-based access control (Admin, Hostel Manager, Cleaning Staff, Hostelite)
- Protected routes with middleware validation
- Session management with token refresh
- π’ Hostel Management: Create, view, and manage hostels
- π₯ User Management: Add hostelites with room assignment
- πββοΈ Manager Assignment: Assign/remove hostel managers
- π Dashboard: Real-time statistics and occupancy rates
- ποΈ User Removal: Remove hostelites and managers
- π Request Management: Review and approve/reject requests
- π Complaint Handling: Respond to hostelite complaints
- π₯ Hostelite Oversight: View assigned hostelite information
- π Analytics: Monitor hostel performance metrics
- π§Ή Staff Coordination: Manage cleaning staff assignments
- π Request Submission: Leave requests, mess-off requests
- π§Ή Cleaning Requests: Schedule cleaning services
- π Complaint Filing: Submit complaints with tracking
- π° Billing: View monthly challans and payment status
- π Dashboard: Personal overview of requests and bills
- π Task Management: View assigned cleaning tasks
- β Status Updates: Mark tasks as completed
- π Schedule View: Daily and weekly task schedules
- π Performance Tracking: Task completion metrics
- π Automated Challan Generation: Monthly billing cycles
- π³ Payment Integration: Stripe-powered payment processing
- π Payment Tracking: Real-time payment status
- π§ Notifications: Email reminders and receipts
- Runtime: Node.js (v16+)
- Framework: Express.js with async error handling
- Database: MongoDB with Mongoose ODM
- Authentication: JSON Web Tokens (JWT) + bcryptjs
- Security: Helmet, CORS, Input validation
- Email: Nodemailer integration
- Payments: Stripe SDK
- Scheduling: Node-cron for automated tasks
- Development: Nodemon for hot reloading
- Framework: Next.js 14+ (App Router)
- Language: TypeScript for type safety
- UI Library: React 18 with React Hooks
- Styling: Tailwind CSS + Heroicons
- Forms: React Hook Form + Zod validation
- HTTP Client: Axios with interceptors
- State Management: Zustand + React Context
- Notifications: React Hot Toast
- Date Handling: date-fns
- Payments: Stripe React components
- Version Control: Git
- Package Manager: npm
- Code Quality: ESLint, TypeScript compiler
- Environment: dotenv for configuration
- API Testing: Built-in test scripts
- Development: Hot reloading for both frontend and backend
Nust_Hostel_Management_System/
βββ π backend/
β βββ π config/
β β βββ database.js # MongoDB connection setup
β βββ π controllers/
β β βββ adminController.js # Admin-specific operations
β β βββ authController.js # Authentication logic
β β βββ billingController.js # Payment and challan management
β β βββ complaintController.js # Complaint handling
β β βββ hosteliteController.js # Hostelite operations
β β βββ managerController.js # Manager-specific functions
β β βββ requestController.js # Request processing
β βββ π middleware/
β β βββ auth.js # JWT verification
β β βββ errorHandler.js # Global error handling
β βββ π models/
β β βββ User.js # Base user model
β β βββ Hostelite.js # Hostelite discriminator
β β βββ HostelManager.js # Manager discriminator
β β βββ CleaningStaff.js # Staff discriminator
β β βββ Hostel.js # Hostel information
β β βββ Request.js # Base request model
β β βββ LeaveRequest.js # Leave request type
β β βββ MessOffRequest.js # Mess-off request type
β β βββ CleaningRequest.js # Cleaning request type
β β βββ Complaint.js # Complaint model
β β βββ Challan.js # Billing model
β βββ π routes/
β β βββ authRoutes.js # Authentication endpoints
β β βββ adminRoutes.js # Admin API routes
β β βββ managerRoutes.js # Manager API routes
β β βββ hosteliteRoutes.js # Hostelite API routes
β β βββ staffRoutes.js # Cleaning staff routes
β β βββ complaintRoutes.js # Complaint management
β β βββ requestRoutes.js # Request handling
β β βββ billingRoutes.js # Billing and payments
β βββ π scripts/
β β βββ seedUsers.js # Database seeding
β β βββ seedChallans.js # Sample billing data
β β
β βββ π services/
β β βββ cronService.js # Scheduled tasks
β βββ π utils/
β β βββ tokenUtils.js # JWT utilities
β β βββ validators.js # Input validation
β βββ π tests/
β β βββ billing.test.js # Billing logic tests
β β βββ messOff.test.js # Mess-off logic tests
β βββ server.js # Application entry point
β
βββ π frontend/
β βββ π src/
β β βββ π app/
β β β βββ layout.tsx # Root layout
β β β βββ page.tsx # Landing page
β β β βββ globals.css # Global styles
β β β βββ π (auth)/ # Authentication pages
β β β β βββ login/
β β β β βββ register/
β β β βββ π (dashboard)/ # Role-based dashboards
β β β βββ admin/
β β β βββ manager/
β β β βββ hostelite/
β β β βββ staff/
β β βββ π components/
β β β βββ Navbar.tsx # Navigation component
β β β βββ ProtectedRoute.tsx # Route protection
β β β βββ billing/ # Billing components
β β βββ π context/
β β β βββ AuthContext.tsx # Global auth state
β β βββ π hooks/
β β β βββ useAuth.ts # Authentication hook
β β βββ π services/
β β β βββ api.ts # Base API configuration
β β β βββ authService.ts # Auth API calls
β β β βββ billingService.ts # Billing API calls
β β β βββ userService.ts # User management APIs
β β βββ π types/
β β β βββ index.ts # TypeScript definitions
β β βββ π utils/
β β βββ api-client.ts # HTTP client setup
β β βββ constants.ts # App constants
β βββ next.config.js # Next.js configuration
β βββ tailwind.config.js # Tailwind CSS config
β βββ tsconfig.json # TypeScript config
β βββ package.json # Dependencies
β
βββ README.md # This file
βββ package.json # Root package configuration
Ensure you have the following installed:
- Node.js (v16 or higher) - Download
- MongoDB (local installation or MongoDB Atlas) - Download
- Git for version control - Download
# Clone the repository
git clone <repository-url>
cd Nust_Hostel_Management_System
# Install dependencies for both frontend and backend
cd backend && npm install
cd ../frontend && npm install
# Set up environment variables (see detailed setup below)
# ... configure .env files ...
# Start both services
cd backend && npm run dev &
cd frontend && npm run devOpen http://localhost:3000 in your browser.
# Install MongoDB Community Edition
# Windows: Download from MongoDB website
# macOS: brew install mongodb-community
# Ubuntu: apt-get install mongodb
# Start MongoDB service
mongod --dbpath /your/data/path- Create account at MongoDB Atlas
- Create a new cluster
- Get connection string:
mongodb+srv://username:password@cluster.mongodb.net/nhms
cd backend
npm installCreate .env file in the backend directory:
# Database Configuration
MONGODB_URI=mongodb://localhost:27017/nhms
# OR for MongoDB Atlas:
# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/nhms
# Security
JWT_SECRET=your-super-secure-jwt-secret-key-here
JWT_EXPIRES_IN=7d
# Server Configuration
PORT=5000
NODE_ENV=development
# Frontend URL (for CORS)
CLIENT_URL=http://localhost:3000
# Stripe Configuration (for payments)
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key# Development mode with auto-reload
npm run dev
# Production mode
npm start
# Run tests
node tests/billing.test.js
node tests/messOff.test.jscd frontend
npm installCreate .env.local file in the frontend directory:
# API Configuration
NEXT_PUBLIC_API_URL=http://localhost:5000/api
# Stripe Configuration (for payments)
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key
# App Configuration
NEXT_PUBLIC_APP_NAME="NUST Hostel Management System"
NEXT_PUBLIC_APP_URL=http://localhost:3000# Development mode
npm run dev
# Build for production
npm run build
npm start
# Type checking
npm run type-check
# Linting
npm run lintcd backend
# Seed initial users (admin, managers, hostelites)
npm run seed:users
# Seed sample billing data
node scripts/seedChallans.jsAfter seeding, you can use these credentials:
Admin:
Email: admin@nust.edu.pk
Password: admin123
Manager:
Email: manager@nust.edu.pk
Password: manager123
Hostelite:
Email: hostelite@nust.edu.pk
Password: hostelite123
http://localhost:5000/api
Register a new user
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@nust.edu.pk",
"password": "securePassword",
"phoneNumber": "+92-300-1234567",
"role": "HOSTELITE"
}User login
{
"email": "john.doe@nust.edu.pk",
"password": "securePassword"
}| Method | Endpoint | Description |
|---|---|---|
| GET | /admin/hostels |
Get all hostels |
| POST | /admin/hostels |
Create new hostel |
| GET | /admin/users |
Get all users |
| POST | /admin/hostelites |
Create hostelite |
| POST | /admin/managers |
Create/assign manager |
| DELETE | /admin/hostelites/:id |
Remove hostelite |
| DELETE | /admin/managers/:id |
Remove manager |
| GET | /admin/available-rooms/:hostelId |
Get available rooms |
| Method | Endpoint | Description |
|---|---|---|
| GET | /manager/requests |
Get hostelite requests |
| PUT | /manager/requests/:id |
Update request status |
| GET | /manager/complaints |
Get complaints |
| PUT | /manager/complaints/:id |
Respond to complaint |
| GET | /manager/hostelites |
Get assigned hostelites |
| Method | Endpoint | Description |
|---|---|---|
| GET | /hostelite/profile |
Get profile |
| PUT | /hostelite/profile |
Update profile |
| GET | /hostelite/requests |
Get my requests |
| POST | /hostelite/requests/leave |
Submit leave request |
| POST | /hostelite/requests/mess-off |
Submit mess-off request |
| POST | /hostelite/requests/cleaning |
Submit cleaning request |
| GET | /hostelite/complaints |
Get my complaints |
| POST | /hostelite/complaints |
Submit complaint |
| GET | /hostelite/bills |
Get billing history |
| Method | Endpoint | Description |
|---|---|---|
| GET | /staff/tasks |
Get assigned tasks |
| PUT | /staff/tasks/:id |
Update task status |
| GET | /staff/profile |
Get profile |
| Method | Endpoint | Description |
|---|---|---|
| GET | /billing/challans/:hosteliteId |
Get user challans |
| POST | /billing/payment-intent |
Create payment intent |
| POST | /billing/webhook |
Stripe webhook handler |
Full system access and management capabilities
Permissions:
- β Create/manage hostels and room allocations
- β Add/remove hostelites with room assignments
- β Assign/remove hostel managers
- β View system-wide statistics and reports
- β Access all user data and activity logs
- β Manage system configurations
Dashboard Features:
- π Real-time occupancy rates across all hostels
- π₯ User management with role assignments
- π’ Hostel management with capacity tracking
- π System analytics and performance metrics
Manages assigned hostel operations
Permissions:
- β Review and approve/reject hostelite requests
- β Respond to complaints from assigned hostelites
- β View hostelite information for assigned hostel
- β Coordinate with cleaning staff
- β Generate hostel-specific reports
Dashboard Features:
- π Pending requests requiring review
- π Unresolved complaints
- π₯ Hostelite directory for assigned hostel
- π Hostel performance metrics
Self-service portal for hostel residents
Permissions:
- β Submit leave requests with date ranges
- β Request cleaning services for room
- β Submit mess-off requests
- β File complaints with tracking
- β View personal billing and payment history
- β Update personal profile information
Dashboard Features:
- π Request submission forms
- π Request status tracking
- π° Current and past bills
- π Complaint history
- π€ Profile management
Task management for cleaning personnel
Permissions:
- β View assigned cleaning tasks
- β Update task completion status
- β View daily/weekly schedules
- β Access contact information for emergencies
Dashboard Features:
- π Daily task list with priorities
- β Task completion tracking
- π Performance metrics
- π Emergency contact information
The system includes seeding scripts for development and testing:
# Seed test users
node scripts/seedUsers.js
# Seed billing data
node scripts/seedChallans.js
# register admin
node scripts/registerAdmin.js- Backend API is deployed on Render: https://nust-hostel-management-system.onrender.com
- Frontend (Next.js) is deployed on Vercel: https://nhms-eight.vercel.app
Backend (.env.production):
MONGODB_URI=mongodb+srv://production-user:password@cluster.mongodb.net/nhms-prod
JWT_SECRET=your-production-jwt-secret-very-long-and-secure
NODE_ENV=production
PORT=5000
CLIENT_URL=https://your-domain.comFrontend (.env.production):
NEXT_PUBLIC_API_URL=https://api.your-domain.com/api
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_your_live_stripe_keyWe welcome contributions to improve NHMS! Please follow these guidelines:
-
Fork the repository
git clone https://github.com/zainabraza06/nhms.git cd nhms -
Create feature branch
git checkout -b feature/your-feature-name
-
Set up development environment
cd backend && npm install cd ../frontend && npm install
-
Make your changes
- Follow existing code style and patterns
- Add comments for complex logic
- Update documentation if needed
-
Test your changes
# Backend tests cd backend && node tests/billing.test.js && node tests/messOff.test.js # Frontend checks cd frontend && npm run type-check && npm run lint
-
Commit and push
git add . git commit -m "feat: add your feature description" git push origin feature/your-feature-name
-
Create Pull Request
- Describe your changes clearly
- Link any related issues
- Add screenshots for UI changes
When reporting bugs, please include:
-
Environment details
- OS and version
- Node.js version
- Browser (for frontend issues)
-
Steps to reproduce
- Detailed step-by-step instructions
- Expected vs actual behavior
-
Error messages
- Full error stack traces
- Console logs
- Screenshots if applicable
-
Context
- User role when error occurred
- Relevant data or configurations
π§ Contact
- Project Maintainer: Zainab Raza Malik
- Institution: National University of Science and Technology (NUST)
- Email: [zainabraza1960@gmail.com]
- GitHub: [zainabraza06]
Made with β€οΈ for NUST Community