Skip to content

HiteshShonak/Hostel-Management-System-MERN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏨 HMS - Hostel Management System

IIIT Sonepat

A mobile platform for day-to-day hostel operations

React Native Expo SDK Node.js TypeScript MongoDB License


Live API Β Β  Download APK


Built with ❀️ for Indian Institute of Information Technology, Sonepat featuring QR gate passes, GPS attendance, mess management, emergency SOS & real-time notifications.


πŸ“± Features

For Students

  • 🎫 Digital Gate Passes - Request, track, and validate passes with QR codes
  • πŸ“ Smart Attendance - Geofence-based attendance marking (7 PM - 8 PM)
  • 🍽️ Mess Menu - Weekly menu with ratings and feedback
  • πŸ“’ Notice Board - Real-time notices from hostel admin
  • πŸ› οΈ Complaints - Submit and track maintenance requests
  • πŸ‘₯ Visitor Management - Pre-register visitors
  • πŸ”” Push Notifications - Real-time alerts and updates

For Parents

  • πŸ‘¨β€πŸ‘©β€πŸ‘§ Child Monitoring - View linked student activities
  • βœ… Gate Pass Approval - Two-tier approval (Parent β†’ Warden)
  • πŸ“Š Attendance Tracking - Daily attendance reports
  • 🚨 Emergency Alerts - Instant notifications

For Guards

  • πŸ“· QR Scanner - Validate gate passes quickly
  • πŸ“ Activity Logs - Entry/exit tracking
  • πŸ‘₯ Real-time Dashboard - Current pass status

For Wardens

  • πŸ“Š Dashboard - Hostel statistics at a glance
  • βœ“ Pass Management - Approve/reject gate passes
  • πŸ“‹ Student Management - View student records
  • πŸ“’ Notice Creation - Broadcast announcements

For Admins

  • πŸ‘₯ User Management - Create and manage all user types
  • πŸ”— Parent-Student Linking - Link parent accounts
  • βš™οΈ System Configuration - Geofence, attendance windows
  • πŸ“ˆ Analytics - System-wide insights

πŸ—οΈ Architecture

Frontend (Mobile App)

Technology Stack:
β”œβ”€β”€ React Native 0.81.5
β”œβ”€β”€ Expo SDK 54
β”œβ”€β”€ Expo Router (File-based routing)
β”œβ”€β”€ TypeScript 5.9
β”œβ”€β”€ TanStack Query (State management)
β”œβ”€β”€ Axios (HTTP client)
└── Expo Secure Store (Token storage)

Key Features:
β”œβ”€β”€ QR Code generation/scanning (expo-barcode-scanner)
β”œβ”€β”€ Geolocation (expo-location)
β”œβ”€β”€ Push notifications (expo-notifications)
β”œβ”€β”€ Dark/Light theme toggle
└── Offline-first with React Query caching

Backend (API Server)

Technology Stack:
β”œβ”€β”€ Node.js 18+
β”œβ”€β”€ Express 4.21
β”œβ”€β”€ MongoDB (Mongoose 8.9)
β”œβ”€β”€ Redis (ioredis) - Caching
β”œβ”€β”€ TypeScript 5.9
β”œβ”€β”€ JWT (jsonwebtoken)
└── PM2 (Process management)

Security:
β”œβ”€β”€ Helmet (HTTP headers)
β”œβ”€β”€ CORS (Origin whitelisting)
β”œβ”€β”€ Rate limiting (express-rate-limit)
β”œβ”€β”€ Input sanitization
β”œβ”€β”€ bcrypt (Password hashing)
β”œβ”€β”€ Expo Push Notifications
└── Zod (Schema validation)

πŸ“‚ Project Structure

