# debjitpramanick/hotel-booking-web-app architecture

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

- Interactive diagram: https://gitdiagram.com/debjitpramanick/hotel-booking-web-app
- Repository: https://github.com/debjitpramanick/hotel-booking-web-app

## Overview

##### Project type and purpose
- This is a full‑stack MERN (MongoDB, Express.js, React, Node.js) hotel‑booking web application.
- Frontend: React SPA that consumes a GraphQL API.
- Backend: Node.js/Express server exposing a GraphQL endpoint.
- Data layer: MongoDB for persisting users, hotels, rooms, bookings.
- External services: Stripe for payments (and optionally Firebase if used for file storage or auth utilities).

##### Main components
a. Presentation Layer (Client)
- Browser / React SPA
- Key parts:
- React Router–managed pages (Home, Explore, HotelPage, Auth, Dashboard, Bookings, Payment, Profile)
- Reusable components: Header, Sidebars, Modals, Loaders, SearchBar, etc.
- GraphQL client (Apollo or fetch) for queries & mutations.
b. API Layer (Server)
- Node.js + Express
- GraphQL middleware (apollo-server-express or express-graphql)
- Middleware functions: isAuth, verifyToken (JWT auth)
- GraphQL schema modules: Query, Mutation, CustomTypes, Type definitions
- Resolvers: bookingQueries, hotelQueries, roomQueries, userQueries, bookingMutations, etc.
c. Data Layer
- MongoDB database
- Mongoose models: User, Hotel, Room, Booking
d. External Services
- Stripe API for payment processing
- (Optional) Firebase utility module if used for image upload or auth
e. Development / Deployment
- GitHub repo, CI/CD to Vercel (frontend) and your Node server host
- .env for MONGO_URL, Stripe keys, JWT secrets

##### Relationships and interactions
- User (browser) → React SPA
- React SPA → GraphQL API (HTTP POST) for queries & mutations
- GraphQL server → MongoDB for data CRUD
- GraphQL mutations for payments → Stripe API → webhooks → update Booking status
- Auth flow: React SPA sends credentials → login mutation → server issues JWT → client stores token → client attaches JWT in Authorization header on subsequent requests
- Admin/Manager role paths: additional mutations for creating/updating/deleting hotels & rooms

##### Architectural patterns & design principles
- Three‑tier architecture: Presentation, API, Data
- GraphQL schema-driven development (type-first)
- MVC‑style within server: schema/resolvers (controller) + models (data)
- Component‑based UI in React (atomic design)
- Context API for global state (auth context, theme, etc.)
- Separation of concerns:
- UI logic vs API calls
- Auth middleware vs business logic

