# leeeee001/hotel-room_booking_api architecture

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

- Interactive diagram: https://gitdiagram.com/leeeee001/hotel-room_booking_api
- Repository: https://github.com/leeeee001/hotel-room_booking_api

## Overview

##### Project type and purpose
- It’s a backend-only RESTful API for hotel room booking.
- Built with Node.js/Express, MongoDB (Mongoose), JWT for auth, and Stripe for payments.
- Users search rooms, create/cancel bookings, and pay via Stripe.

##### File structure
- server.js – entry point that wires up Express, middleware, routes.
- config/db.js – database connection to MongoDB.
- middleware/auth.js – JWT authentication/authorization.
- routes/*.js – Express routers for users, rooms, bookings, payments.
- controllers/*.controller.js – business logic per entity (CRUD, booking logic, Stripe calls).
- models/*.model.js – Mongoose schemas: Users, Hotels, Rooms, RoomAvailability, Bookings, Payments.

##### Main components
a. Client (frontend or API consumer)
b. API Server (Express application)
– HTTP routing layer
– Auth middleware (JWT)
– Controllers/Services layer
c. MongoDB (with collections for users, hotels, rooms, availabilities, bookings, payments)
d. External Service: Stripe API

##### Relationships and data flows
1. Client → HTTP request to Express routes
2. Route handler → auth middleware (if protected) → Controller
3. Controller → business logic:
- Reads/writes via Mongoose models → MongoDB
- For payments: calls Stripe REST API, then persists payment result in MongoDB
4. Controller returns JSON response → Client

##### Architectural patterns and design principles
- Layered MVC-style separation: Routes → Controllers → Models
- Modular and scalable: each controller and route handles one resource
- Stateless REST API with JWT auth (middleware enforces security)
- External integration as a separate service boundary (Stripe)
- Database encapsulation via Mongoose ODM

##### Technologies & frameworks to annotate
- Express.js (HTTP server & routing)
- Mongoose ODM (MongoDB access)
- JSON Web Tokens (authentication/authorization)
- Stripe API (payments)

- Notes on key interactions (e.g., “POST /bookings → invokes room availability logic”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef code fill:#D0E1FF,stroke:#000,color:#000;
    classDef db fill:#D0F0C0,stroke:#000,color:#000;
    classDef external fill:#FFD8A8,stroke:#000,color:#000;

    Client["Client\n(Browser/App)"]:::external

    subgraph "API Server"
        direction TB
        entry["server.js"]:::code
        routing["User Routes\n(routes/userRoute.js)"]:::code
        auth["Auth Middleware\n(middleware/auth.js)"]:::code
        userCtrl["User Controller\n(controllers/user.controller.js)"]:::code
        roomCtrl["Room Controller\n(controllers/room.controller.js)"]:::code
        bookingCtrl["Booking Controller\n(controllers/booking.controller.js)"]:::code
        paymentCtrl["Payment Controller\n(controllers/payment.controller.js)"]:::code
        dbConfig["DB Config\n(config/db.js)"]:::code
    end

    mongodb["MongoDB\n(Collections: Users, Hotels, Rooms, Availability, Bookings, Payments)"]:::db

    stripe["Stripe API"]:::external

    Client -->|"HTTP Request"| entry
    entry -->|"Route to User Routes"| routing
    routing -->|"Authenticate (JWT)"| auth
    auth -->|"Invoke Controller"| userCtrl
    auth --> userCtrl
    auth --> roomCtrl
    auth --> bookingCtrl
    auth --> paymentCtrl

    userCtrl -->|"CRUD via Mongoose"| dbConfig
    roomCtrl --> dbConfig
    bookingCtrl --> dbConfig
    paymentCtrl --> dbConfig

    dbConfig -->|"MongoDB Connection"| mongodb

    paymentCtrl -->|"Stripe Charge"| stripe
    stripe -->|"Payment Result"| paymentCtrl

    userCtrl -->|"JSON Response"| Client
    roomCtrl --> Client
    bookingCtrl --> Client
    paymentCtrl --> Client

    click entry "https://github.com/leeeee001/hotel-room_booking_api/blob/main/server.js"
    click routing "https://github.com/leeeee001/hotel-room_booking_api/blob/main/routes/userRoute.js"
    click auth "https://github.com/leeeee001/hotel-room_booking_api/blob/main/middleware/auth.js"
    click userCtrl "https://github.com/leeeee001/hotel-room_booking_api/blob/main/controllers/user.controller.js"
    click roomCtrl "https://github.com/leeeee001/hotel-room_booking_api/blob/main/controllers/room.controller.js"
    click bookingCtrl "https://github.com/leeeee001/hotel-room_booking_api/blob/main/controllers/booking.controller.js"
    click paymentCtrl "https://github.com/leeeee001/hotel-room_booking_api/blob/main/controllers/payment.controller.js"
    click dbConfig "https://github.com/leeeee001/hotel-room_booking_api/blob/main/config/db.js"
    click mongodb "https://github.com/leeeee001/hotel-room_booking_api/blob/main/models/users.model.js"
    click mongodb "https://github.com/leeeee001/hotel-room_booking_api/blob/main/models/hotels.model.js"
    click mongodb "https://github.com/leeeee001/hotel-room_booking_api/blob/main/models/rooms.model.js"
    click mongodb "https://github.com/leeeee001/hotel-room_booking_api/blob/main/models/roomAvailability.model.js"
    click mongodb "https://github.com/leeeee001/hotel-room_booking_api/blob/main/models/booking.model.js"
    click mongodb "https://github.com/leeeee001/hotel-room_booking_api/blob/main/models/payment.model.js"
```
