# dharshan47/rrckitchen architecture

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

- Interactive diagram: https://gitdiagram.com/dharshan47/rrckitchen
- Repository: https://github.com/dharshan47/rrckitchen

## Overview

#### Purpose and runtime
RRC Kitchen is a Next.js 16/React 19 TypeScript PWA marketplace for Thanjavur meal delivery. It serves customers, kitchen partners, delivery partners, and administrators from one App Router application. Primary web entry points are `app/page.tsx`, `app/layout.tsx`, and role-specific route trees such as `app/kitchen/dashboard`, `app/delivery-partner/dashboard`, and `app/admin`.

#### Routing and application boundary
Pages are composed as server/client React surfaces under `app/`; API route handlers provide webhook, integration, and client-facing HTTP boundaries under `app/api`. Business operations are primarily server actions grouped by domain in `actions/`, rather than a separate backend service.
- `app/cart/page.tsx`
- `app/kitchens/[slug]/page.tsx`
- `app/api/payment/verify/route.ts`
- `actions/index.ts`

#### Identity, roles, and portals
Better-Auth supports phone OTP authentication and administrative auth/2FA. Authorization boundaries distinguish customer accounts from kitchen, delivery, and admin operations; each role has a dedicated dashboard and corresponding action modules.
- `app/api/auth/[...all]/route.ts`
- `lib/auth.ts`
- `lib/auth-guards.ts`
- `app/admin/layout.tsx`
- `actions/onboarding/auth.ts`

#### Catalog, discovery, and cart
Customer discovery flows retrieve kitchens, menus, categories, nearby/search results, and reviews; client components and Zustand stores manage interactive filtering, menu selection, wishlist, location, and cart state. Checkout converts the client cart plus address/coupon inputs into an order/payment flow.
- `actions/catalog/home-data.ts`
- `actions/catalog/kitchen-detail.ts`
- `actions/catalog/menu.ts`
- `stores/cartStore.ts`
- `components/cart/cart-content.tsx`

#### Order lifecycle and dispatch
Orders progress from checkout/payment through kitchen preparation, dispatch assignment, pickup, delivery status, completion, reviews, and payout/reconciliation. Dispatch logic is split between central dispatch actions and order-oriented actions, while delivery partners submit availability, status, and location updates.
- `actions/orders/orders.ts`
- `actions/dispatch/dispatch-actions.ts`
- `actions/delivery/profile.ts`
- `app/api/delivery/order-status/route.ts`
- `app/api/rider/location/route.ts`

#### Payments, financial operations, and scheduled recovery
Razorpay covers online orders, UPI collect, verification, and webhooks; cash-on-delivery is also represented in the order/payment domain. Refund, kitchen payout, delivery payout, and retry/settlement jobs are separate operational stages. Webhook handling is an external trust boundary and scheduled GitHub/Vercel-triggered endpoints process deferred work.
- `app/api/payment/create-order/route.ts`
- `app/api/auth/razorpay/webhook/route.ts`
- `actions/payments/refund.ts`
- `actions/payouts/kitchen-payout.ts`
- `app/api/jobs/settle-payouts/route.ts`
- `.github/workflows/scheduled-jobs.yml`

#### Persistence, cache, media, and integrations
PostgreSQL is the system of record through Prisma, with its schema defining users/roles, kitchens, menus, orders, payments, delivery partners, reviews, and service zones. Redis supports caching; Cloudinary is the signed media upload/delete boundary. Geocoding/routing APIs support location-aware fulfillment.
- `prisma/schema.prisma`
- `lib/prisma.ts`
- `lib/redis.ts`
- `app/api/cloudinary/sign/route.ts`
- `app/api/geocode/search/route.ts`

#### Real-time, notification, and offline delivery
Ably provides order-tracking and rider-location channels to customer and partner dashboards. Web Push subscriptions and notification logic handle asynchronous user alerts. The service worker and manifest establish installable/offline PWA behavior; cron/job endpoints also drive nudges and event processing.
- `lib/ably/server.ts`
- `hooks/useAblySubscribe.ts`
- `components/map/live-order-tracking-map.tsx`
- `app/api/push/subscribe/route.ts`
- `app/api/cron/process-order-events/route.ts`
- `public/sw.js`

