# rajat1120/airbnb-clone architecture

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

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

## Overview

##### Project type and purpose
- This is a full-stack web application: an Airbnb clone built with React on the frontend and Supabase on the backend.
- Purpose: let users search listings, authenticate (Google Sign-In), save favorites, book trips (payments via Stripe), and view data with infinite scroll and real-time sync.

##### File structure
- Top-level dirs:
- src: React entrypoint, components, hooks, Redux slices, API wrappers, styles.
- public & dist: static assets, HTML, manifest, robots.txt.
- supabase: edge functions (create-payment-intent), config.toml, seed.sql.
- config files: vite.config.js, tailwind.config.js, postcss.config.js, vercel.json.
- Patterns & layers:
- UI components (src/components) follow feature areas (Header, Footer, House-detail, Main, Modals).
- State management in src/redux (slices, store).
- Data fetching & caching via TanStack Query wrappers under src/api and src/payment.
- Supabase functions implement backend logic (payments).
- Deployment: Vite for build, Vercel for hosting, shell script for local run (run-react-app.sh).

##### README for additional insights
- Core features: authentication, search, infinite scroll listings, favorites, bookings.
- Tech stack reinforces layers: React Router, Redux Toolkit, React Query, Tailwind, Supabase (PostgreSQL + Auth), Stripe, Google OAuth, redux-state-sync for cross-tab sync.

a. Main components
- Client (Browser) – React SPA
- CDN/Static Host – serves index.html, JS/CSS bundles (Vercel or similar)
- API Layer – calls to Supabase client SDK + custom edge functions
- Authentication Service – Supabase Auth with Google OAuth
- Database – Supabase PostgreSQL
- Payment Processor – Stripe via Supabase edge function “create-payment-intent”
- State Management – Redux + redux-state-sync
- Data Fetching – TanStack Query
- External Services – Google OAuth, Stripe
b. Relationships & data flows
1. User → Browser UI → React Router → Component
2. UI dispatches Redux actions or triggers React Query hooks
3. React Query / Supabase client → Supabase Auth / REST endpoints → Database
4. Booking flow: UI → Supabase edge function (create-payment-intent) → Stripe → webhook → update DB
5. redux-state-sync synchronizes store across open tabs
c. Architectural patterns & design principles
- Separation of concerns: UI vs. state vs. data-fetching vs. backend logic
- Feature-based folder structure for components
- Centralized state (Redux) with slice per domain (App, Card, HouseDetail, mainForm)
- Serverless functions for secure operations (payments)
- CDN for static asset delivery, global performance
d. Key technologies & their roles
- React & React Router – SPA navigation & UI
- Redux Toolkit – global state & actions
- TanStack Query – caching & background refetch
- Supabase SDK – built-in auth & DB client
- Supabase Edge Functions – secure serverless endpoints
- Stripe – payment processing
- Tailwind – utility-first styling
- Vite – dev server & bundler
- Vercel – hosting & CDN

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Browser (Client)"
    direction TB
    Browser["React SPA<br/>src/index.jsx, src/App.jsx"]:::frontend
    Router["React Router"]:::frontend
    Components["UI Components"]:::frontend
    Redux["Redux Toolkit<br/>Store & Slices"]:::state
    click Redux "https://github.com/rajat1120/airbnb-clone/blob/main/src/redux/Store.jsx"
    click Redux "https://github.com/rajat1120/airbnb-clone/blob/main/src/redux/AppSlice.jsx"
    click Redux "https://github.com/rajat1120/airbnb-clone/blob/main/src/redux/CardSlice.jsx"
    click Redux "https://github.com/rajat1120/airbnb-clone/blob/main/src/redux/HouseDetailSlice.jsx"
    click Redux "https://github.com/rajat1120/airbnb-clone/blob/main/src/redux/mainFormSlice.jsx"
    Query["TanStack Query"]:::state
  end

  CDN["CDN / Static Host<br/>dist/, public/"]:::doc
  click CDN "https://github.com/rajat1120/airbnb-clone/tree/main/dist/"
  click CDN "https://github.com/rajat1120/airbnb-clone/tree/main/public/"

  subgraph "API Layer (Supabase SDK)"
    direction TB
    SupabaseSDK["Supabase SDK wrappers"]:::api
    click SupabaseSDK "https://github.com/rajat1120/airbnb-clone/blob/main/src/api/Supabase.jsx"
    AuthAPI["Authentication API"]:::api
    click AuthAPI "https://github.com/rajat1120/airbnb-clone/blob/main/src/api/apiAuthentication.jsx"
    RoomsAPI["Rooms API"]:::api
    click RoomsAPI "https://github.com/rajat1120/airbnb-clone/blob/main/src/api/apiRooms.jsx"
  end

  subgraph "Payments Client"
    direction TB
    BookingHandlers["BookingHandlers.jsx"]:::api
    click BookingHandlers "https://github.com/rajat1120/airbnb-clone/blob/main/src/payment/BookingHandlers.jsx"
    BookingQueries["BookingQueries.jsx"]:::api
    click BookingQueries "https://github.com/rajat1120/airbnb-clone/blob/main/src/payment/BookingQueries.jsx"
    CheckoutForm["CheckoutForm.jsx"]:::api
    click CheckoutForm "https://github.com/rajat1120/airbnb-clone/blob/main/src/payment/CheckoutForm.jsx"
    UpdatePaymentForm["UpdatePaymentForm.jsx"]:::api
    click UpdatePaymentForm "https://github.com/rajat1120/airbnb-clone/blob/main/src/payment/UpdatePaymentForm.jsx"
  end

  subgraph "Backend (Supabase)"
    direction TB
    EdgeFn["create-payment-intent (Edge Function)"]:::backend
    click EdgeFn "https://github.com/rajat1120/airbnb-clone/blob/main/supabase/functions/create-payment-intent/index.ts"
    Config["supabase/config.toml"]:::backend
    click Config "https://github.com/rajat1120/airbnb-clone/blob/main/supabase/config.toml"
    DB["PostgreSQL"]:::db
    click DB "https://github.com/rajat1120/airbnb-clone/blob/main/supabase/seed.sql"
  end

  Stripe["Stripe"]:::external
  Google["Google OAuth"]:::external

  CDN -->|serves| Browser
  Browser -->|navigate| Router
  Browser -->|render| Components
  Components -->|dispatch| Redux
  Components -->|useQuery| Query
  Redux -->|state| Components
  Query -->|fetch| SupabaseSDK
  SupabaseSDK -->|auth calls| AuthAPI
  AuthAPI -->|OAuth| Google
  SupabaseSDK -->|data calls| RoomsAPI
  Components -->|booking actions| BookingHandlers
  BookingHandlers -->|invoke| EdgeFn
  EdgeFn -->|create intent| Stripe
  Stripe -->|webhook| EdgeFn
  EdgeFn -->|update| DB
  SupabaseSDK -->|read/write| DB

  classDef frontend fill:#cce5ff,stroke:#004085,color:#004085,stroke-width:1px;
  classDef state fill:#d4edda,stroke:#155724,color:#155724,stroke-width:1px;
  classDef api fill:#d1ecf1,stroke:#0c5460,color:#0c5460,stroke-width:1px;
  classDef backend fill:#fff3cd,stroke:#856404,color:#856404,stroke-width:1px;
  classDef db fill:#f5c6cb,stroke:#721c24,color:#721c24,stroke-width:1px;
  classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d,stroke-width:1px;
  classDef doc fill:#e2e3e5,stroke:#6c757d,color:#6c757d,stroke-width:1px;
```
