# dyancheng/web4in1-s5- architecture

> Architecture diagram of the GitHub repository dyancheng/web4in1-s5-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dyancheng/web4in1-s5-
- Repository: https://github.com/dyancheng/web4in1-s5-

## Overview

1. **Overall shape**
   This is a three-service travel/booking platform: a **Next.js frontend**, an **ASP.NET Core Web API backend**, and a **Python FastAPI AI service**, with **Supabase/PostgreSQL** as the main data store. The backend is the core application boundary; the frontend is mostly presentation and client state; the AI service is a separate auxiliary service.

2. **Frontend subsystem**
   The `frontend/` app is a Next.js 13+ style route-based UI (`src/app/...`) that covers the main customer flows: hotels, tours, flights, buses/vehicles, cart, checkout, payment, login/register, favorites, and role-specific dashboards such as admin, employee, accountant, and hotel-owner. This strongly suggests one unified web client serving both end users and internal staff.

3. **Frontend state and API integration**
   The frontend uses React context for cross-cutting state: `AuthContext`, `CartContext`, and `ThemeContext`. It also has small client-side storage/API helper modules in `src/lib/` for backend URL resolution, checkout, hotel storage, and tour storage, which implies the UI talks to the backend for transactions while also keeping some transient selections locally.

4. **Backend subsystem**
   The `backend/` project is the central business layer. It exposes domain controllers for `Auth`, `Bookings`, `Bus`, `Discount`, `HotelBookings`, `Hotels`, `Orders`, `Payments`, `Rooms`, and `Tours`. That split indicates the backend is organized by business capability rather than by technical layer.

5. **Backend service layer**
   The backend’s `Services/` folder contains the real orchestration and persistence logic: `CheckoutService`, `DataStoreService`, domain DB services for auth/hotels/tours/payments, `BusService`, `DiscountService`, `EmailService`, `GoogleAuthService`, and `SePayService`. This points to a service-oriented API design where controllers are thin and business rules/payment/auth flows are centralized in services.

6. **Data and persistence boundary**
   Supabase/PostgreSQL is the main persistence boundary. The presence of SQL setup files (`schema.sql`, `schema-payments.sql`, `setup_hotel_bookings.sql`, `update_rpcs.sql`, seed scripts) suggests the backend relies on explicit database schema management and probably some PostgreSQL RPC/functions in addition to normal CRUD. The architecture therefore includes a clear application-to-database boundary with database-level features used for parts of the workflow.

7. **Identity and external integrations**
   Authentication is not purely local: there is `GoogleAuthService`, and the readme calls out Supabase keys and URL configuration. Payments are also externalized via `SePayService`, and `EmailService` indicates transactional notifications are part of the backend workflow. These integrations are likely invoked from checkout/payment-related endpoints.

8. **Domain model boundaries**
   The model layer includes `User`, `Booking`, `Hotel`, `Room`, `Tour`, `BusTrip`, `BusBooking`, and `HotelBooking`, which maps closely to the major business entities in the UI and controllers. This suggests the system is built around travel inventory plus reservation/order management, with separate booking concepts per product type.

9. **AI service boundary**
   `ai_service/` is a separate FastAPI app with its own container and Python dependencies. The repo doesn’t show mature AI logic yet, but the existence of `Chatbot.tsx` on the frontend and a dedicated service implies AI features are isolated from the main backend, likely as a standalone API that the frontend can call independently.

10. **Runtime and deployment model**
   The repository is designed for containerized local development with Docker Compose, exposing the frontend on `3000`, backend on `5000`, and AI service on `8000`. The readme also frames the frontend for Vercel deployment, which means the frontend can be deployed separately while still depending on the backend API and Supabase.

11. **Operational tooling and environment**
   Environment configuration is centralized through `.env` and `.env.example`, with CI defined in GitHub Actions and container build files per service. This indicates the repository is meant to be deployed as independently built services, not as a single monolith.

12. **How data likely flows**
   The usual request path is: user interacts with the Next.js app → frontend calls the ASP.NET API for auth, inventory, booking, checkout, payment, or profile actions → backend reads/writes Supabase/PostgreSQL and triggers integrations like email, Google auth, or SePay → frontend reflects the result in the relevant page or dashboard. The AI service is an optional parallel path for chatbot/AI requests rather than part of the core transaction flow.