HMS-Mobile/
β”‚
β”œβ”€β”€ Frontend/              # React Native Mobile App
β”‚   β”œβ”€β”€ app/              # Expo Router screens
β”‚   β”‚   β”œβ”€β”€ (tabs)/      # Main tab navigation
β”‚   β”‚   β”œβ”€β”€ guard/       # Guard-specific screens
β”‚   β”‚   β”œβ”€β”€ parent/      # Parent portal
β”‚   β”‚   └── warden/      # Warden dashboard
β”‚   β”œβ”€β”€ components/       # Reusable UI components
β”‚   β”œβ”€β”€ lib/             # Core utilities
β”‚   β”‚   β”œβ”€β”€ api.ts       # Axios instance
β”‚   β”‚   β”œβ”€β”€ hooks.ts     # React Query hooks
β”‚   β”‚   β”œβ”€β”€ services.ts  # API service layer
β”‚   β”‚   └── types.ts     # TypeScript types
β”‚   β”œβ”€β”€ app.json         # Expo configuration
β”‚   β”œβ”€β”€ eas.json         # EAS Build configuration
β”‚   └── package.json
β”‚
β”œβ”€β”€ Backend/              # Express API Server
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/ # Request handlers (14 files)
β”‚   β”‚   β”œβ”€β”€ models/      # MongoDB schemas (15 collections)
β”‚   β”‚   β”œβ”€β”€ routes/      # API endpoints
β”‚   β”‚   β”œβ”€β”€ middleware/  # Auth, validation, error handling
β”‚   β”‚   β”œβ”€β”€ services/    # Business logic (JWT, notifications)
β”‚   β”‚   β”œβ”€β”€ utils/       # Helpers (logger, cache, pagination)
β”‚   β”‚   β”œβ”€β”€ schemas/     # Zod validation schemas
β”‚   β”‚   └── types/       # TypeScript interfaces
β”‚   β”œβ”€β”€ dist/            # Compiled JavaScript (production)
β”‚   β”œβ”€β”€ ecosystem.config.js  # PM2 configuration
β”‚   β”œβ”€β”€ .env             # Environment variables
β”‚   └── package.json
β”‚
└── Documentation.md      # Detailed project documentation

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ (Download)
  • MongoDB 5+ (Local or MongoDB Atlas)
  • Redis 6+ (Optional but recommended)
  • Git (Download)
  • Expo CLI (will be installed automatically)

Backend Setup

# 1. Clone repository
git clone <repository-url>
cd HMS-Mobile/Backend

# 2. Install dependencies
npm install

# 3. Configure environment
cp .env.example .env
# Edit .env with your values:
#   - MONGODB_URI (your MongoDB connection)
#   - JWT_SECRET (generate with: node -e "console.log(require('crypto').randomBytes(64).toString('hex'))")
#   - REDIS_URL (if using Redis)

# 4. Run development server
npm run dev

# Server starts at http://localhost:5000
# Health check: http://localhost:5000/health

Frontend Setup

# 1. Navigate to frontend
cd ../Frontend

# 2. Install dependencies
npm install

# 3. Configure API URL
# Edit .env file:
EXPO_PUBLIC_API_URL=http://YOUR_LOCAL_IP:5000/api
# Note: Use your computer's local IP (not localhost) for physical device testing

# 4. Start Expo
npx expo start

# Options:
# - Press 'a' for Android emulator
# - Press 'i' for iOS simulator (Mac only)
# - Scan QR code with Expo Go app on your phone

πŸ”§ Environment Variables

Backend .env

# Server
PORT=5000
NODE_ENV=development

# MongoDB
MONGODB_URI=mongodb://localhost:27017/hms
# Or MongoDB Atlas: mongodb+srv://username:password@cluster.mongodb.net/database

# JWT
JWT_SECRET=your-super-secret-key-CHANGE-THIS
JWT_EXPIRES_IN=7d

# Redis (optional)
REDIS_URL=redis://localhost:6379

# CORS (production domains)
ALLOWED_ORIGINS=https://yourdomain.com

Frontend .env

# API Configuration
EXPO_PUBLIC_API_URL=http://192.168.1.33:5000/api

# For production:
# EXPO_PUBLIC_API_URL=https://your-backend-domain.com/api

πŸ“¦ Building for Production

Android APK

# 1. Install EAS CLI
npm install -g eas-cli

# 2. Login to Expo
eas login

