# nguyenvanhuy2005/beachstay-hub architecture

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

- Interactive diagram: https://gitdiagram.com/nguyenvanhuy2005/beachstay-hub
- Repository: https://github.com/nguyenvanhuy2005/beachstay-hub

## Overview

##### Main Components
- Client/Frontend: This is a single-page application (SPA) that includes several subdomains:
- Public-facing pages (e.g., Home, About, Booking, Blog, Room Details).
- Admin dashboard pages (e.g., AdminDashboardPage, AdminLoginPage).
- Shared components like layout (Header, Footer, LanguageSwitcher), booking forms, and UI components.
- API & Integration Layer: The src/api directory (e.g., bookingApi.ts) provides client-side API calls.
- UI Library & Utilities: Extensive custom UI components (in src/components/ui), hooks (src/hooks), contexts (src/contexts), and utilities (src/lib) that structure and enhance the app functionality.
- Backend/Services: The “supabase” folder and src/integrations/supabase indicate:
- Integration with Supabase services for database operations.
- Serverless functions handling operations such as creating image buckets, storage buckets, and sending booking notifications.

##### Detail the Relationships and Interactions
- The client (browser) loads the index.html which bootstraps the frontend, rendering React components defined in the src directory.
- The frontend is organized into pages and components—public pages and admin pages are separated for access control and functionality.
- User interactions (e.g., booking a room) trigger API calls from the src/api layer. The requests eventually engage with Supabase’s backend functions to update the database, manage storage, or send notifications.
- Integration components (src/integrations/supabase) serve as the intermediary between the client-side logic and Supabase’s serverless functions.
- The build process and deployments are managed through Vite and configuration files (like vite.config.ts, tailwind.config.ts), ensuring instant previews and auto-reloading during development.

##### Architectural Patterns
- Component-based Architecture: The React components are neatly organized (e.g., separate folders for admin, booking, home, layout, ui) following a clear separation of concerns.
- Modular and Layered Organization: Distinct directories for APIs, hooks, contexts, and utilities help maintain the project in layers – presentation (components/pages), business logic (contexts/hooks), and integration (API, supabase integrations).
- Serverless Functions: The use of Supabase functions indicates an event-driven architecture for specific backend operations.

##### Relevant Technologies and Their Roles
- Vite: For fast development and hot-module reloading.
- TypeScript & React: Primary technologies for building a robust and maintainable frontend.
- shadcn-ui & Tailwind CSS: For building a consistent, theme-able UI with reusable components.
- Supabase: As the backend-as-a-service providing database, storage, and serverless function capabilities.

