# rosbytes/gods-plan architecture

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

- Interactive diagram: https://gitdiagram.com/rosbytes/gods-plan
- Repository: https://github.com/rosbytes/gods-plan

## Overview

#### Purpose and topology
ROS is a pnpm/Turbo monorepo for a produce-market workflow spanning platform administration, mandi operators, and market vendors. It separates role-specific frontends and APIs while sharing database models and common utilities. Business timing and slot rules are documented in `.business-logic/`.

#### Entry points and runtimes
Three TypeScript API services expose tRPC-backed role boundaries, each with a server entry and Vercel adapter:
- Admin: `apps/admin-api/src/index.ts`, `apps/admin-api/api/index.js`
- Mandi: `apps/mandi-api/src/index.ts`, `apps/mandi-api/api/index.js`
- Vendor: `apps/vendor-api/src/index.ts`, `apps/vendor-api/api/index.js`

Role applications are Vite React SPAs: `apps/admin/src/main.tsx`, `apps/mandi/src/main.tsx`. Public/informational sites are Next.js apps rooted at `apps/info/src/app/page.tsx` and `apps/www/src/app/(root)/page.tsx`.

#### Shared persistence model
`packages/db` is the central persistence contract, using Drizzle schemas, migrations, seed/reset scripts, and local Docker support. Its schema models both sides of marketplace operations: mandis, stores, prices, vendors, carts, orders, payments, agreements, wallets, and status histories.
Key boundaries:
- Database connection/export: `packages/db/src/db.ts`, `packages/db/src/index.ts`
- Mandi-side entities: `packages/db/src/schema/mandi.ts`, `packages/db/src/schema/mandiVendor.ts`, `packages/db/src/schema/mandiPrice.ts`
- Market transaction lifecycle: `packages/db/src/schema/marketMandiOrder.ts`, `packages/db/src/schema/marketMandiPayment.ts`, `packages/db/src/schema/marketVendorWallet.ts`

#### Administration and onboarding
The admin API owns platform setup and governance: administrators, cities, mandis, vegetables, stores, assets, agreements, OTP/authentication, and payments. It is organized as module route/controller/schema units behind admin middleware.
- API composition/auth: `apps/admin-api/src/trpc/appRouter.ts`, `apps/admin-api/src/module/auth/auth.service.ts`, `apps/admin-api/src/middlewares/admin.middleware.ts`
- Administrative domain modules: `apps/admin-api/src/module/mandi/mandi.controller.ts`, `apps/admin-api/src/module/store/store.controller.ts`, `apps/admin-api/src/module/agreement/agreement.controller.ts`
- Admin SPA workflow pages: `apps/admin/src/pages/CreateVendor.tsx`, `apps/admin/src/pages/KycDocuments.tsx`, `apps/admin/src/pages/Payment.tsx`

#### Mandi operations
The mandi-facing system is currently narrow: authenticated mandi vendors access a protected API and SPA for vendor-slot operations, price updates, finance, orders, payments, and transactions. Slot assignment and pricing windows are explicit domain constraints rather than generic UI behavior.
- Service boundary: `apps/mandi-api/src/middlewares/mandiVendor.ts`, `apps/mandi-api/src/modules/auth/auth.controller.ts`
- Operator UI: `apps/mandi/src/pages/Home.tsx`, `apps/mandi/src/components/UpdatePriceDialog.tsx`, `apps/mandi/src/components/SlotTabs.tsx`
- Rules: `.business-logic/market-vendor-slot-assignments.md`, `.business-logic/mandi-vendor-actual-price-time-period.md`

#### Vendor commerce flow
The vendor API implements the core buyer workflow: authenticate, discover catalog, maintain cart, place/manage orders, and coordinate pickup. Controller/route/schema/service layering marks the API/domain boundary; the database persists order, payment, and wallet transitions.
- Router composition: `apps/vendor-api/src/trpc/appRouter.ts`, `apps/vendor-api/src/middlewares/marketVendor.ts`
- Commerce stages: `apps/vendor-api/src/modules/catalog/catalog.service.ts`, `apps/vendor-api/src/modules/cart/cart.service.ts`, `apps/vendor-api/src/modules/order/order.service.ts`
- Fulfillment: `apps/vendor-api/src/modules/pickup/pickup.service.ts`, `.business-logic/market-vendor-order-placement-time-period.md`