Main entry points: [`actions/orders/orders.ts`](https://github.com/dharshan47/rrckitchen/blob/main/actions/orders/orders.ts) (Order lifecycle), [`app/page.tsx`](https://github.com/dharshan47/rrckitchen/blob/main/app/page.tsx) (Customer storefront), [`prisma/schema.prisma`](https://github.com/dharshan47/rrckitchen/blob/main/prisma/schema.prisma) (PostgreSQL / Prisma), [`app/api/payment/verify/route.ts`](https://github.com/dharshan47/rrckitchen/blob/main/app/api/payment/verify/route.ts) (API routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Next.js application"]
  node_customer["Customer storefront<br/>React pages<br/>[page.tsx]"]
  node_role_portals["Role portals<br/>React dashboards"]
  node_api_routes["API routes<br/>HTTP handlers<br/>[route.ts]"]
  node_pwa["PWA service worker<br/>offline runtime<br/>[sw.js]"]
end

subgraph group_domain["Business operations"]
  node_auth{{"Auth and role guards<br/>identity boundary<br/>[auth.ts]"}}
  node_catalog["Catalog and discovery<br/>server actions<br/>[home-data.ts]"]
  node_cart["Cart state<br/>Zustand store<br/>[cartStore.ts]"]
  node_orders["Order lifecycle<br/>server actions<br/>[orders.ts]"]
  node_dispatch["Dispatch operations<br/>server actions"]
  node_delivery["Delivery updates<br/>partner operations<br/>[profile.ts]"]
  node_financial_ops["Refunds and payouts<br/>financial actions<br/>[refund.ts]"]
end

subgraph group_platform["Data and integrations"]
  node_database[("PostgreSQL / Prisma<br/>system of record<br/>[schema.prisma]")]
  node_redis[("Redis cache<br/>[redis.ts]")]
  node_razorpay{{"Razorpay<br/>payment provider<br/>[route.ts]"}}
  node_scheduled_jobs["Scheduled settlement<br/>job endpoint<br/>[route.ts]"]
  node_ably["Ably real-time<br/>event channels<br/>[server.ts]"]
  node_push{{"Web Push<br/>notification boundary<br/>[route.ts]"}}
  node_media_geo{{"Media and geolocation APIs<br/>external integrations<br/>[route.ts]"}}
end

node_customer -->|"browses"| node_catalog
node_customer -->|"updates"| node_cart
node_cart -->|"checkout input"| node_orders
node_role_portals -->|"authorizes"| node_auth
node_customer -->|"signs in"| node_auth
node_api_routes -->|"enforces roles"| node_auth
node_catalog -->|"reads catalog"| node_database
node_catalog -->|"caches"| node_redis
node_orders -->|"persists orders"| node_database
node_orders -->|"creates and verifies payment"| node_razorpay
node_razorpay -->|"webhook"| node_api_routes
node_orders -->|"requests assignment"| node_dispatch
node_dispatch -->|"assigns delivery"| node_delivery
node_delivery -->|"records status and location"| node_database
node_orders -->|"publishes order events"| node_ably
node_delivery -->|"publishes rider updates"| node_ably
node_ably -->|"live tracking"| node_customer
node_orders -->|"sends alerts"| node_push
node_financial_ops -->|"records reconciliation"| node_database
node_scheduled_jobs -.->|"triggers settlement"| node_financial_ops
node_api_routes -->|"proxies integrations"| node_media_geo
node_pwa -.->|"offline support"| node_customer

click node_customer "https://github.com/dharshan47/rrckitchen/blob/main/app/page.tsx"
click node_role_portals "https://github.com/dharshan47/rrckitchen/tree/main/app/kitchen/dashboard"
click node_api_routes "https://github.com/dharshan47/rrckitchen/blob/main/app/api/payment/verify/route.ts"
click node_pwa "https://github.com/dharshan47/rrckitchen/blob/main/public/sw.js"
click node_auth "https://github.com/dharshan47/rrckitchen/blob/main/lib/auth.ts"
click node_catalog "https://github.com/dharshan47/rrckitchen/blob/main/actions/catalog/home-data.ts"
click node_cart "https://github.com/dharshan47/rrckitchen/blob/main/stores/cartStore.ts"
click node_orders "https://github.com/dharshan47/rrckitchen/blob/main/actions/orders/orders.ts"
click node_dispatch "https://github.com/dharshan47/rrckitchen/blob/main/actions/dispatch/dispatch-actions.ts"
click node_delivery "https://github.com/dharshan47/rrckitchen/blob/main/actions/delivery/profile.ts"
click node_financial_ops "https://github.com/dharshan47/rrckitchen/blob/main/actions/payments/refund.ts"
click node_database "https://github.com/dharshan47/rrckitchen/blob/main/prisma/schema.prisma"
click node_redis "https://github.com/dharshan47/rrckitchen/blob/main/lib/redis.ts"
click node_razorpay "https://github.com/dharshan47/rrckitchen/blob/main/app/api/payment/create-order/route.ts"
click node_scheduled_jobs "https://github.com/dharshan47/rrckitchen/blob/main/app/api/jobs/settle-payouts/route.ts"
click node_ably "https://github.com/dharshan47/rrckitchen/blob/main/lib/ably/server.ts"
click node_push "https://github.com/dharshan47/rrckitchen/blob/main/app/api/push/subscribe/route.ts"
click node_media_geo "https://github.com/dharshan47/rrckitchen/blob/main/app/api/cloudinary/sign/route.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_customer,node_role_portals,node_api_routes,node_pwa toneBlue
class node_auth,node_catalog,node_cart,node_orders,node_dispatch,node_delivery,node_financial_ops toneAmber
class node_database,node_redis,node_razorpay,node_scheduled_jobs,node_ably,node_push,node_media_geo toneMint
```

## Components

### Next.js application

App Router surfaces and HTTP boundaries.

- [Customer storefront](https://github.com/dharshan47/rrckitchen/blob/main/app/page.tsx): React pages · Discovery, cart, checkout, and order tracking. · `app/page.tsx`
- [Role portals](https://github.com/dharshan47/rrckitchen/tree/main/app/kitchen/dashboard): React dashboards · Kitchen, delivery, and admin operational surfaces. · `app/kitchen/dashboard`
- [API routes](https://github.com/dharshan47/rrckitchen/blob/main/app/api/payment/verify/route.ts): HTTP handlers · Client, webhook, integration, and job endpoints. · `app/api/payment/verify/route.ts`
- [PWA service worker](https://github.com/dharshan47/rrckitchen/blob/main/public/sw.js): offline runtime · Provides installable and offline behavior. · `public/sw.js`

### Business operations

Server actions implement marketplace workflows.

- [Auth and role guards](https://github.com/dharshan47/rrckitchen/blob/main/lib/auth.ts): identity boundary · Phone OTP, admin 2FA, and authorization checks. · `lib/auth.ts`
- [Catalog and discovery](https://github.com/dharshan47/rrckitchen/blob/main/actions/catalog/home-data.ts): server actions · Retrieves kitchens, menus, search, and reviews. · `actions/catalog/home-data.ts`
- [Cart state](https://github.com/dharshan47/rrckitchen/blob/main/stores/cartStore.ts): Zustand store · Holds client-side meal selections for checkout. · `stores/cartStore.ts`
- [Order lifecycle](https://github.com/dharshan47/rrckitchen/blob/main/actions/orders/orders.ts): server actions · Creates and advances orders through completion and reviews. · `actions/orders/orders.ts`
- [Dispatch operations](https://github.com/dharshan47/rrckitchen/blob/main/actions/dispatch/dispatch-actions.ts): server actions · Assigns delivery work and coordinates fulfillment. · `actions/dispatch/dispatch-actions.ts`
- [Delivery updates](https://github.com/dharshan47/rrckitchen/blob/main/actions/delivery/profile.ts): partner operations · Availability, order status, and rider location updates. · `actions/delivery/profile.ts`
- [Refunds and payouts](https://github.com/dharshan47/rrckitchen/blob/main/actions/payments/refund.ts): financial actions · Handles refunds and kitchen or rider payouts. · `actions/payments/refund.ts`

### Data and integrations

Persistence, real-time, payments, and external services.

- [PostgreSQL / Prisma](https://github.com/dharshan47/rrckitchen/blob/main/prisma/schema.prisma): system of record · Stores marketplace identities, catalog, orders, payments, and zones. · `prisma/schema.prisma`
- [Redis cache](https://github.com/dharshan47/rrckitchen/blob/main/lib/redis.ts): cache · `lib/redis.ts`
- [Razorpay](https://github.com/dharshan47/rrckitchen/blob/main/app/api/payment/create-order/route.ts): payment provider · Online payment, UPI collect, verification, and webhooks. · `app/api/payment/create-order/route.ts`
- [Scheduled settlement](https://github.com/dharshan47/rrckitchen/blob/main/app/api/jobs/settle-payouts/route.ts): job endpoint · Processes deferred payouts and recovery work. · `app/api/jobs/settle-payouts/route.ts`
- [Ably real-time](https://github.com/dharshan47/rrckitchen/blob/main/lib/ably/server.ts): event channels · Publishes order tracking and rider-location updates. · `lib/ably/server.ts`
- [Web Push](https://github.com/dharshan47/rrckitchen/blob/main/app/api/push/subscribe/route.ts): notification boundary · Stores subscriptions and sends asynchronous alerts. · `app/api/push/subscribe/route.ts`
- [Media and geolocation APIs](https://github.com/dharshan47/rrckitchen/blob/main/app/api/cloudinary/sign/route.ts): external integrations · Supports signed uploads, geocoding, and routing. · `app/api/cloudinary/sign/route.ts`

## Connections

- Customer storefront → Catalog and discovery: browses
- Customer storefront → Cart state: updates
- Cart state → Order lifecycle: checkout input
- Role portals → Auth and role guards: authorizes
- Customer storefront → Auth and role guards: signs in
- API routes → Auth and role guards: enforces roles
- Catalog and discovery → PostgreSQL / Prisma: reads catalog
- Catalog and discovery → Redis cache: caches
- Order lifecycle → PostgreSQL / Prisma: persists orders
- Order lifecycle → Razorpay: creates and verifies payment
- Razorpay → API routes: webhook
- Order lifecycle → Dispatch operations: requests assignment
- Dispatch operations → Delivery updates: assigns delivery
- Delivery updates → PostgreSQL / Prisma: records status and location
- Order lifecycle → Ably real-time: publishes order events
- Delivery updates → Ably real-time: publishes rider updates
- Ably real-time → Customer storefront: live tracking
- Order lifecycle → Web Push: sends alerts
- Refunds and payouts → PostgreSQL / Prisma: records reconciliation
- Scheduled settlement → Refunds and payouts: triggers settlement
- API routes → Media and geolocation APIs: proxies integrations
- PWA service worker → Customer storefront: offline support