# 3. Build APK
cd Frontend
eas build --platform android --profile preview

# Wait 15-20 minutes -> Download APK -> Share with users

iOS IPA (Requires Mac + Apple Developer Account)

# Build for TestFlight
cd Frontend
eas build --platform ios --profile preview

# Submit to App Store
eas submit --platform ios

Backend Deployment (Render)

Already deployed at: https://hostel-management-system-backend-jde3.onrender.com

To deploy your own:

  1. Create account at render.com
  2. Connect GitHub repository
  3. Add environment variables
  4. Deploy with one click

πŸ§ͺ Testing

Backend Tests

cd Backend
npm test          # Run all tests
npm run test:watch # Watch mode

API Testing

# Health Check
curl https://hostel-management-system-backend-jde3.onrender.com/health

# Login
curl -X POST https://your-backend/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"student@test.com","password":"password123"}'

πŸ“Š Project Statistics

Component Files Lines of Code
Frontend ~5,206 lines React Native, TypeScript
Backend ~5,755 lines Node.js, Express, TypeScript
Total ~10,961 lines Production code

Database Collections (15 total)

  • users - All user accounts (students, parents, staff)
  • gatepasses - Gate pass requests
  • gatepasslogs - Entry/exit activity
  • attendance - Daily attendance records
  • notices - Notice board posts
  • complaints - Maintenance complaints
  • messmenus - Weekly meal schedules
  • foodratings - Meal ratings
  • visitors - Visitor registrations
  • payments - Fee tracking
  • laundries - Laundry service
  • emergencies - SOS alerts
  • notifications - In-app notifications
  • parentstudents - Parent-child links
  • systemconfigs - System settings

πŸ”’ Security Features

βœ… JWT Authentication - Secure token-based auth
βœ… Password Hashing - bcrypt with salt rounds
βœ… Role-Based Access Control - Student, Parent, Guard, Warden, Admin
βœ… Rate Limiting - Protect against brute force (3 tiers)
βœ… Input Validation - Zod schemas for all endpoints
βœ… XSS Protection - Input sanitization middleware
βœ… CORS Whitelisting - Configurable allowed origins
βœ… Helmet Security - HTTP headers hardening
βœ… Geofencing - Location-based attendance verification
βœ… QR Code Security - Unique codes for gate pass validation


🌟 Key Highlights

  • βœ… Mobile-First Design - Optimized for students on the go
  • βœ… Real-Time Updates - Push notifications for instant alerts
  • βœ… Offline Support - React Query caching for offline access
  • βœ… Dark Mode - System-aware theme switching
  • βœ… Production-Ready - PM2 cluster mode, Redis caching, structured logging
  • βœ… Type-Safe - Full TypeScript on frontend and backend
  • βœ… Scalable Architecture - Supports 1000+ concurrent users

πŸ“š Documentation


πŸ› οΈ Development

Running Locally

# Terminal 1 - Backend
cd Backend
npm run dev
# Server at http://localhost:5000

# Terminal 2 - Frontend
cd Frontend
npx expo start
# Scan QR with Expo Go app

Code Quality

# Backend build check
cd Backend
npm run build

# TypeScript check
npx tsc --noEmit

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License.


πŸ‘₯ Team

Developed at Indian Institute of Information Technology, Sonepat (IIIT Sonepat)


πŸ†˜ Support

For issues or questions:

  • Check Documentation.md
  • Review API docs
  • Open an issue on the GitHub repository
  • Contact the team at IIIT Sonepat

🎯 Roadmap

  • WebSocket for live updates
  • Analytics dashboard
  • SMS notifications for parents
  • Biometric authentication
  • Offline mode sync
  • Multi-language support
  • Payment gateway integration
  • Medical records module
  • Event calendar
  • Chat system (Student ↔ Warden)

Built with ❀️ at IIIT Sonepat for smarter hostel management

About

A production-ready Hostel Management System (HMS) built with React Native, Expo, Node.js, & MongoDB. Features QR Gate Passes, Geofenced Attendance, and Role-Based Access Control (RBAC).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages