How tej-carpenter/nestmate works
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: listings.ts Listings logic · server.ts Supabase · components Shared components · actions Server actions
Components 29
App surfaces
Next.js route segments and user-facing experiences.
- Home & content · Public marketing and informational pages.
src/app/page.tsx - Guest area · Guest dashboard, bookings, and chat experience.
src/app/guest - Host area · Host dashboard, listing creation, and verification flows.
src/app/host - Admin area · Operational dashboards for analytics, fraud, payouts, and archives.
src/app/admin - Search & browse · Search, city pages, and listing detail browsing.
src/app/search - Booking flow · Booking and payment entrypoints for guests.
src/app/book - Payment flow · Booking payment and receipt pages.
src/app/payment - Auth routes · Login, signup, and password recovery pages.
src/app/auth - Profile area · User profile and archived listings surfaces.
src/app/profile
Shared UI
Reusable components and presentation shells used across routes.
- Shared components · Reusable UI and feature components for layouts, navigation, listings, search, and verification.
src/components - Page shell · Application shell, header, footer, and navigation scaffolding.
src/components/layout/page-shell.tsx - Access control UI · Login forms and route access gate used to protect role-based areas.
src/components/auth/route-access-gate.tsx - Listing UI · Cards, templates, wizard, archived browser, availability, reviews, and view tracking components.
src/components/listings/listing-card.tsx - Search UI · Search filters and results shell.
src/components/search/search-results-shell.tsx - Host UI · Host dashboard client and profile card components.
src/components/host/host-dashboard-client.tsx - Analytics UI · Traffic and view tracking components for operational telemetry.
src/components/analytics/traffic-tracker.tsx - Verification UI · Badges and host verification presentation.
src/components/verification/verification-badges.tsx
Domain logic
Server actions, business rules, validation, and orchestration.
- Server actions · Server-action entrypoints for host, listing, and review mutations.
src/actions - Listings logic · Listing queries, lifecycle status, validation, and pricing/thumbnail support.
src/lib/listings.ts - Roles & access · Role definitions, permissions, and central access policy.
src/lib/auth/permissions.ts - Search ranking · Search query building and ranking/enrichment helpers.
src/lib/search/query.ts - Payments core · Razorpay orchestration, payout logic, webhook security, and rate limiting.
src/lib/payments/razorpay.ts - Verification logic · Verification requests and status handling.
src/lib/verification/requests.ts
Data & integrations
Persistence, external services, and cross-cutting infrastructure.
- Supabase · Primary database and auth client boundary for server and browser contexts.
src/lib/supabase/server.ts - DB schema · Typed database schema and model contract.
src/types/database.ts - Media storage · Cloudinary-backed uploads and image storage.
src/lib/storage/cloudinary.ts - Event tracking · Analytics events and view tracking data paths.
src/lib/analytics/events.ts - Route handlers · HTTP endpoints for health, dashboard data, listings, views, and payments.
src/app/api - Local data · Mock and fallback data plus local store abstractions.
src/lib/local-data.ts
Connections 27
- 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.