#### Infrastructure and external integrations
APIs are configured for environment-driven deployment and logging, with Vercel entry adapters. The repository indicates Redis/cache, S3 media storage, MSG91 OTP delivery, and Razorpay payments; payment webhooks are persisted in the shared database.
- Integrations: `apps/admin-api/src/configs/cache.ts`, `apps/admin-api/src/configs/msg91.ts`, `apps/admin-api/src/configs/payment.ts`
- Object storage/payment configuration: `apps/vendor-api/src/configs/s3.ts`, `apps/vendor-api/src/configs/payment.ts`
- Payment audit boundary: `packages/db/src/schema/marketMandiPaymentWebhookEvent.ts`, `packages/db/src/schema/marketMandiPaymentStatusHistory.ts`

Main entry points: [`apps/admin-api/src/index.ts`](https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/index.ts) (Admin API), [`apps/mandi-api/src/index.ts`](https://github.com/rosbytes/gods-plan/blob/main/apps/mandi-api/src/index.ts) (Mandi API), [`apps/vendor-api/src/modules/order/order.service.ts`](https://github.com/rosbytes/gods-plan/blob/main/apps/vendor-api/src/modules/order/order.service.ts) (Commerce services), [`packages/db/src/schema/marketMandiOrder.ts`](https://github.com/rosbytes/gods-plan/blob/main/packages/db/src/schema/marketMandiOrder.ts) (Market lifecycle schemas)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Role applications"]
  node_admin_spa["Admin SPA<br/>Vite React<br/>[main.tsx]"]
  node_mandi_spa["Mandi SPA<br/>Vite React<br/>[main.tsx]"]
  node_info_site["Info site<br/>Next.js<br/>[page.tsx]"]
  node_www_site["Public site<br/>Next.js<br/>[page.tsx]"]
end

subgraph group_apis["Role APIs"]
  node_admin_api["Admin API<br/>tRPC service<br/>[index.ts]"]
  node_admin_router["Admin router and auth<br/>tRPC/auth layer<br/>[appRouter.ts]"]
  node_admin_domains["Admin domain modules<br/>controllers"]
  node_mandi_api["Mandi API<br/>tRPC service<br/>[index.ts]"]
  node_mandi_auth["Mandi vendor access<br/>middleware/auth<br/>[mandiVendor.ts]"]
  node_vendor_api["Vendor API<br/>tRPC service<br/>[index.ts]"]
  node_vendor_router["Vendor router and access<br/>tRPC/middleware<br/>[appRouter.ts]"]
  node_commerce_flow["Commerce services<br/>catalog/cart/order<br/>[order.service.ts]"]
  node_pickup["Pickup service<br/>fulfillment<br/>[pickup.service.ts]"]
end

subgraph group_data["Shared data"]
  node_database[("Shared database<br/>Drizzle persistence<br/>[db.ts]")]
  node_market_lifecycle["Market lifecycle schemas<br/>orders/payments/wallets"]
  node_business_rules["Slot and timing rules<br/>business documentation"]
end

subgraph group_external["External services"]
  node_redis["Redis cache<br/>cache integration<br/>[cache.ts]"]
  node_msg91["MSG91<br/>OTP delivery<br/>[msg91.ts]"]
  node_s3["S3 media storage<br/>object storage<br/>[s3.ts]"]
  node_razorpay["Razorpay<br/>payment gateway<br/>[payment.ts]"]
end

node_admin_spa -->|"admin operations"| node_admin_api
node_mandi_spa -->|"operator operations"| node_mandi_api
node_admin_api -->|"composes"| node_admin_router
node_admin_router -->|"routes to"| node_admin_domains
node_admin_domains -->|"persists"| node_database
node_mandi_api -->|"protects with"| node_mandi_auth
node_mandi_api -->|"reads and writes"| node_database
node_vendor_api -->|"composes"| node_vendor_router
node_vendor_router -->|"routes to"| node_commerce_flow
node_commerce_flow -->|"coordinates fulfillment"| node_pickup
node_commerce_flow -->|"transitions"| node_market_lifecycle
node_market_lifecycle -->|"stored in"| node_database
node_pickup -.->|"constrained by"| node_business_rules
node_mandi_api -.->|"applies"| node_business_rules
node_admin_api -->|"uses"| node_redis
node_admin_api -->|"sends OTP via"| node_msg91
node_admin_api -->|"processes payments via"| node_razorpay
node_vendor_api -->|"stores media in"| node_s3
node_razorpay -->|"webhook audit"| node_market_lifecycle

click node_admin_spa "https://github.com/rosbytes/gods-plan/blob/main/apps/admin/src/main.tsx"
click node_mandi_spa "https://github.com/rosbytes/gods-plan/blob/main/apps/mandi/src/main.tsx"
click node_info_site "https://github.com/rosbytes/gods-plan/blob/main/apps/info/src/app/page.tsx"
click node_www_site "https://github.com/rosbytes/gods-plan/blob/main/apps/www/src/app/(root)/page.tsx"
click node_admin_api "https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/index.ts"
click node_admin_router "https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/trpc/appRouter.ts"
click node_admin_domains "https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/module/mandi/mandi.controller.ts"
click node_mandi_api "https://github.com/rosbytes/gods-plan/blob/main/apps/mandi-api/src/index.ts"
click node_mandi_auth "https://github.com/rosbytes/gods-plan/blob/main/apps/mandi-api/src/middlewares/mandiVendor.ts"
click node_vendor_api "https://github.com/rosbytes/gods-plan/blob/main/apps/vendor-api/src/index.ts"
click node_vendor_router "https://github.com/rosbytes/gods-plan/blob/main/apps/vendor-api/src/trpc/appRouter.ts"
click node_commerce_flow "https://github.com/rosbytes/gods-plan/blob/main/apps/vendor-api/src/modules/order/order.service.ts"
click node_pickup "https://github.com/rosbytes/gods-plan/blob/main/apps/vendor-api/src/modules/pickup/pickup.service.ts"
click node_database "https://github.com/rosbytes/gods-plan/blob/main/packages/db/src/db.ts"
click node_market_lifecycle "https://github.com/rosbytes/gods-plan/blob/main/packages/db/src/schema/marketMandiOrder.ts"
click node_business_rules "https://github.com/rosbytes/gods-plan/blob/main/.business-logic/market-vendor-slot-assignments.md"
click node_redis "https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/configs/cache.ts"
click node_msg91 "https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/configs/msg91.ts"
click node_s3 "https://github.com/rosbytes/gods-plan/blob/main/apps/vendor-api/src/configs/s3.ts"
click node_razorpay "https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/configs/payment.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_admin_spa,node_mandi_spa,node_info_site,node_www_site toneBlue
class node_admin_api,node_admin_router,node_admin_domains,node_mandi_api,node_mandi_auth,node_vendor_api,node_vendor_router,node_commerce_flow,node_pickup toneAmber
class node_database,node_market_lifecycle,node_business_rules toneMint
class node_redis,node_msg91,node_s3,node_razorpay toneRose
```

## Components

### Role applications

- [Admin SPA](https://github.com/rosbytes/gods-plan/blob/main/apps/admin/src/main.tsx): Vite React · Platform setup, onboarding, KYC, and payment workflows. · `apps/admin/src/main.tsx`
- [Mandi SPA](https://github.com/rosbytes/gods-plan/blob/main/apps/mandi/src/main.tsx): Vite React · Operator interface for slots and price updates. · `apps/mandi/src/main.tsx`
- [Info site](https://github.com/rosbytes/gods-plan/blob/main/apps/info/src/app/page.tsx): Next.js · `apps/info/src/app/page.tsx`
- [Public site](https://github.com/rosbytes/gods-plan/blob/main/apps/www/src/app/(root)/page.tsx): Next.js · `apps/www/src/app/(root)/page.tsx`

### Role APIs

- [Admin API](https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/index.ts): tRPC service · Administration, onboarding, governance, and payments. · `apps/admin-api/src/index.ts`
- [Admin router and auth](https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/trpc/appRouter.ts): tRPC/auth layer · `apps/admin-api/src/trpc/appRouter.ts`
- [Admin domain modules](https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/module/mandi/mandi.controller.ts): controllers · Mandi, store, agreement, and other platform administration. · `apps/admin-api/src/module/mandi/mandi.controller.ts`
- [Mandi API](https://github.com/rosbytes/gods-plan/blob/main/apps/mandi-api/src/index.ts): tRPC service · Protected mandi-vendor operations. · `apps/mandi-api/src/index.ts`
- [Mandi vendor access](https://github.com/rosbytes/gods-plan/blob/main/apps/mandi-api/src/middlewares/mandiVendor.ts): middleware/auth · `apps/mandi-api/src/middlewares/mandiVendor.ts`
- [Vendor API](https://github.com/rosbytes/gods-plan/blob/main/apps/vendor-api/src/index.ts): tRPC service · Buyer commerce and pickup coordination. · `apps/vendor-api/src/index.ts`
- [Vendor router and access](https://github.com/rosbytes/gods-plan/blob/main/apps/vendor-api/src/trpc/appRouter.ts): tRPC/middleware · `apps/vendor-api/src/trpc/appRouter.ts`
- [Commerce services](https://github.com/rosbytes/gods-plan/blob/main/apps/vendor-api/src/modules/order/order.service.ts): catalog/cart/order · Catalog discovery through order management. · `apps/vendor-api/src/modules/order/order.service.ts`
- [Pickup service](https://github.com/rosbytes/gods-plan/blob/main/apps/vendor-api/src/modules/pickup/pickup.service.ts): fulfillment · `apps/vendor-api/src/modules/pickup/pickup.service.ts`

### Shared data

- [Shared database](https://github.com/rosbytes/gods-plan/blob/main/packages/db/src/db.ts): Drizzle persistence · Central marketplace persistence contract. · `packages/db/src/db.ts`
- [Market lifecycle schemas](https://github.com/rosbytes/gods-plan/blob/main/packages/db/src/schema/marketMandiOrder.ts): orders/payments/wallets · Persists order, payment, and wallet transitions. · `packages/db/src/schema/marketMandiOrder.ts`
- [Slot and timing rules](https://github.com/rosbytes/gods-plan/blob/main/.business-logic/market-vendor-slot-assignments.md): business documentation · Defines vendor slots, pricing windows, and order timing. · `.business-logic/market-vendor-slot-assignments.md`

### External services

- [Redis cache](https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/configs/cache.ts): cache integration · `apps/admin-api/src/configs/cache.ts`
- [MSG91](https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/configs/msg91.ts): OTP delivery · `apps/admin-api/src/configs/msg91.ts`
- [S3 media storage](https://github.com/rosbytes/gods-plan/blob/main/apps/vendor-api/src/configs/s3.ts): object storage · `apps/vendor-api/src/configs/s3.ts`
- [Razorpay](https://github.com/rosbytes/gods-plan/blob/main/apps/admin-api/src/configs/payment.ts): payment gateway · Payment webhooks are audited in shared persistence. · `apps/admin-api/src/configs/payment.ts`

## Connections

- Admin SPA → Admin API: admin operations
- Mandi SPA → Mandi API: operator operations
- Admin API → Admin router and auth: composes
- Admin router and auth → Admin domain modules: routes to
- Admin domain modules → Shared database: persists
- Mandi API → Mandi vendor access: protects with
- Mandi API → Shared database: reads and writes
- Vendor API → Vendor router and access: composes
- Vendor router and access → Commerce services: routes to
- Commerce services → Pickup service: coordinates fulfillment
- Commerce services → Market lifecycle schemas: transitions
- Market lifecycle schemas → Shared database: stored in
- Pickup service → Slot and timing rules: constrained by
- Mandi API → Slot and timing rules: applies
- Admin API → Redis cache: uses
- Admin API → MSG91: sends OTP via
- Admin API → Razorpay: processes payments via
- Vendor API → S3 media storage: stores media in
- Razorpay → Market lifecycle schemas: webhook audit
