# nguyenvuongviet/airbnb architecture

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

- Interactive diagram: https://gitdiagram.com/nguyenvuongviet/airbnb
- Repository: https://github.com/nguyenvuongviet/airbnb

## Overview

##### Project type and purpose
- This is a React-and-TypeScript single-page application (SPA) that mimics an AirBnB-style booking front-end. It’s built with Vite, Tailwind CSS, React Router, Redux Toolkit, and connects to external REST APIs (booking service, weather service, PayPal, etc.). There is no in-repo backend—api.ts is the HTTP client.

##### File structure
- Top level:
- public, index.html – static host and entry point
- src/main.tsx – React app bootstrap
- src/routes, src/pages – page-level components organized by feature (Home, Booking, Payment, Profile, Admin)
- src/components – shared presentational UI components (Loading, AppHeader, AppFooter, etc.)
- src/store – Redux slices per domain (auth, bookings, rooms, comments, weather, etc.)
- src/services/api.ts – Axios (or fetch) wrapper for HTTP calls
- src/models – TypeScript DTO/interface definitions for API responses and domain models
- src/config – dev/prod environment variables and endpoints
- src/hooks – custom React hooks (e.g. ScrollToTop)
- config files: vite.config.ts, tailwind.config.js, tsconfig*.json, eslint.config.js

