Skip to content

zainabraza06/NHMS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

30 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NUST Hostel Management System (NHMS)

🏠 A modern, role-based hostel management system for academic institutions

Built with MERN Stack (MongoDB, Express.js, React, Node.js)


πŸ“– Table of Contents


πŸ“ Overview

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).

🎯 Problem Statement

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

πŸ’‘ Solution

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

✨ Features

πŸ” Authentication & Authorization

  • 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

πŸ‘¨β€πŸ’Ό Admin Features

  • 🏒 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

🏨 Hostel Manager Features

  • πŸ“‹ 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

🏠 Hostelite Features

  • πŸ“ 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

🧹 Cleaning Staff Features

  • πŸ“‹ Task Management: View assigned cleaning tasks
  • βœ… Status Updates: Mark tasks as completed
  • πŸ“… Schedule View: Daily and weekly task schedules
  • πŸ“Š Performance Tracking: Task completion metrics

πŸ’° Billing & Payments

  • πŸ“… Automated Challan Generation: Monthly billing cycles
  • πŸ’³ Payment Integration: Stripe-powered payment processing
  • πŸ“Š Payment Tracking: Real-time payment status
  • πŸ“§ Notifications: Email reminders and receipts

πŸ› οΈ Tech Stack

Backend Technologies

  • 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

Frontend Technologies

  • 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

DevOps & Tools

  • 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

πŸ—οΈ Project Architecture

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

πŸš€ Quick Start

Prerequisites

Ensure you have the following installed:

  • Node.js (v16 or higher) - Download
  • MongoDB (local installation or MongoDB Atlas) - Download
  • Git for version control - Download

πŸƒβ€β™‚οΈ One-Command Setup

# 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 dev

Open http://localhost:3000 in your browser.


πŸ“‹ Detailed Setup

1. πŸ—„οΈ Database Setup

Option A: Local MongoDB

# 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

Option B: MongoDB Atlas (Recommended)

  1. Create account at MongoDB Atlas
  2. Create a new cluster
  3. Get connection string: mongodb+srv://username:password@cluster.mongodb.net/nhms

2. βš™οΈ Backend Configuration

cd backend
npm install

Create .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

Start Backend Server

# Development mode with auto-reload
npm run dev

# Production mode
npm start

# Run tests
node tests/billing.test.js
node tests/messOff.test.js

3. 🎨 Frontend Configuration

cd frontend
npm install

Create .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

Start Frontend Application

# Development mode
npm run dev

# Build for production
npm run build
npm start

# Type checking
npm run type-check

# Linting
npm run lint

4. 🌱 Database Seeding (Optional)

cd backend

# Seed initial users (admin, managers, hostelites)
npm run seed:users

# Seed sample billing data
node scripts/seedChallans.js

5. πŸ”‘ Default Credentials

After 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

πŸ”Œ API Documentation

Base URL

http://localhost:5000/api

πŸ” Authentication Endpoints

POST /auth/register

Register a new user

{
  "firstName": "John",
  "lastName": "Doe", 
  "email": "john.doe@nust.edu.pk",
  "password": "securePassword",
  "phoneNumber": "+92-300-1234567",
  "role": "HOSTELITE"
}

POST /auth/login

User login

{
  "email": "john.doe@nust.edu.pk",
  "password": "securePassword"
}

πŸ‘¨β€πŸ’Ό Admin Endpoints

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

🏨 Manager Endpoints

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

🏠 Hostelite Endpoints

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

🧹 Staff Endpoints

Method Endpoint Description
GET /staff/tasks Get assigned tasks
PUT /staff/tasks/:id Update task status
GET /staff/profile Get profile

πŸ’° Billing Endpoints

Method Endpoint Description
GET /billing/challans/:hosteliteId Get user challans
POST /billing/payment-intent Create payment intent
POST /billing/webhook Stripe webhook handler

πŸ‘₯ User Roles & Permissions

πŸ”‘ Admin (System Administrator)

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

🏨 Hostel Manager

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

🏠 Hostelite (Student Resident)

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

🧹 Cleaning Staff

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

πŸ—‚οΈ Test Data

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

πŸš€ Deployment

πŸ“ Current Hosting

🌐 Environment Preparation

Production Environment Variables

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.com

Frontend (.env.production):

NEXT_PUBLIC_API_URL=https://api.your-domain.com/api
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_your_live_stripe_key

🀝 Contributing

We welcome contributions to improve NHMS! Please follow these guidelines:

πŸ”§ Development Workflow

  1. Fork the repository

    git clone https://github.com/zainabraza06/nhms.git
    cd nhms
  2. Create feature branch

    git checkout -b feature/your-feature-name
  3. Set up development environment

    cd backend && npm install
    cd ../frontend && npm install
  4. Make your changes

    • Follow existing code style and patterns
    • Add comments for complex logic
    • Update documentation if needed
  5. 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
  6. Commit and push

    git add .
    git commit -m "feat: add your feature description"
    git push origin feature/your-feature-name
  7. Create Pull Request

    • Describe your changes clearly
    • Link any related issues
    • Add screenshots for UI changes

πŸ› Bug Reports

When reporting bugs, please include:

  1. Environment details

    • OS and version
    • Node.js version
    • Browser (for frontend issues)
  2. Steps to reproduce

    • Detailed step-by-step instructions
    • Expected vs actual behavior
  3. Error messages

    • Full error stack traces
    • Console logs
    • Screenshots if applicable
  4. 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

About

NUST Hostel Management System (NHMS) is a MERN-based, role-driven platform that digitizes hostel operations with dedicated dashboards for admins, managers, staff, and hostelites, supporting requests, complaints, billing, and hostel management workflows.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors