How saad0095/hotel-management-system works
Project type and purpose
• This is a backend RESTful API for a Hotel Management System, built with Node.js, Express, and MongoDB (Mongoose).
• It provides endpoints for rooms, users, bookings, services, and analytics, secured with JWT-based authentication and role-based access.
Main architectural layers & components
a. Client Layer (External)
• Mobile app / Web front-end / CLI / third-party integrator
• Sends HTTP(S) requests with JWT tokens
b. API Layer (Express Server)
• index.js: entry point, loads middlewares, routes, DB connection
• middlewares/:
• authMiddleware.js – JWT verification, role checks
• uploadMiddleware.js – file upload handling (e.g., profile images)
• routes/:
• Maps URL paths (/api/rooms, /api/bookings, etc.) to controllers
c. Controller Layer
• controllers/*.js
• Implements business logic: validate inputs, call models, handle errors
d. Data Access Layer (Models & DB)
• models/*.js – Mongoose schemas for User, Room, Booking, Service
• db/index.js – Initializes MongoDB connection
• seed/ – Scripts to prepopulate MongoDB with rooms, services, bookings, users
e. External Dependencies
• MongoDB (local or Atlas)
• JWT Authentication
• File storage (local / cloud for uploads/)
Relationships & Data Flow
1. Client → Express Server (HTTP request + Authorization header)
2. Express Router → Auth Middleware → Upload Middleware (if applicable)
3. Controller → calls Model methods
4. Model → interacts with MongoDB
5. Controller → responds to client
Architectural patterns & design principles
• Layered architecture: separation of concerns (routing, middleware, controllers, models)
• RESTful design: one resource per route file
• JWT-based stateless authentication & RBAC
• Single codebase monolith, prepared for horizontal scaling
Technologies & frameworks in each layer
• Node.js, Express
• Mongoose (MongoDB ODM)
• JWT (jsonwebtoken)
• dotenv (config)
• multer or similar for file uploads
• npm scripts for seeding data