# pamodaravihansa/hotel-management-system-mern-stack architecture

> Architecture diagram of the GitHub repository pamodaravihansa/hotel-management-system-mern-stack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pamodaravihansa/hotel-management-system-mern-stack
- Repository: https://github.com/pamodaravihansa/hotel-management-system-mern-stack

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) web application.
- Purpose: A Hotel Management System (“Hotel Elite”) that automates customer reservations, employee management, room management, supplier management, and inventory management via a React SPA frontend and a RESTful Node/Express backend connected to MongoDB.

##### File structure
- Top-level separation into two folders:
- backend (Express server, Mongoose models, REST routes)
- frontend (React SPA, components, pages, static assets)
- Backend follows an MVC-like organization:
- models/: Mongoose schemas for admin, customer, employee, booking, inventory, supplier
- routes/: Express routers mapping HTTP endpoints to controllers
- server.js: entrypoint that wires routes, middleware, DB connection
- Frontend is a component-driven React app:
- src/components/: domain-specific UI modules (Auth, Employee, Room, Inventory, Supplier, Layouts)
- src/pages/: top-level views (Home, Rooms, SingleRoom, Error)
- Context, data files, service worker, Contentful integration for CMS
- Package.json files in both folders define dependencies and scripts (`npm run server`, `npm start`).

##### README insights
- Confirms MERN stack, REST API approach, no mention of microservices—monolithic backend.
- Key features: customer reservation flow, CRUD for employees, rooms, suppliers, inventory.

