# haddybhaiya/countryside architecture

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

- Interactive diagram: https://gitdiagram.com/haddybhaiya/countryside
- Repository: https://github.com/haddybhaiya/countryside

## Overview

#### Purpose and Runtime
Countryside is a full-stack rural-hospitality property marketplace and booking system. It serves customer discovery/checkout, host property operations, and administrator analytics under role-based access control. The primary runtime is a React 18/TypeScript Vite SPA in `frontend/src/main.tsx`, deployed with Vercel configuration in `frontend/vercel.json`.

#### Application Composition and Entry Points
`frontend/src/App.tsx` composes the application experience, while page-level route targets live in `frontend/src/pages/`. Public flows include landing, exploration, property detail, checkout, confirmation, and trips; protected workspace flows include host and admin dashboards. Route guards in `frontend/src/routes/ProtectedRoute.tsx` and `frontend/src/routes/GuestRoute.tsx` establish authentication boundaries.

#### Identity, Roles, and Shared State
Authentication and user/session state are centralized through `frontend/src/context/AuthContext.tsx`, with application-wide state in `frontend/src/context/AppContext.tsx`. Client-side RBAC logic is defined in `frontend/src/lib/rbac.ts`; it separates customer, host, and admin capabilities before users reach role-specific pages such as `frontend/src/pages/HostDashboardPage.tsx` and `frontend/src/pages/AdminPage.tsx`.

#### Property Discovery and Host Management
Customers browse and inspect inventory through `frontend/src/components/ExploreView.tsx` and `frontend/src/components/DetailView.tsx`. Hosts manage inventory through `frontend/src/components/AdminPropertyManagement.tsx` and the host dashboard page. Property operations are isolated behind `frontend/src/services/property.service.ts`, which communicates with the InsForge/Supabase-compatible client in `frontend/src/lib/insforge.ts`. Persistent property schema and ownership/RLS changes are captured in `migrations/20260711165801_properties-schema.sql` and `migrations/20260713000001_host-property-rls.sql`.

#### Booking and Payment Flow
Checkout starts in `frontend/src/pages/CheckoutPage.tsx` / `frontend/src/components/CheckoutView.tsx`, where pricing and availability are converted into booking operations through `frontend/src/services/booking.service.ts`. Booking persistence and conflict-control constraints belong to `migrations/20260712162218_bookings-schema.sql`. Stripe payment handling crosses a trust boundary: the browser uses Stripe configuration, while webhook verification/finalization is handled by the serverless endpoint `functions/stripe-webhook/index.ts`. A mock checkout path exists at `frontend/src/pages/StripeMockCheckout.tsx`; successful completion routes to `frontend/src/pages/ConfirmationPage.tsx`.

#### Admin Operations and Analytics
Administrative controls are composed in `frontend/src/components/AdminConsole.tsx`, with user/property operations in `frontend/src/components/AdminUserManagement.tsx` and `frontend/src/components/AdminPropertyManagement.tsx`. Analytics data is aggregated for dashboard visualizations through `frontend/src/hooks/useAdminAnalytics.ts`, rendered by `frontend/src/components/admin/AdminDashboardOverview.tsx` and `frontend/src/components/admin/AdminDetailedAnalytics.tsx`, and exportable via `frontend/src/utils/exportCsv.ts`.

#### Backend, Data, and Delivery Boundaries
InsForge provides PostgreSQL, Auth, and Storage behind the Supabase-compatible client. Database evolution is SQL-migration driven, including profile/role setup in `migrations/20260712170713_profiles-schema.sql` and role-policy fixes in `migrations/20260713000002_fix-rls-roles.sql`. Stripe is the external payment service; Vercel hosts the frontend and serverless webhook. CI is defined in `.github/workflows/ci.yml`.

