# mohitsaini2028/hotel-booking-system architecture

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

- Interactive diagram: https://gitdiagram.com/mohitsaini2028/hotel-booking-system
- Repository: https://github.com/mohitsaini2028/hotel-booking-system

## Overview

##### Project type and purpose
- This is a full-stack hotel booking system composed of three main parts:
- An “Admin” React SPA for internal management (in `/admin`).
- A public “Client” React SPA for customers (in `/client`).
- A Node.js/Express REST API for business logic and data access (in `/api`).
- The README describes a booking site where users search destinations, compare prices, view rooms, and an admin panel to manage hotels, rooms, and users.

##### File structure
- Top-level directories:
- `/admin` (React, components, context, pages)
- `/client` (React, components, context, pages)
- `/api` (Express entry point, routes, controllers, models, utils)
- API uses MVC-style separation:
- `routes/*.js` define endpoints
- `controllers/*.js` implement request handlers
- `models/*.js` define MongoDB schemas via Mongoose
- `utils/verifyToken.js` and `error.js` provide middleware and error handling
- Frontends use Context for global state (AuthContext, darkModeContext, SearchContext), React Router (in App.js), and custom hooks (useFetch).

##### README for additional insights
- Features: search/filter, comparison, room listing, user authentication.

##### Elements
- API layers in another (e.g., green)
- Database in a third (e.g., orange)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layers
    subgraph "Admin Frontend" 
        direction TB
        AdminIndex["Entry Point\nindex.js"]:::frontend
        AdminApp["Main Router\nApp.js"]:::frontend
        subgraph "Context Providers"
            direction TB
            AdminAuthContext["AuthContext.js"]:::frontend
            AdminDarkContext["darkModeContext.js"]:::frontend
        end
        AdminHook["useFetch.js"]:::frontend
        subgraph "Pages" 
            direction TB
            AdminHome["Home.jsx"]:::frontend
            AdminList["List.jsx"]:::frontend
            AdminLogin["Login.jsx"]:::frontend
            AdminNew["New.jsx"]:::frontend
            AdminNewHotel["NewHotel.jsx"]:::frontend
            AdminNewRoom["NewRoom.jsx"]:::frontend
            AdminSingle["Single.jsx"]:::frontend
        end
    end

    subgraph "Client Frontend" 
        direction TB
        ClientIndex["Entry Point\nindex.js"]:::frontend
        ClientApp["Main Router\nApp.js"]:::frontend
        subgraph "Context Providers"
            direction TB
            ClientAuthContext["AuthContext.js"]:::frontend
            ClientSearchContext["SearchContext.js"]:::frontend
        end
        ClientHook["useFetch.js"]:::frontend
        subgraph "Pages" 
            direction TB
            ClientHome["Home.jsx"]:::frontend
            ClientList["List.jsx"]:::frontend
            ClientHotel["Hotel.jsx"]:::frontend
            ClientLogin["Login.jsx"]:::frontend
        end
    end

    %% API Layer
    subgraph "API Server" 
        direction TB
        APIEntry["Express Entry\nindex.js"]:::backend

        subgraph "Routes" 
            direction TB
            routeAuth["auth.js"]:::backend
            routeHotels["hotels.js"]:::backend
            routeRooms["rooms.js"]:::backend
            routeUsers["users.js"]:::backend
        end

        subgraph "Controllers" 
            direction TB
            ctrlAuth["auth.js"]:::backend
            ctrlHotel["hotel.js"]:::backend
            ctrlRoom["room.js"]:::backend
            ctrlUser["user.js"]:::backend
        end

        subgraph "Models" 
            direction TB
            modelHotel["Hotel.js"]:::backend
            modelRoom["Room.js"]:::backend
            modelUser["User.js"]:::backend
        end

        subgraph "Utils/Middleware" 
            direction TB
            utilVerify["verifyToken.js"]:::utility
            utilError["error.js"]:::utility
            envConfig[".env"]:::utility
        end
    end

    %% Database
    MongoDB["MongoDB\n(Atlas)"]:::db

    %% Connections
    AdminApp -->|"HTTP/HTTPS"| APIEntry
    ClientApp -->|"HTTP/HTTPS"| APIEntry

    APIEntry -->|"use routes"| routeAuth
    APIEntry --> routeHotels
    APIEntry --> routeRooms
    APIEntry --> routeUsers

    routeAuth --> ctrlAuth
    routeHotels --> ctrlHotel
    routeRooms --> ctrlRoom
    routeUsers --> ctrlUser

    ctrlAuth --> utilVerify
    ctrlAuth --> utilError

    ctrlHotel --> modelHotel
    ctrlRoom --> modelRoom
    ctrlUser --> modelUser

    modelHotel --> MongoDB
    modelRoom --> MongoDB
    modelUser --> MongoDB

    %% Click Events - Admin
    click AdminIndex "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/index.js"
    click AdminApp "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/App.js"
    click AdminAuthContext "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/context/AuthContext.js"
    click AdminDarkContext "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/context/darkModeContext.js"
    click AdminHook "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/hooks/useFetch.js"
    click AdminHome "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/pages/home/Home.jsx"
    click AdminList "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/pages/list/List.jsx"
    click AdminLogin "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/pages/login/Login.jsx"
    click AdminNew "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/pages/new/New.jsx"
    click AdminNewHotel "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/pages/newHotel/NewHotel.jsx"
    click AdminNewRoom "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/pages/newRoom/NewRoom.jsx"
    click AdminSingle "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/admin/src/pages/single/Single.jsx"

    %% Click Events - Client
    click ClientIndex "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/client/src/index.js"
    click ClientApp "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/client/src/App.js"
    click ClientAuthContext "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/client/src/context/AuthContext.js"
    click ClientSearchContext "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/client/src/context/SearchContext.js"
    click ClientHook "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/client/src/hooks/useFetch.js"
    click ClientHome "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/client/src/pages/home/Home.jsx"
    click ClientList "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/client/src/pages/list/List.jsx"
    click ClientHotel "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/client/src/pages/hotel/Hotel.jsx"
    click ClientLogin "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/client/src/pages/login/Login.jsx"

    %% Click Events - API
    click APIEntry "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/index.js"
    click routeAuth "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/routes/auth.js"
    click routeHotels "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/routes/hotels.js"
    click routeRooms "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/routes/rooms.js"
    click routeUsers "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/routes/users.js"
    click ctrlAuth "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/controllers/auth.js"
    click ctrlHotel "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/controllers/hotel.js"
    click ctrlRoom "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/controllers/room.js"
    click ctrlUser "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/controllers/user.js"
    click modelHotel "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/models/Hotel.js"
    click modelRoom "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/models/Room.js"
    click modelUser "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/models/User.js"
    click utilVerify "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/utils/verifyToken.js"
    click utilError "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/utils/error.js"
    click envConfig "https://github.com/mohitsaini2028/hotel-booking-system/blob/main/api/.env"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#000
    classDef backend fill:#D0FFD8,stroke:#28a745,color:#000
    classDef db fill:#FFE4B3,stroke:#d99923,color:#000
    classDef utility fill:#FFF4CE,stroke:#cfa216,color:#000
```
