# tej-carpenter/nestmate architecture

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

- Interactive diagram: https://gitdiagram.com/tej-carpenter/nestmate
- Repository: https://github.com/tej-carpenter/nestmate

## Overview

1. **Overall shape**
   - This is a Next.js App Router application built in TypeScript.
   - The repo is organized as a marketplace-style product with distinct **guest**, **host**, and **admin** experiences, plus supporting payment, search, verification, and analytics flows.

2. **Presentation layer**
   - `src/app/**` contains route segments and page entrypoints for the user-facing surface area.
   - The top-level routes include home, listings, search, city pages, booking, payment, auth, profile, safety/legal pages, and separate host/admin dashboards.
   - `src/components/**` holds reusable UI and feature components that power those pages, while `src/components/layout`, `nav`, `theme`, and `ui` provide the shared shell and design system.

3. **Role-based product areas**
   - The app clearly separates behavior by actor:
     - **Guests**: dashboard, bookings, chat.
     - **Hosts**: dashboard, listing creation, verification.
     - **Admins**: dashboard, analytics, fraud, payouts, archived properties.
   - `src/components/auth/route-access-gate.tsx`, `src/lib/auth/permissions.ts`, and `src/lib/auth/roles.ts` suggest access control is enforced centrally and reused across routes and components.

4. **Listings domain**
   - Listings are a core domain model, with pages for listing detail, city browsing, search, archived listings, and host listing creation.
   - The business logic is split between `src/lib/listings.ts`, `src/lib/listing-queries.ts`, `src/lib/listings/status.ts`, `src/lib/validators/listing.ts`, and UI pieces like `listing-card`, `listing-page-template`, `listing-wizard`, and `availability-badge`.
   - `src/actions/listings.ts` and `src/app/api/listings/**` indicate listings can be manipulated both through server actions and HTTP endpoints.

5. **Booking and payment flow**
   - Payments are handled as a separate subsystem with dedicated routes under `src/app/payment/[bookingId]` and Razorpay API endpoints under `src/app/api/razorpay/*`.
   - `src/lib/payments/razorpay.ts`, `src/lib/security/webhooks.ts`, and `src/lib/security/rate-limit.ts` suggest the payment flow includes order creation, verification, webhook handling, and abuse protection.
   - `src/app/api/razorpay/create-order/route.ts` and `verify/route.ts` are the boundary between the app and the payment provider.

6. **Backend/data boundary**
   - `src/lib/supabase/server.ts` and `src/lib/supabase/client.ts` show Supabase is the primary backend client for server and browser contexts.
   - `supabase/migrations/**` and `src/types/database.ts` indicate the database schema is treated as a first-class contract.
   - `src/lib/database/schema.ts`, `listing-store.ts`, and `src/lib/local-data.ts` suggest a mix of persistence abstractions and local/mock data support, likely used for development or fallback paths.

7. **Server-side orchestration**
   - `src/actions/host.ts`, `listings.ts`, and `reviews.ts` are the main server-action entrypoints for domain mutations and host workflows.
   - `src/app/api/**` contains HTTP endpoints for health checks, dashboard host data, listing view tracking, and payment operations.
   - This split implies the app uses both React server actions for in-app mutations and route handlers for integration-facing or client-consumed endpoints.

8. **Analytics, tracking, and admin oversight**
   - `src/components/analytics/traffic-tracker.tsx`, `src/components/listings/view-tracker.tsx`, and `src/lib/analytics/events.ts` indicate event collection around traffic and views.
   - The admin analytics and fraud pages, plus the `host-analytics-and-inventory` database migration, show analytics is not just cosmetic; it feeds operational dashboards and oversight.
   - View tracking is also surfaced via `src/app/api/listings/[listingId]/view/route.ts`.

9. **Verification, trust, and policy handling**
   - Host verification has its own page and UI, backed by `src/lib/verification/*` and `src/components/verification/verification-badges.tsx`.
   - Policy acceptance and archived-property migrations suggest trust/safety state is persisted and affects what content is shown or managed.
   - Supporting pages like safety, terms, privacy, host terms, refund, and fraud reinforce that this is a regulated transaction workflow rather than a simple content site.