Main entry points: [`frontend/src/App.tsx`](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/App.tsx) (App and routes), [`frontend/src/lib/insforge.ts`](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/lib/insforge.ts) (InsForge client), [`frontend/src/routes/ProtectedRoute.tsx`](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/routes/ProtectedRoute.tsx) (Route guards), [`frontend/src/pages/CheckoutPage.tsx`](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/pages/CheckoutPage.tsx) (Checkout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React SPA"]
  node_entry["SPA entry<br/>React entry<br/>[main.tsx]"]
  node_app["App and routes<br/>route composition<br/>[App.tsx]"]
  node_route_guards["Route guards<br/>auth boundary<br/>[ProtectedRoute.tsx]"]
  node_auth_state["Auth session<br/>context<br/>[AuthContext.tsx]"]
  node_rbac["Role capabilities<br/>RBAC policy<br/>[rbac.ts]"]
  node_discovery["Property discovery<br/>customer views<br/>[ExploreView.tsx]"]
  node_checkout["Checkout<br/>booking UI<br/>[CheckoutPage.tsx]"]
  node_host_ops["Host property operations<br/>host workspace"]
  node_admin_console["Admin operations<br/>admin workspace<br/>[AdminConsole.tsx]"]
  node_analytics["Admin analytics<br/>analytics hook"]
end

subgraph group_services["Application Services"]
  node_booking_service["Booking service<br/>domain service<br/>[booking.service.ts]"]
  node_property_service["Property service<br/>domain service"]
  node_insforge_client{{"InsForge client<br/>Supabase client<br/>[insforge.ts]"}}
end

subgraph group_platform["Platform &amp; Delivery"]
  node_insforge[("InsForge<br/>managed backend")]
  node_property_schema["Property schema and RLS<br/>SQL migrations"]
  node_booking_schema["Booking constraints<br/>SQL migration"]
  node_profile_roles["Profiles and role policies<br/>SQL migrations"]
  node_stripe{{"Stripe<br/>payment provider"}}
  node_webhook["Stripe webhook<br/>serverless endpoint<br/>[index.ts]"]
  node_vercel{{"Vercel deployment<br/>hosting platform<br/>[vercel.json]"}}
  node_ci["CI pipeline<br/>GitHub Actions<br/>[ci.yml]"]
end

node_entry -->|"mounts"| node_app
node_app -->|"applies"| node_route_guards
node_route_guards -->|"reads session"| node_auth_state
node_route_guards -->|"enforces roles"| node_rbac
node_app -->|"public routes"| node_discovery
node_app -->|"checkout route"| node_checkout
node_app -->|"host route"| node_host_ops
node_app -->|"admin route"| node_admin_console
node_discovery -->|"loads inventory"| node_property_service
node_host_ops -->|"manages inventory"| node_property_service
node_checkout -->|"creates booking"| node_booking_service
node_admin_console -->|"shows metrics"| node_analytics
node_property_service -->|"uses"| node_insforge_client
node_booking_service -->|"uses"| node_insforge_client
node_auth_state -->|"authenticates with"| node_insforge_client
node_insforge_client -->|"accesses"| node_insforge
node_property_schema -.->|"evolves database"| node_insforge
node_booking_schema -.->|"evolves database"| node_insforge
node_profile_roles -.->|"defines access policies"| node_insforge
node_checkout -->|"initiates payment"| node_stripe
node_stripe -->|"payment event"| node_webhook
node_webhook -->|"finalizes booking"| node_insforge
node_vercel -->|"serves SPA"| node_entry
node_vercel -->|"runs endpoint"| node_webhook
node_ci -.->|"validates delivery"| node_vercel

click node_entry "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/main.tsx"
click node_app "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/App.tsx"
click node_route_guards "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/routes/ProtectedRoute.tsx"
click node_auth_state "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/context/AuthContext.tsx"
click node_rbac "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/lib/rbac.ts"
click node_discovery "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/components/ExploreView.tsx"
click node_checkout "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/pages/CheckoutPage.tsx"
click node_booking_service "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/services/booking.service.ts"
click node_host_ops "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/pages/HostDashboardPage.tsx"
click node_property_service "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/services/property.service.ts"
click node_admin_console "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/components/AdminConsole.tsx"
click node_analytics "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/hooks/useAdminAnalytics.ts"
click node_insforge_client "https://github.com/haddybhaiya/countryside/blob/main/frontend/src/lib/insforge.ts"
click node_property_schema "https://github.com/haddybhaiya/countryside/blob/main/migrations/20260713000001_host-property-rls.sql"
click node_booking_schema "https://github.com/haddybhaiya/countryside/blob/main/migrations/20260712162218_bookings-schema.sql"
click node_profile_roles "https://github.com/haddybhaiya/countryside/blob/main/migrations/20260713000002_fix-rls-roles.sql"
click node_webhook "https://github.com/haddybhaiya/countryside/blob/main/functions/stripe-webhook/index.ts"
click node_vercel "https://github.com/haddybhaiya/countryside/blob/main/frontend/vercel.json"
click node_ci "https://github.com/haddybhaiya/countryside/blob/main/.github/workflows/ci.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_entry,node_app,node_route_guards,node_auth_state,node_rbac,node_discovery,node_checkout,node_host_ops,node_admin_console,node_analytics toneBlue
class node_booking_service,node_property_service,node_insforge_client toneAmber
class node_insforge,node_property_schema,node_booking_schema,node_profile_roles,node_stripe,node_webhook,node_vercel,node_ci toneMint
```

## Components

### React SPA

Customer, host, and admin application.

- [SPA entry](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/main.tsx): React entry · `frontend/src/main.tsx`
- [App and routes](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/App.tsx): route composition · `frontend/src/App.tsx`
- [Route guards](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/routes/ProtectedRoute.tsx): auth boundary · Protects authenticated and guest-only routes. · `frontend/src/routes/ProtectedRoute.tsx`
- [Auth session](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/context/AuthContext.tsx): context · Central user and session state. · `frontend/src/context/AuthContext.tsx`
- [Role capabilities](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/lib/rbac.ts): RBAC policy · `frontend/src/lib/rbac.ts`
- [Property discovery](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/components/ExploreView.tsx): customer views · `frontend/src/components/ExploreView.tsx`
- [Checkout](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/pages/CheckoutPage.tsx): booking UI · `frontend/src/pages/CheckoutPage.tsx`
- [Host property operations](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/pages/HostDashboardPage.tsx): host workspace · `frontend/src/pages/HostDashboardPage.tsx`
- [Admin operations](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/components/AdminConsole.tsx): admin workspace · `frontend/src/components/AdminConsole.tsx`
- [Admin analytics](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/hooks/useAdminAnalytics.ts): analytics hook · Aggregates dashboard data and supports CSV export. · `frontend/src/hooks/useAdminAnalytics.ts`

### Application Services

- [Booking service](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/services/booking.service.ts): domain service · Creates bookings after pricing and availability checks. · `frontend/src/services/booking.service.ts`
- [Property service](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/services/property.service.ts): domain service · `frontend/src/services/property.service.ts`
- [InsForge client](https://github.com/haddybhaiya/countryside/blob/main/frontend/src/lib/insforge.ts): Supabase client · `frontend/src/lib/insforge.ts`

### Platform & Delivery

- **InsForge**: managed backend · Provides PostgreSQL, Auth, and Storage.
- [Property schema and RLS](https://github.com/haddybhaiya/countryside/blob/main/migrations/20260713000001_host-property-rls.sql): SQL migrations · Defines property ownership and host access controls. · `migrations/20260713000001_host-property-rls.sql`
- [Booking constraints](https://github.com/haddybhaiya/countryside/blob/main/migrations/20260712162218_bookings-schema.sql): SQL migration · Persists bookings and conflict controls. · `migrations/20260712162218_bookings-schema.sql`
- [Profiles and role policies](https://github.com/haddybhaiya/countryside/blob/main/migrations/20260713000002_fix-rls-roles.sql): SQL migrations · Establishes profiles, roles, and corrected RLS policies. · `migrations/20260713000002_fix-rls-roles.sql`
- **Stripe**: payment provider
- [Stripe webhook](https://github.com/haddybhaiya/countryside/blob/main/functions/stripe-webhook/index.ts): serverless endpoint · Verifies payment webhooks and finalizes bookings. · `functions/stripe-webhook/index.ts`
- [Vercel deployment](https://github.com/haddybhaiya/countryside/blob/main/frontend/vercel.json): hosting platform · Hosts the SPA and webhook endpoint. · `frontend/vercel.json`
- [CI pipeline](https://github.com/haddybhaiya/countryside/blob/main/.github/workflows/ci.yml): GitHub Actions · `.github/workflows/ci.yml`

## Connections

- SPA entry → App and routes: mounts
- App and routes → Route guards: applies
- Route guards → Auth session: reads session
- Route guards → Role capabilities: enforces roles
- App and routes → Property discovery: public routes
- App and routes → Checkout: checkout route
- App and routes → Host property operations: host route
- App and routes → Admin operations: admin route
- Property discovery → Property service: loads inventory
- Host property operations → Property service: manages inventory
- Checkout → Booking service: creates booking
- Admin operations → Admin analytics: shows metrics
- Property service → InsForge client: uses
- Booking service → InsForge client: uses
- Auth session → InsForge client: authenticates with
- InsForge client → InsForge: accesses
- Property schema and RLS → InsForge: evolves database
- Booking constraints → InsForge: evolves database
- Profiles and role policies → InsForge: defines access policies
- Checkout → Stripe: initiates payment
- Stripe → Stripe webhook: payment event
- Stripe webhook → InsForge: finalizes booking
- Vercel deployment → SPA entry: serves SPA
- Vercel deployment → Stripe webhook: runs endpoint
- CI pipeline → Vercel deployment: validates delivery