Main entry points: [`backend/Program.cs`](https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Program.cs) (API layer), [`backend/Services`](https://github.com/dyancheng/web4in1-s5-/tree/main/backend/Services) (Service layer), [`frontend/src/app`](https://github.com/dyancheng/web4in1-s5-/tree/main/frontend/src/app) (Web app), [`docker-compose.yml`](https://github.com/dyancheng/web4in1-s5-/blob/main/docker-compose.yml) (Compose stack)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["Web app<br/>Next.js UI"]
  node_frontend_auth["Auth state<br/>React context<br/>[AuthContext.tsx]"]
  node_frontend_cart["Cart state<br/>React context<br/>[CartContext.tsx]"]
  node_frontend_theme["Theme state<br/>React context<br/>[ThemeContext.tsx]"]
  node_frontend_api["API helpers<br/>client libs"]
  node_frontend_chatbot["Chatbot UI<br/>client component<br/>[Chatbot.tsx]"]
end

subgraph group_backend["Backend"]
  node_backend_api["API layer<br/>ASP.NET Core<br/>[Program.cs]"]
  node_backend_auth["Auth API<br/>controller<br/>[AuthController.cs]"]
  node_backend_booking["Booking API<br/>controller"]
  node_backend_inventory["Inventory APIs<br/>controllers"]
  node_backend_payment["Payment API<br/>controller"]
  node_backend_services["Service layer<br/>orchestration"]
  node_backend_datastore[("Data store<br/>persistence services")]
  node_backend_models["Domain models<br/>entities"]
end

subgraph group_ai["AI Service"]
  node_ai_api["FastAPI app<br/>Python API<br/>[main.py]"]
end

subgraph group_data["Data"]
  node_backend_sql["Schema scripts<br/>SQL setup<br/>[schema.sql]"]
  node_backend_supabase[("Supabase/Postgres<br/>database")]
end

node_docker_stack{{"Compose stack<br/>deployment<br/>[docker-compose.yml]"}}

node_frontend_app -->|"uses"| node_frontend_auth
node_frontend_app -->|"uses"| node_frontend_cart
node_frontend_app -->|"uses"| node_frontend_theme
node_frontend_app -->|"calls"| node_frontend_api
node_frontend_app -->|"HTTP"| node_backend_api
node_frontend_chatbot -->|"HTTP"| node_ai_api
node_backend_api -->|"routes"| node_backend_auth
node_backend_api -->|"routes"| node_backend_booking
node_backend_api -->|"routes"| node_backend_inventory
node_backend_api -->|"routes"| node_backend_payment
node_backend_api -->|"orchestrates"| node_backend_services
node_backend_services -->|"reads/writes"| node_backend_datastore
node_backend_services -->|"uses"| node_backend_models
node_backend_datastore -->|"persists"| node_backend_supabase
node_backend_sql -->|"defines"| node_backend_supabase
node_backend_services -.->|"depends on"| node_backend_sql
node_backend_services -->|"integrates"| node_backend_payment
node_backend_services -->|"integrates"| node_backend_auth
node_docker_stack -->|"runs"| node_frontend_app
node_docker_stack -->|"runs"| node_backend_api
node_docker_stack -->|"runs"| node_ai_api

click node_frontend_app "https://github.com/dyancheng/web4in1-s5-/tree/main/frontend/src/app"
click node_frontend_auth "https://github.com/dyancheng/web4in1-s5-/blob/main/frontend/src/contexts/AuthContext.tsx"
click node_frontend_cart "https://github.com/dyancheng/web4in1-s5-/blob/main/frontend/src/contexts/CartContext.tsx"
click node_frontend_theme "https://github.com/dyancheng/web4in1-s5-/blob/main/frontend/src/contexts/ThemeContext.tsx"
click node_frontend_api "https://github.com/dyancheng/web4in1-s5-/tree/main/frontend/src/lib"
click node_frontend_chatbot "https://github.com/dyancheng/web4in1-s5-/blob/main/frontend/src/components/Chatbot.tsx"
click node_backend_api "https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Program.cs"
click node_backend_auth "https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Controllers/AuthController.cs"
click node_backend_booking "https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Controllers/BookingsController.cs"
click node_backend_inventory "https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Controllers/HotelsController.cs"
click node_backend_payment "https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Controllers/PaymentsController.cs"
click node_backend_services "https://github.com/dyancheng/web4in1-s5-/tree/main/backend/Services"
click node_backend_datastore "https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Services/DataStoreService.cs"
click node_backend_models "https://github.com/dyancheng/web4in1-s5-/tree/main/backend/Models"
click node_backend_sql "https://github.com/dyancheng/web4in1-s5-/blob/main/backend/schema.sql"
click node_ai_api "https://github.com/dyancheng/web4in1-s5-/blob/main/ai_service/main.py"
click node_docker_stack "https://github.com/dyancheng/web4in1-s5-/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_app,node_frontend_auth,node_frontend_cart,node_frontend_theme,node_frontend_api,node_frontend_chatbot toneBlue
class node_backend_api,node_backend_auth,node_backend_booking,node_backend_inventory,node_backend_payment,node_backend_services,node_backend_datastore,node_backend_models toneAmber
class node_ai_api toneMint
class node_backend_sql,node_backend_supabase toneRose
class node_docker_stack toneNeutral
```

## Components

### Frontend

Next.js customer and staff UI

- [Web app](https://github.com/dyancheng/web4in1-s5-/tree/main/frontend/src/app): Next.js UI · Route-based customer and staff interface · `frontend/src/app`
- [Auth state](https://github.com/dyancheng/web4in1-s5-/blob/main/frontend/src/contexts/AuthContext.tsx): React context · Session and sign-in state across the UI · `frontend/src/contexts/AuthContext.tsx`
- [Cart state](https://github.com/dyancheng/web4in1-s5-/blob/main/frontend/src/contexts/CartContext.tsx): React context · Shared cart and checkout selections · `frontend/src/contexts/CartContext.tsx`
- [Theme state](https://github.com/dyancheng/web4in1-s5-/blob/main/frontend/src/contexts/ThemeContext.tsx): React context · UI theme toggling and persistence · `frontend/src/contexts/ThemeContext.tsx`
- [API helpers](https://github.com/dyancheng/web4in1-s5-/tree/main/frontend/src/lib): client libs · Backend URL, checkout, hotel, and tour helpers · `frontend/src/lib`
- [Chatbot UI](https://github.com/dyancheng/web4in1-s5-/blob/main/frontend/src/components/Chatbot.tsx): client component · Frontend entry point for AI-assisted conversations · `frontend/src/components/Chatbot.tsx`

### Backend

ASP.NET Core business API and persistence services

- [API layer](https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Program.cs): ASP.NET Core · Main application boundary exposing business endpoints · `backend/Program.cs`
- [Auth API](https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Controllers/AuthController.cs): controller · Login, registration, and identity flows · `backend/Controllers/AuthController.cs`
- [Booking API](https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Controllers/BookingsController.cs): controller · Core reservation and order workflows · `backend/Controllers/BookingsController.cs`
- [Inventory APIs](https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Controllers/HotelsController.cs): controllers · Hotels, rooms, tours, buses, and hotel bookings · `backend/Controllers/HotelsController.cs`
- [Payment API](https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Controllers/PaymentsController.cs): controller · Payment and payment-status endpoints · `backend/Controllers/PaymentsController.cs`
- [Service layer](https://github.com/dyancheng/web4in1-s5-/tree/main/backend/Services): orchestration · Business rules, checkout, auth, email, and gateway integrations · `backend/Services`
- [Data store](https://github.com/dyancheng/web4in1-s5-/blob/main/backend/Services/DataStoreService.cs): persistence services · Database access for auth, hotels, tours, payments, and generic storage · `backend/Services/DataStoreService.cs`
- [Domain models](https://github.com/dyancheng/web4in1-s5-/tree/main/backend/Models): entities · User, booking, hotel, room, tour, and bus booking objects · `backend/Models`

### AI Service

Standalone FastAPI chatbot service

- [FastAPI app](https://github.com/dyancheng/web4in1-s5-/blob/main/ai_service/main.py): Python API · Standalone AI service for chatbot-style requests · `ai_service/main.py`

### Data

Supabase/PostgreSQL schema and scripts

- [Schema scripts](https://github.com/dyancheng/web4in1-s5-/blob/main/backend/schema.sql): SQL setup · Database schema, seeds, and RPC updates · `backend/schema.sql`
- **Supabase/Postgres**: database · Primary persistence boundary and RPC-backed workflows

### Other components

- [Compose stack](https://github.com/dyancheng/web4in1-s5-/blob/main/docker-compose.yml): deployment · Local multi-service runtime for frontend, backend, and AI · `docker-compose.yml`

## Connections

- Web app → Auth state: uses · UI reads auth/session state
- Web app → Cart state: uses · UI shares cart and checkout state
- Web app → Theme state: uses · UI applies theme state
- Web app → API helpers: calls · Pages call backend-facing helpers
- Web app → API layer: HTTP · Customer and staff screens call the main API
- Chatbot UI → FastAPI app: HTTP · Chatbot component talks to the AI service
- API layer → Auth API: routes · Auth endpoints are exposed through controllers
- API layer → Booking API: routes · Booking and order workflows are exposed through controllers
- API layer → Inventory APIs: routes · Inventory and product controllers
- API layer → Payment API: routes · Payment-related endpoints
- API layer → Service layer: orchestrates · Controllers delegate business logic to services
- Service layer → Data store: reads/writes · Services persist and load business data
- Service layer → Domain models: uses · Services operate on domain entities
- Data store → Supabase/Postgres: persists · Database access targets Supabase/PostgreSQL
- Schema scripts → Supabase/Postgres: defines · Schema and seed scripts shape the database
- Service layer → Schema scripts: depends on · Service behavior assumes schema and RPC setup
- Service layer → Payment API: integrates · Payment flows connect to external gateways and receipts
- Service layer → Auth API: integrates · Auth services include local and Google sign-in
- Compose stack → Web app: runs · Containerized frontend service
- Compose stack → API layer: runs · Containerized backend service
- Compose stack → FastAPI app: runs · Containerized AI service