##### Detail
- Config files feeding into the API client
- How routesConfig maps URL patterns to Pages
- Role of models/interfaces in defining data contracts

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% App Bootstrap
    subgraph "App Bootstrap"
        MB["Main Entry\n(src/main.tsx)"]:::bootstrap
        RC["Root Component\n(src/App.tsx)"]:::bootstrap
    end

    MB -->|renders| RC

    %% Routing Layer
    subgraph "Routing Layer"
        RC --> R1["Router Provider\n(src/routers/index.tsx)"]:::routing
        R1 --> R2["Route Definitions\n(src/routers/routesConfig.ts)"]:::routing
    end

    %% UI Layer
    subgraph "UI Layer"
        subgraph "Pages"
            HP["HomePage"]:::ui
            LR["ListRoomsPage"]:::ui
            DR["DetailRoomPage"]:::ui
            PP["PaymentPage"]:::ui
            PRP["ProfilePage"]:::ui
            AP["AdminPage"]:::ui
            PN["PageNotFound"]:::ui
        end
        subgraph "Shared Components"
            AH["AppHeader"]:::ui
            AF["AppFooter"]:::ui
            LD["Loading"]:::ui
        end
    end

    %% State Management
    subgraph "State Management"
        SM["Store Setup\n(src/store/index.ts)"]:::state
        subgraph "Auth Slices"
            SI["Sign-In Slice"]:::state
            SU["Sign-Up Slice"]:::state
        end
        RS["Rooms Slice"]:::state
        BS["Booking Slice"]:::state
        CS["Comments Slice"]:::state
        WS["Weather Slice"]:::state
        LS["Locations Slice"]:::state
        BRS["BookedRooms Slice"]:::state
        RDS["Room Details Slice"]:::state
        US["User Slice"]:::state
        CCS["Coordinates Slice"]:::state
    end

    %% Service Layer
    subgraph "Service Layer"
        API["API Client\n(src/services/api.ts)"]:::service
    end

    %% Config & Constants
    subgraph "Config & Constants"
        CI["Config Index\n(src/config/index.ts)"]:::config
        CD["Dev Config\n(src/config/dev.ts)"]:::config
        CP["Prod Config\n(src/config/prod.ts)"]:::config
        AC["Amenity Constants\n(src/constants/amenities.tsx)"]:::config
    end

    %% Models & Types
    MT["Models & Types\n(src/models/*.ts)"]:::models

    %% Custom Hooks
    HT["ScrollToTop Hook\n(src/hooks/ScrollToTop.tsx)"]:::hooks

    %% External Services
    subgraph "External Services"
        BE["Backend REST APIs"]:::external
        PPAPI["PayPal API"]:::external
        WAPI["Weather API"]:::external
    end

    %% Relationships
    R2 -->|renders| HP
    R2 -->|renders| LR
    R2 -->|renders| DR
    R2 -->|renders| PP
    R2 -->|renders| PRP
    R2 -->|renders| AP
    R2 -->|renders| PN
    HP -->|uses| AH
    HP -->|uses| AF
    HP -->|uses| LD
    LR -->|uses| AH
    LR -->|uses| AF
    LR -->|uses| LD
    DR -->|uses| AH
    DR -->|uses| AF
    DR -->|uses| LD
    PP -->|uses| AH
    PP -->|uses| AF
    PP -->|uses| LD
    PRP -->|uses| AH
    PRP -->|uses| AF
    PRP -->|uses| LD
    AP -->|uses| AH
    AP -->|uses| AF
    AP -->|uses| LD

    %% UI to State
    HP -->|dispatches| SM
    LR -->|dispatches| SM
    DR -->|dispatches| SM
    PP -->|dispatches| SM
    PRP -->|dispatches| SM
    AP -->|dispatches| SM

    %% State slices link
    SM --> SI
    SM --> SU
    SM --> RS
    SM --> BS
    SM --> CS
    SM --> WS
    SM --> LS
    SM --> BRS
    SM --> RDS
    SM --> US
    SM --> CCS

    %% State to Service
    SI -->|calls| API
    SU -->|calls| API
    RS -->|calls| API
    BS -->|calls| API
    CS -->|calls| API
    WS -->|calls| API
    LS -->|calls| API
    BRS -->|calls| API
    RDS -->|calls| API
    US -->|calls| API
    CCS -->|calls| API

    %% Service to Config & Models
    API -->|reads endpoints| CI
    API -->|reads endpoints| CD
    API -->|reads endpoints| CP
    API -->|uses constants| AC
    API -->|uses models| MT

    %% Service to External
    API -->|HTTP requests| BE
    API -->|HTTP requests| PPAPI
    API -->|HTTP requests| WAPI

    %% UI uses hooks
    HP -->|uses| HT
    LR -->|uses| HT
    DR -->|uses| HT
    PP -->|uses| HT
    PRP -->|uses| HT
    AP -->|uses| HT

    %% Click Events
    click HP "https://github.com/nguyenvuongviet/airbnb/blob/main/src/pages/UserPage/HomePage/index.tsx"
    click LR "https://github.com/nguyenvuongviet/airbnb/blob/main/src/pages/UserPage/ListRoomPage/index.tsx"
    click DR "https://github.com/nguyenvuongviet/airbnb/blob/main/src/pages/UserPage/DetailRoomPage/index.tsx"
    click PP "https://github.com/nguyenvuongviet/airbnb/blob/main/src/pages/UserPage/Payment/index.tsx"
    click PRP "https://github.com/nguyenvuongviet/airbnb/blob/main/src/pages/UserPage/ProfilePage/index.tsx"
    click AP "https://github.com/nguyenvuongviet/airbnb/blob/main/src/pages/AdminPage/index.tsx"
    click PN "https://github.com/nguyenvuongviet/airbnb/blob/main/src/pages/PageNotFound/index.tsx"
    click AH "https://github.com/nguyenvuongviet/airbnb/blob/main/src/pages/UserPage/_components/AppHeader/index.tsx"
    click AF "https://github.com/nguyenvuongviet/airbnb/blob/main/src/pages/UserPage/_components/AppFooter/index.tsx"
    click LD "https://github.com/nguyenvuongviet/airbnb/blob/main/src/components/Loading.tsx"
    click R2 "https://github.com/nguyenvuongviet/airbnb/blob/main/src/routers/routesConfig.ts"
    click R1 "https://github.com/nguyenvuongviet/airbnb/blob/main/src/routers/index.tsx"
    click SM "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/index.ts"
    click SI "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/slices/Auth/sign-in.ts"
    click SU "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/slices/Auth/sign-up.ts"
    click RS "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/slices/rooms.ts"
    click BS "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/slices/booking.ts"
    click CS "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/slices/comments.ts"
    click WS "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/slices/weather.ts"
    click LS "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/slices/locations.ts"
    click BRS "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/slices/bookedRooms.ts"
    click RDS "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/slices/room.ts"
    click US "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/slices/user.ts"
    click CCS "https://github.com/nguyenvuongviet/airbnb/blob/main/src/store/slices/coordinates.ts"
    click API "https://github.com/nguyenvuongviet/airbnb/blob/main/src/services/api.ts"
    click CI "https://github.com/nguyenvuongviet/airbnb/blob/main/src/config/index.ts"
    click CD "https://github.com/nguyenvuongviet/airbnb/blob/main/src/config/dev.ts"
    click CP "https://github.com/nguyenvuongviet/airbnb/blob/main/src/config/prod.ts"
    click AC "https://github.com/nguyenvuongviet/airbnb/blob/main/src/constants/amenities.tsx"
    click MT "https://github.com/nguyenvuongviet/airbnb/tree/main/src/models/"
    click HT "https://github.com/nguyenvuongviet/airbnb/blob/main/src/hooks/ScrollToTop.tsx"
    click MB "https://github.com/nguyenvuongviet/airbnb/blob/main/src/main.tsx"
    click RC "https://github.com/nguyenvuongviet/airbnb/blob/main/src/App.tsx"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000
    classDef routing fill:#87CEEB,stroke:#000
    classDef state fill:#90EE90,stroke:#000
    classDef service fill:#FFA500,stroke:#000
    classDef config fill:#FFDAB9,stroke:#000
    classDef models fill:#E6E6FA,stroke:#000
    classDef hooks fill:#FFFACD,stroke:#000
    classDef external fill:#DDA0DD,stroke:#000
    classDef bootstrap fill:#B0C4DE,stroke:#000
```