1. Presentation Layer: Browser/Client with React application. Include subcomponents like Home, Admin dashboard, Booking page.
2. Logic/API Layer: API calls (bookingApi.ts) and integration with Supabase (src/integrations/supabase and functions).
3. Data/Backend Layer: Supabase database and serverless functions (with specific functions for images and notifications).
- To represent the entry point (index.html / main.tsx) clearly, as well as the central role of routing (src/pages) in segregating user experiences.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Entry["index.html / main.tsx"]:::frontend
        Browser["Browser/Client"]:::frontend
        subgraph "Public Pages"
            Home["Home"]:::frontend
            About["About"]:::frontend
            Booking["Booking"]:::frontend
            Blog["Blog"]:::frontend
            RoomDetail["Room Details"]:::frontend
        end
        subgraph "Admin Section"
            AdminDash["AdminDashboardPage"]:::frontend
            AdminLogin["AdminLoginPage"]:::frontend
            AdminComp["Admin Components"]:::frontend
        end
        subgraph "Shared Layout"
            Header["Header"]:::frontend
            Footer["Footer"]:::frontend
            LanguageSwitcher["LanguageSwitcher"]:::frontend
            MainLayout["MainLayout"]:::frontend
        end
        subgraph "Booking Forms"
            BookingForm["BookingForm"]:::frontend
            QuickBookingForm["QuickBookingForm"]:::frontend
            DateRangePicker["DateRangePicker"]:::frontend
            BookingSummary["BookingSummary"]:::frontend
            RoomSearchFilter["RoomSearchFilter"]:::frontend
        end
        subgraph "UI Library"
            UIComponents["UI Components"]:::frontend
        end
    end

    %% API & Integration Layer
    subgraph "API & Integration Layer"
        API["bookingApi"]:::api
        subgraph "Application Logic"
            Hooks["Hooks"]:::api
            Contexts["Contexts"]:::api
        end
        Utilities["Utilities"]:::api
    end

    %% Backend / Supabase
    subgraph "Backend / Supabase"
        SupabaseIntegration["Supabase Integration"]:::backend
        subgraph "Serverless Functions"
            CreateImage["Create Image Bucket"]:::backend
            CreateStorage["Create Storage Buckets"]:::backend
            SendNotification["Send Booking Notification"]:::backend
        end
    end

    %% Connections within Presentation Layer
    Entry --> Browser
    Browser --> Home
    Browser --> About
    Browser --> Booking
    Browser --> Blog
    Browser --> RoomDetail
    Browser --> AdminDash
    Browser --> AdminLogin
    Browser --> Header
    Browser --> BookingForm
    Header --- Footer
    %% Connections from Presentation to API Layer
    Home -->|"fetch_data"| API
    BookingForm -->|"submit_booking"| API
    AdminDash -->|"admin_call"| API
    UIComponents -->|"ui_events"| API

    %% Connections from Application Logic to API Layer
    Hooks --> API
    Contexts --> API
    Utilities --> API

    %% Connections from API Layer to Backend
    API -->|"data_request"| SupabaseIntegration
    API -->|"trigger_function"| CreateImage
    API -->|"trigger_function"| CreateStorage
    API -->|"trigger_function"| SendNotification

    %% Click Events for Presentation Layer
    click Home "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/pages/Index.tsx"
    click About "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/pages/AboutPage.tsx"
    click Booking "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/pages/BookingPage.tsx"
    click Blog "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/pages/BlogPage.tsx"
    click RoomDetail "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/pages/RoomDetailPage.tsx"
    click AdminDash "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/pages/AdminDashboardPage.tsx"
    click AdminLogin "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/pages/AdminLoginPage.tsx"
    click AdminComp "https://github.com/nguyenvanhuy2005/beachstay-hub/tree/main/src/components/admin"
    click Header "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/components/layout/Header.tsx"
    click Footer "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/components/layout/Footer.tsx"
    click LanguageSwitcher "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/components/layout/LanguageSwitcher.tsx"
    click MainLayout "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/components/layout/MainLayout.tsx"
    click BookingForm "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/components/booking/BookingForm.tsx"
    click QuickBookingForm "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/components/booking/QuickBookingForm.tsx"
    click DateRangePicker "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/components/booking/DateRangePicker.tsx"
    click BookingSummary "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/components/booking/BookingSummary.tsx"
    click RoomSearchFilter "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/components/booking/RoomSearchFilter.tsx"
    click UIComponents "https://github.com/nguyenvanhuy2005/beachstay-hub/tree/main/src/components/ui"

    %% Click Events for API & Integration Layer
    click API "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/api/bookingApi.ts"
    click Hooks "https://github.com/nguyenvanhuy2005/beachstay-hub/tree/main/src/hooks"
    click Contexts "https://github.com/nguyenvanhuy2005/beachstay-hub/tree/main/src/contexts"
    click Utilities "https://github.com/nguyenvanhuy2005/beachstay-hub/tree/main/src/lib"

    %% Click Events for Backend / Supabase
    click SupabaseIntegration "https://github.com/nguyenvanhuy2005/beachstay-hub/blob/main/src/integrations/supabase/client.ts"
    click CreateImage "https://github.com/nguyenvanhuy2005/beachstay-hub/tree/main/supabase/functions/create-image-bucket"
    click CreateStorage "https://github.com/nguyenvanhuy2005/beachstay-hub/tree/main/supabase/functions/create-storage-buckets"
    click SendNotification "https://github.com/nguyenvanhuy2005/beachstay-hub/tree/main/supabase/functions/send-booking-notification"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef api fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef backend fill:#ffcc99,stroke:#000,stroke-width:2px;
```