##### Detail without over-segmentation
- Domain as its own service/module rather than one monolithic block.
- One-to-many Mongoose model relationships (e.g., bookings reference rooms, employees).
- Fallback or error flows if desired (e.g., API → Error Page).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        direction TB
        SPA["Browser / React SPA"]:::frontend
        Contentful["Contentful CMS Integration"]:::external
        subgraph "Components"
            direction TB
            AuthComp["Auth Components"]:::frontend
            RoomComp["Room Components"]:::frontend
            EmpComp["Employee Components"]:::frontend
            InvComp["Inventory Components"]:::frontend
            SupComp["Supplier Components"]:::frontend
            LayoutComp["Layout Components"]:::frontend
        end
        subgraph "Pages"
            direction TB
            Pages["Top-level Pages"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend (Node/Express)"
        direction TB
        APIServer["API Gateway / Express Server"]:::backend

        subgraph "Authentication Service"
            direction TB
            AdminModel["AdminLoginModel"]:::model
            AdminRoute["AdminLoginRoutes"]:::route
            CustomerModel["CustomerModel"]:::model
            CustomerRoute["CustomerRoutes"]:::route
        end

        subgraph "Reservation Service"
            direction TB
            BookingModel["BookingModel"]:::model
            BookingRoute["BookingRoutes"]:::route
        end

        subgraph "Room Management Service"
            direction TB
            RoomMgmtModel["RoomModel"]:::model
            RoomMgmtRoute["RoomRoutes"]:::route
            RoomsModel["RoomsCollectionModel"]:::model
            RoomsRoute["RoomsCollectionRoutes"]:::route
        end

        subgraph "Employee Service"
            direction TB
            EmpModel["EmployeesModel"]:::model
            SalaryModel["PaidSalariesModel"]:::model
            EmpRoute["EmployeesRoutes"]:::route
            SalaryRoute["PaidSalariesRoutes"]:::route
        end

        subgraph "Supplier Service"
            direction TB
            SupModel["SupplierModel"]:::model
            SupHistModel["SupplierHistoryModel"]:::model
            SupRoute["SupplierRoutes"]:::route
            SupHistRoute["SupplierHistoryRoutes"]:::route
        end

        subgraph "Inventory Service"
            direction TB
            InvModel["InventoryModel"]:::model
            InvRoute["InventoryRoutes"]:::route
        end
    end

    %% Database Layer
    subgraph "MongoDB"
        direction TB
        DB1["Admins Collection"]:::db
        DB2["Customers Collection"]:::db
        DB3["Bookings Collection"]:::db
        DB4["Rooms Collection"]:::db
        DB5["Employees Collection"]:::db
        DB6["PaidSalaries Collection"]:::db
        DB7["Suppliers Collection"]:::db
        DB8["SupplierHistory Collection"]:::db
        DB9["Inventory Collection"]:::db
    end

    %% External Services
    ExternalAuth["Third-Party Auth/Email/SMS"]:::external

    %% Connections
    SPA -->|"HTTP REST"| APIServer
    Contentful -->|fetch data| SPA

    APIServer -->|"uses"| AdminRoute
    APIServer -->|"uses"| CustomerRoute
    APIServer -->|"uses"| BookingRoute
    APIServer -->|"uses"| RoomMgmtRoute
    APIServer -->|"uses"| RoomsRoute
    APIServer -->|"uses"| EmpRoute
    APIServer -->|"uses"| SalaryRoute
    APIServer -->|"uses"| SupRoute
    APIServer -->|"uses"| SupHistRoute
    APIServer -->|"uses"| InvRoute

    AdminRoute -->|"calls"| AdminModel
    CustomerRoute -->|"calls"| CustomerModel
    BookingRoute -->|"calls"| BookingModel
    RoomMgmtRoute -->|"calls"| RoomMgmtModel
    RoomsRoute -->|"calls"| RoomsModel
    EmpRoute -->|"calls"| EmpModel
    SalaryRoute -->|"calls"| SalaryModel
    SupRoute -->|"calls"| SupModel
    SupHistRoute -->|"calls"| SupHistModel
    InvRoute -->|"calls"| InvModel

    AdminModel -->|"CRUD"| DB1
    CustomerModel -->|"CRUD"| DB2
    BookingModel -->|"CRUD"| DB3
    RoomMgmtModel -->|"CRUD"| DB4
    RoomsModel -->|"CRUD"| DB4
    EmpModel -->|"CRUD"| DB5
    SalaryModel -->|"CRUD"| DB6
    SupModel -->|"CRUD"| DB7
    SupHistModel -->|"CRUD"| DB8
    InvModel -->|"CRUD"| DB9

    APIServer --> ExternalAuth
    SPA --> ExternalAuth

    %% Click Events Frontend
    click SPA "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/tree/main/frontend/src"
    click Contentful "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/frontend/src/Contentful.js"
    click AuthComp "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/tree/main/frontend/src/components/auth"
    click RoomComp "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/tree/main/frontend/src/components/room"
    click EmpComp "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/tree/main/frontend/src/components/employee"
    click InvComp "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/tree/main/frontend/src/components/inventory"
    click SupComp "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/tree/main/frontend/src/components/supplier"
    click LayoutComp "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/tree/main/frontend/src/components/layouts"
    click Pages "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/tree/main/frontend/src/pages"

    %% Click Events Backend
    click APIServer "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/server.js"
    click AdminModel "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/models/adminlogin.js"
    click AdminRoute "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/routes/adminlogin.js"
    click CustomerModel "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/models/customer/customerModel.js"
    click CustomerRoute "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/routes/customer/customerRoute.js"
    click BookingModel "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/models/room-booking/bookingModel.js"
    click BookingRoute "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/routes/room-booking/bookingRoute.js"
    click RoomMgmtModel "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/models/employee-manager/roomModel.js"
    click RoomMgmtRoute "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/routes/employee-manager/RoomRoute.js"
    click RoomsModel "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/models/rooms.js"
    click RoomsRoute "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/routes/rooms.js"
    click EmpModel "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/models/emp-manager/employees.js"
    click SalaryModel "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/models/emp-manager/paidsalaries.js"
    click EmpRoute "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/routes/emp-manager/employees.js"
    click SalaryRoute "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/routes/emp-manager/paidsalaries.js"
    click SupModel "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/models/supplier-manager/suppliermodel.js"
    click SupHistModel "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/models/supplier-manager/supplierhistorymodel.js"
    click SupRoute "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/routes/supplier-manager/supplierRoute.js"
    click SupHistRoute "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/routes/supplier-manager/supplierhistoryRoute.js"
    click InvModel "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/models/inventory-manager/inventoryModel.js"
    click InvRoute "https://github.com/pamodaravihansa/hotel-management-system-mern-stack/blob/main/backend/routes/inventory-manager/inventoryRoute.js"

    %% Styles
    classDef frontend fill:#ccffcc,stroke:#006600,color:#003300;
    classDef backend fill:#cce0ff,stroke:#004080,color:#002040;
    classDef model fill:#ffe0b3,stroke:#cc7a00,color:#663c00;
    classDef route fill:#ffddb3,stroke:#cc8c00,color:#663d00;
    classDef db fill:#ffcccc,stroke:#cc0000,color:#660000;
    classDef external fill:#e0ccff,stroke:#8000cc,color:#400066;
```