##### What to capture in detail
- Authentication middleware flow: isAuth → verifyToken → context.user
- GraphQL schema structure: Queries vs Mutations modules
- Payment workflow: StripeForm in client → paymentMutation → Stripe SDK on server → webhook callback
- Data relationships: User ←→ Booking ←→ Room ←→ Hotel
- Role‑based access (admin vs manager vs guest)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer (React SPA)" 
        direction TB
        Browser["Browser"]:::external
        ReactApp["React SPA"]:::presentation
        subgraph "Entry Points"
            direction TB
            App["App.js"]:::presentation
            Index["index.js"]:::presentation
        end
        subgraph "Pages" 
            direction TB
            AuthPage["Auth"]:::presentation
            HomePage["Home"]:::presentation
            ExplorePage["Explore"]:::presentation
            HotelPage["HotelPage"]:::presentation
            DashboardPage["Dashboard"]:::presentation
            BookingsPage["Bookings"]:::presentation
            PaymentPage["Payment"]:::presentation
            ProfilePage["Profile"]:::presentation
        end
        subgraph "Components" 
            direction TB
            HeaderComp["Header"]:::presentation
            SidebarsComp["Sidebars"]:::presentation
            ModalsComp["Modals"]:::presentation
            LoadersComp["Loaders"]:::presentation
            SearchBarComp["SearchBar"]:::presentation
        end
        subgraph "GraphQL Client" 
            direction TB
            Queries["queries"]:::presentation
            Mutations["mutations"]:::presentation
        end
        subgraph "Utils" 
            direction TB
            Context["Context.js"]:::presentation
            ConditionalRoutes["ConditionalRoutes.js"]:::presentation
            FirebaseUtil["Firebase.js"]:::presentation
        end
    end

    %% API Layer
    subgraph "API Layer (Express + GraphQL)"
        direction TB
        ServerEntry["server.js"]:::api
        subgraph "Middleware"
            direction TB
            IsAuth["isAuth.js"]:::api
            VerifyToken["verifyToken.js"]:::api
        end
        subgraph "GraphQL Server"
            direction TB
            Schema["Schema.js"]:::api
            TypeDefs["Type.js & CustomTypes.js"]:::api
            subgraph "Queries"
                direction TB
                BookingQ["bookingQueries.js"]:::api
                HotelQ["hotelQueries.js"]:::api
                RoomQ["roomQueries.js"]:::api
                UserQ["userQueries.js"]:::api
            end
            subgraph "Mutations"
                direction TB
                BookingM["bookingMutation.js"]:::api
                HotelM["hotelMutations.js"]:::api
                RoomM["roomMutations.js"]:::api
                UserM["userMutations.js"]:::api
                PaymentM["paymentMutation.js"]:::api
            end
        end
    end

    %% Data Layer
    subgraph "Data Layer (MongoDB)" 
        direction TB
        MongoDB[(MongoDB)]:::data
        subgraph "Collections"
            direction TB
            UserModel["User.js"]:::data
            HotelModel["Hotel.js"]:::data
            RoomModel["Room.js"]:::data
            BookingModel["Booking.js"]:::data
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Stripe["Stripe API"]:::external
        Firebase["Firebase (optional)"]:::external
    end

    %% Connections
    Browser -->|"loads"| ReactApp
    ReactApp -->|"HTTP GraphQL Query/Mutation (+ JWT)"| Schema
    ServerEntry -->|uses| IsAuth
    ServerEntry -->|uses| VerifyToken
    Schema -->|executes| BookingQ
    Schema -->|executes| HotelQ
    Schema -->|executes| RoomQ
    Schema -->|executes| UserQ
    Schema -->|executes| BookingM
    Schema -->|executes| HotelM
    Schema -->|executes| RoomM
    Schema -->|executes| UserM
    Schema -->|executes| PaymentM
    PaymentM -->|"Stripe SDK"| Stripe
    Schema -->|"CRUD"| MongoDB
    ReactApp -->|"Payment Request"| Stripe
    ReactApp -->|"Optional File Storage"| Firebase

    %% Click Events
    click App "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/client/src/App.js"
    click Index "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/client/src/index.js"
    click AuthPage "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/pages/Auth"
    click HomePage "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/pages/Home"
    click ExplorePage "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/pages/Explore"
    click HotelPage "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/pages/HotelPage"
    click DashboardPage "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/pages/Dashboard"
    click BookingsPage "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/pages/Bookings"
    click PaymentPage "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/pages/Payment"
    click ProfilePage "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/pages/Profile"
    click HeaderComp "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/components/Header"
    click SidebarsComp "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/components/Sidebars"
    click ModalsComp "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/components/Modals"
    click LoadersComp "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/components/Loaders"
    click SearchBarComp "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/components/SearchBar"
    click Queries "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/graphql/queries"
    click Mutations "https://github.com/debjitpramanick/hotel-booking-web-app/tree/master/client/src/graphql/mutations"
    click Context "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/client/src/utils/Context.js"
    click ConditionalRoutes "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/client/src/utils/ConditionalRoutes.js"
    click FirebaseUtil "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/client/src/utils/Firebase.js"
    click ServerEntry "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/server.js"
    click IsAuth "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/middlewares/isAuth.js"
    click VerifyToken "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/middlewares/verifyToken.js"
    click Schema "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/schemas/Schema.js"
    click TypeDefs "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/schemas/Type.js"
    click BookingQ "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/schemas/queries/bookingQueries.js"
    click HotelQ "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/schemas/queries/hotelQueries.js"
    click RoomQ "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/schemas/queries/roomQueries.js"
    click UserQ "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/schemas/queries/userQueries.js"
    click BookingM "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/schemas/mutations/bookingMutation.js"
    click HotelM "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/schemas/mutations/hotelMutations.js"
    click RoomM "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/schemas/mutations/roomMutations.js"
    click UserM "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/schemas/mutations/userMutations.js"
    click PaymentM "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/schemas/mutations/paymentMutation.js"
    click UserModel "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/models/User.js"
    click HotelModel "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/models/Hotel.js"
    click RoomModel "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/models/Room.js"
    click BookingModel "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/server/models/Booking.js"
    click Stripe "https://github.com/debjitpramanick/hotel-booking-web-app/blob/master/client/src/components/Stripe/StripeForm.js"

    %% Styles
    classDef presentation fill:#e0f7fa,stroke:#0277bd,color:#000
    classDef api fill:#e8f5e9,stroke:#2e7d32,color:#000
    classDef data fill:#fff3e0,stroke:#ef6c00,color:#000
    classDef external fill:#f3e5f5,stroke:#6a1b9a,color:#000
```