10. **Supporting integrations**
   - `src/lib/storage/cloudinary.ts` and `uploads.ts` indicate media uploads are externalized to Cloudinary or a similar asset store.
   - `src/lib/google-maps.ts`, `src/lib/search/query.ts`, `src/lib/pricing.ts`, and `src/lib/nestscore.ts` point to enrichment logic for search, pricing, location, and ranking/quality scoring.
   - `src/lib/notifications/channels.ts` likely centralizes outbound messaging channels for operational or user notifications.

11. **Testing and quality boundaries**
   - The repo includes Vitest tests for authorization and availability logic, plus API/payment scripts and database test helpers.
   - This suggests the most critical correctness boundaries are around permissions, availability, booking integrity, and payment reconciliation.

12. **What to draw in an architecture diagram**
   - A good diagram should show:
     - Browser/UI routes built from the Next.js App Router.
     - Shared component and feature libraries feeding those pages.
     - Server actions and route handlers as the mutation/API layer.
     - Supabase as the persistence/auth backbone.
     - Razorpay and Cloudinary as external service boundaries.
     - Tracking/analytics and admin dashboards as a parallel operational plane.

Main entry points: [`src/lib/listings.ts`](https://github.com/tej-carpenter/nestmate/blob/main/src/lib/listings.ts) (Listings logic), [`src/lib/supabase/server.ts`](https://github.com/tej-carpenter/nestmate/blob/main/src/lib/supabase/server.ts) (Supabase), [`src/components`](https://github.com/tej-carpenter/nestmate/tree/main/src/components) (Shared components), [`src/actions`](https://github.com/tej-carpenter/nestmate/tree/main/src/actions) (Server actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_app["App surfaces"]
  node_node_home["Home & content<br/>routes<br/>[page.tsx]"]
  node_node_guest["Guest area<br/>routes"]
  node_node_host["Host area<br/>routes"]
  node_node_admin["Admin area<br/>routes"]
  node_node_search["Search & browse<br/>routes"]
  node_node_booking["Booking flow<br/>routes"]
  node_node_payment["Payment flow<br/>routes"]
  node_node_auth["Auth routes"]
  node_node_profile["Profile area<br/>routes"]
end

subgraph group_group_ui["Shared UI"]
  node_node_components["Shared components<br/>ui library"]
  node_node_layout["Page shell<br/>layout<br/>[page-shell.tsx]"]
  node_node_auth_ui["Access control UI<br/>auth ui"]
  node_node_listing_ui["Listing UI<br/>[listing-card.tsx]"]
  node_node_search_ui["Search UI"]
  node_node_host_ui["Host UI"]
  node_node_analytics_ui["Analytics UI"]
  node_node_verification_ui["Verification UI<br/>trust ui"]
end

subgraph group_group_domain["Domain logic"]
  node_node_actions["Server actions<br/>mutations"]
  node_node_listings_logic["Listings logic<br/>domain<br/>[listings.ts]"]
  node_node_auth_logic["Roles & access<br/>policy<br/>[permissions.ts]"]
  node_node_search_logic["Search ranking<br/>domain<br/>[query.ts]"]
  node_node_payments_logic["Payments core<br/>[razorpay.ts]"]
  node_node_verification_logic["Verification logic<br/>trust domain<br/>[requests.ts]"]
end

subgraph group_group_data["Data & integrations"]
  node_node_supabase[("Supabase<br/>backend<br/>[server.ts]")]
  node_node_db_schema["DB schema<br/>contract<br/>[database.ts]"]
  node_node_storage["Media storage<br/>asset service<br/>[cloudinary.ts]"]
  node_node_analytics_data["Event tracking<br/>telemetry<br/>[events.ts]"]
  node_node_api["Route handlers<br/>http api"]
  node_node_mock["Local data<br/>dev data<br/>[local-data.ts]"]
end

node_node_home -->|"renders with"| node_node_components
node_node_guest -->|"uses"| node_node_components
node_node_host -->|"uses"| node_node_components
node_node_admin -->|"uses"| node_node_components
node_node_search -->|"uses"| node_node_search_ui
node_node_booking -->|"hands off to"| node_node_payment
node_node_payment -->|"uses"| node_node_payments_logic
node_node_auth -->|"uses"| node_node_auth_ui
node_node_profile -->|"uses"| node_node_components
node_node_host -->|"shows"| node_node_verification_ui
node_node_listing_ui -->|"reflects"| node_node_listings_logic
node_node_search_ui -->|"queries"| node_node_search_logic
node_node_actions -->|"mutates"| node_node_listings_logic
node_node_actions -->|"mutates"| node_node_verification_logic
node_node_actions -->|"persists via"| node_node_supabase
node_node_listings_logic -->|"typed by"| node_node_db_schema
node_node_auth_logic -->|"authorizes against"| node_node_supabase
node_node_payments_logic -->|"exposed by"| node_node_api
node_node_api -->|"reads/writes"| node_node_supabase
node_node_api -->|"emits"| node_node_analytics_data
node_node_analytics_ui -->|"feeds"| node_node_analytics_data
node_node_verification_logic -->|"stores in"| node_node_supabase
node_node_storage -->|"supports"| node_node_listings_logic
node_node_mock -->|"backs"| node_node_listings_logic
node_node_host_ui -->|"invokes"| node_node_actions
node_node_auth_ui -->|"checks"| node_node_auth_logic
node_node_supabase -->|"implements"| node_node_db_schema

click node_node_home "https://github.com/tej-carpenter/nestmate/blob/main/src/app/page.tsx"
click node_node_guest "https://github.com/tej-carpenter/nestmate/tree/main/src/app/guest"
click node_node_host "https://github.com/tej-carpenter/nestmate/tree/main/src/app/host"
click node_node_admin "https://github.com/tej-carpenter/nestmate/tree/main/src/app/admin"
click node_node_search "https://github.com/tej-carpenter/nestmate/tree/main/src/app/search"
click node_node_booking "https://github.com/tej-carpenter/nestmate/tree/main/src/app/book"
click node_node_payment "https://github.com/tej-carpenter/nestmate/tree/main/src/app/payment"
click node_node_auth "https://github.com/tej-carpenter/nestmate/tree/main/src/app/auth"
click node_node_profile "https://github.com/tej-carpenter/nestmate/tree/main/src/app/profile"
click node_node_components "https://github.com/tej-carpenter/nestmate/tree/main/src/components"
click node_node_layout "https://github.com/tej-carpenter/nestmate/blob/main/src/components/layout/page-shell.tsx"
click node_node_auth_ui "https://github.com/tej-carpenter/nestmate/blob/main/src/components/auth/route-access-gate.tsx"
click node_node_listing_ui "https://github.com/tej-carpenter/nestmate/blob/main/src/components/listings/listing-card.tsx"
click node_node_search_ui "https://github.com/tej-carpenter/nestmate/blob/main/src/components/search/search-results-shell.tsx"
click node_node_host_ui "https://github.com/tej-carpenter/nestmate/blob/main/src/components/host/host-dashboard-client.tsx"
click node_node_analytics_ui "https://github.com/tej-carpenter/nestmate/blob/main/src/components/analytics/traffic-tracker.tsx"
click node_node_verification_ui "https://github.com/tej-carpenter/nestmate/blob/main/src/components/verification/verification-badges.tsx"
click node_node_actions "https://github.com/tej-carpenter/nestmate/tree/main/src/actions"
click node_node_listings_logic "https://github.com/tej-carpenter/nestmate/blob/main/src/lib/listings.ts"
click node_node_auth_logic "https://github.com/tej-carpenter/nestmate/blob/main/src/lib/auth/permissions.ts"
click node_node_search_logic "https://github.com/tej-carpenter/nestmate/blob/main/src/lib/search/query.ts"
click node_node_payments_logic "https://github.com/tej-carpenter/nestmate/blob/main/src/lib/payments/razorpay.ts"
click node_node_verification_logic "https://github.com/tej-carpenter/nestmate/blob/main/src/lib/verification/requests.ts"
click node_node_supabase "https://github.com/tej-carpenter/nestmate/blob/main/src/lib/supabase/server.ts"
click node_node_db_schema "https://github.com/tej-carpenter/nestmate/blob/main/src/types/database.ts"
click node_node_storage "https://github.com/tej-carpenter/nestmate/blob/main/src/lib/storage/cloudinary.ts"
click node_node_analytics_data "https://github.com/tej-carpenter/nestmate/blob/main/src/lib/analytics/events.ts"
click node_node_api "https://github.com/tej-carpenter/nestmate/tree/main/src/app/api"
click node_node_mock "https://github.com/tej-carpenter/nestmate/blob/main/src/lib/local-data.ts"

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_node_home,node_node_guest,node_node_host,node_node_admin,node_node_search,node_node_booking,node_node_payment,node_node_auth,node_node_profile toneBlue
class node_node_components,node_node_layout,node_node_auth_ui,node_node_listing_ui,node_node_search_ui,node_node_host_ui,node_node_analytics_ui,node_node_verification_ui toneAmber
class node_node_actions,node_node_listings_logic,node_node_auth_logic,node_node_search_logic,node_node_payments_logic,node_node_verification_logic toneMint
class node_node_supabase,node_node_db_schema,node_node_storage,node_node_analytics_data,node_node_api,node_node_mock toneRose
```

## Components

### App surfaces

Next.js route segments and user-facing experiences.

- [Home & content](https://github.com/tej-carpenter/nestmate/blob/main/src/app/page.tsx): routes · Public marketing and informational pages. · `src/app/page.tsx`
- [Guest area](https://github.com/tej-carpenter/nestmate/tree/main/src/app/guest): routes · Guest dashboard, bookings, and chat experience. · `src/app/guest`
- [Host area](https://github.com/tej-carpenter/nestmate/tree/main/src/app/host): routes · Host dashboard, listing creation, and verification flows. · `src/app/host`
- [Admin area](https://github.com/tej-carpenter/nestmate/tree/main/src/app/admin): routes · Operational dashboards for analytics, fraud, payouts, and archives. · `src/app/admin`
- [Search & browse](https://github.com/tej-carpenter/nestmate/tree/main/src/app/search): routes · Search, city pages, and listing detail browsing. · `src/app/search`
- [Booking flow](https://github.com/tej-carpenter/nestmate/tree/main/src/app/book): routes · Booking and payment entrypoints for guests. · `src/app/book`
- [Payment flow](https://github.com/tej-carpenter/nestmate/tree/main/src/app/payment): routes · Booking payment and receipt pages. · `src/app/payment`
- [Auth routes](https://github.com/tej-carpenter/nestmate/tree/main/src/app/auth): routes · Login, signup, and password recovery pages. · `src/app/auth`
- [Profile area](https://github.com/tej-carpenter/nestmate/tree/main/src/app/profile): routes · User profile and archived listings surfaces. · `src/app/profile`

### Shared UI

Reusable components and presentation shells used across routes.

- [Shared components](https://github.com/tej-carpenter/nestmate/tree/main/src/components): ui library · Reusable UI and feature components for layouts, navigation, listings, search, and verification. · `src/components`
- [Page shell](https://github.com/tej-carpenter/nestmate/blob/main/src/components/layout/page-shell.tsx): layout · Application shell, header, footer, and navigation scaffolding. · `src/components/layout/page-shell.tsx`
- [Access control UI](https://github.com/tej-carpenter/nestmate/blob/main/src/components/auth/route-access-gate.tsx): auth ui · Login forms and route access gate used to protect role-based areas. · `src/components/auth/route-access-gate.tsx`
- [Listing UI](https://github.com/tej-carpenter/nestmate/blob/main/src/components/listings/listing-card.tsx): listing ui · Cards, templates, wizard, archived browser, availability, reviews, and view tracking components. · `src/components/listings/listing-card.tsx`
- [Search UI](https://github.com/tej-carpenter/nestmate/blob/main/src/components/search/search-results-shell.tsx): search ui · Search filters and results shell. · `src/components/search/search-results-shell.tsx`
- [Host UI](https://github.com/tej-carpenter/nestmate/blob/main/src/components/host/host-dashboard-client.tsx): host ui · Host dashboard client and profile card components. · `src/components/host/host-dashboard-client.tsx`
- [Analytics UI](https://github.com/tej-carpenter/nestmate/blob/main/src/components/analytics/traffic-tracker.tsx): analytics ui · Traffic and view tracking components for operational telemetry. · `src/components/analytics/traffic-tracker.tsx`
- [Verification UI](https://github.com/tej-carpenter/nestmate/blob/main/src/components/verification/verification-badges.tsx): trust ui · Badges and host verification presentation. · `src/components/verification/verification-badges.tsx`

### Domain logic

Server actions, business rules, validation, and orchestration.

- [Server actions](https://github.com/tej-carpenter/nestmate/tree/main/src/actions): mutations · Server-action entrypoints for host, listing, and review mutations. · `src/actions`
- [Listings logic](https://github.com/tej-carpenter/nestmate/blob/main/src/lib/listings.ts): domain · Listing queries, lifecycle status, validation, and pricing/thumbnail support. · `src/lib/listings.ts`
- [Roles & access](https://github.com/tej-carpenter/nestmate/blob/main/src/lib/auth/permissions.ts): policy · Role definitions, permissions, and central access policy. · `src/lib/auth/permissions.ts`
- [Search ranking](https://github.com/tej-carpenter/nestmate/blob/main/src/lib/search/query.ts): domain · Search query building and ranking/enrichment helpers. · `src/lib/search/query.ts`
- [Payments core](https://github.com/tej-carpenter/nestmate/blob/main/src/lib/payments/razorpay.ts): payment · Razorpay orchestration, payout logic, webhook security, and rate limiting. · `src/lib/payments/razorpay.ts`
- [Verification logic](https://github.com/tej-carpenter/nestmate/blob/main/src/lib/verification/requests.ts): trust domain · Verification requests and status handling. · `src/lib/verification/requests.ts`

### Data & integrations

Persistence, external services, and cross-cutting infrastructure.

- [Supabase](https://github.com/tej-carpenter/nestmate/blob/main/src/lib/supabase/server.ts): backend · Primary database and auth client boundary for server and browser contexts. · `src/lib/supabase/server.ts`
- [DB schema](https://github.com/tej-carpenter/nestmate/blob/main/src/types/database.ts): contract · Typed database schema and model contract. · `src/types/database.ts`
- [Media storage](https://github.com/tej-carpenter/nestmate/blob/main/src/lib/storage/cloudinary.ts): asset service · Cloudinary-backed uploads and image storage. · `src/lib/storage/cloudinary.ts`
- [Event tracking](https://github.com/tej-carpenter/nestmate/blob/main/src/lib/analytics/events.ts): telemetry · Analytics events and view tracking data paths. · `src/lib/analytics/events.ts`
- [Route handlers](https://github.com/tej-carpenter/nestmate/tree/main/src/app/api): http api · HTTP endpoints for health, dashboard data, listings, views, and payments. · `src/app/api`
- [Local data](https://github.com/tej-carpenter/nestmate/blob/main/src/lib/local-data.ts): dev data · Mock and fallback data plus local store abstractions. · `src/lib/local-data.ts`

## Connections

- Home & content → Shared components: renders with · Home and content pages are assembled from shared UI.
- Guest area → Shared components: uses · Guest pages use the shared component library.
- Host area → Shared components: uses · Host pages use reusable UI and feature components.
- Admin area → Shared components: uses · Admin dashboards are built from shared UI primitives.
- Search & browse → Search UI: uses · Search and city routes are driven by the search UI shell.
- Booking flow → Payment flow: hands off to · Booking routes lead into payment pages.
- Payment flow → Payments core: uses · Payment pages depend on payment orchestration logic.
- Auth routes → Access control UI: uses · Auth routes use shared forms and access gating.
- Profile area → Shared components: uses · Profile pages reuse shared layout and UI components.
- Host area → Verification UI: shows · Host verification pages present trust badges and status.
- Listing UI → Listings logic: reflects · Listing components are driven by listings domain state.
- Search UI → Search ranking: queries · Search UI depends on search query and ranking logic.
- Server actions → Listings logic: mutates · Server actions implement listing workflows.
- Server actions → Verification logic: mutates · Server actions also handle verification workflows.
- Server actions → Supabase: persists via · Mutations are written through Supabase.
- Listings logic → DB schema: typed by · Listings logic is constrained by the database contract.
- Roles & access → Supabase: authorizes against · Access control uses Supabase-backed identity and roles.
- Payments core → Route handlers: exposed by · Payment operations are surfaced through route handlers.
- Route handlers → Supabase: reads/writes · HTTP handlers interact with the backend data layer.
- Route handlers → Event tracking: emits · View tracking and operational endpoints emit telemetry.
- Analytics UI → Event tracking: feeds · Tracking components send events to analytics plumbing.
- Verification logic → Supabase: stores in · Verification requests and status are persisted in Supabase.
- Media storage → Listings logic: supports · Listings and uploads depend on media storage.
- Local data → Listings logic: backs · Local data supports development and fallback listing flows.
- Host UI → Server actions: invokes · Host dashboard UI triggers server mutations.
- Access control UI → Roles & access: checks · Access gate and auth UI enforce role-based permissions.
- Supabase → DB schema: implements · Supabase usage is anchored to the typed schema contract.
