# phk006/bolovyapaari architecture

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

- Interactive diagram: https://gitdiagram.com/phk006/bolovyapaari
- Repository: https://github.com/phk006/bolovyapaari

## Overview

Bolovyapaari is a voice-first local grocery-commerce demo connecting customers, kirana shopkeepers and distributors. Customers browse a shared catalogue, build a basket and submit an order; shopkeepers handle orders and request replenishment; distributors confirm or propose quantities, dispatch and track supply. The Next.js app provides role-based views and API routes, with PostgreSQL holding commerce state and activity records. Voice input uses a local Whisper service, while customer voice commands can update the basket. Some UI-to-route wiring is documented rather than shown in the excerpts, so those links are marked unverified.

Main entry points: [`src/components/dashboard-client.tsx`](https://github.com/phk006/bolovyapaari/blob/main/src/components/dashboard-client.tsx) (Role dashboards), [`src/lib/db.ts`](https://github.com/phk006/bolovyapaari/blob/main/src/lib/db.ts) (Database transactions), [`src/lib/auth/require-role.ts`](https://github.com/phk006/bolovyapaari/blob/main/src/lib/auth/require-role.ts) (Role checks), [`src/app/api/orders/route.ts`](https://github.com/phk006/bolovyapaari/blob/main/src/app/api/orders/route.ts) (Order creation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Application experience"]
  node_dashboard["Role dashboards"]
end

subgraph group_identity["Role and session"]
  node_session_api["Session API<br/>[route.ts]"]
  node_session_logic["Signed sessions<br/>[session.ts]"]
  node_role_guard["Role checks<br/>[require-role.ts]"]
end

subgraph group_retail["Customer commerce"]
  node_catalogue_orders["Catalogue and orders<br/>[route.ts]"]
  node_order_api["Order creation<br/>[route.ts]"]
  node_order_updates["Order updates<br/>[route.ts]"]
end

subgraph group_supply["Wholesale replenishment"]
  node_purchase_create["Replenishment requests<br/>[route.ts]"]
  node_purchase_updates["Wholesale lifecycle<br/>[route.ts]"]
end

subgraph group_voice["Voice input"]
  node_voice_ui["Voice assistant UI"]
  node_voice_commands["Voice command parser"]
  node_speech_provider["Local Whisper client<br/>[local-whisper.ts]"]
  node_transcription_api["Transcription API<br/>[route.ts]"]
  node_speech_service["Whisper service<br/>[main.py]"]
end

node_customer(("Customer"))
node_shopkeeper(("Shopkeeper"))
node_distributor(("Distributor"))
node_database[("PostgreSQL commerce data<br/>[001_schema.sql]")]
node_db_access["Database transactions<br/>[db.ts]"]
node_activity["Activity logging<br/>[activity.ts]"]

node_customer -->|"uses storefront"| node_dashboard
node_shopkeeper -->|"uses workspace"| node_dashboard
node_distributor -->|"uses workspace"| node_dashboard
node_dashboard -->|"loads session"| node_session_api
node_session_api -->|"reads session"| node_session_logic
node_session_api -->|"queries users"| node_db_access
node_role_guard -->|"validates role"| node_session_logic
node_dashboard -.->|"loads dashboard"| node_catalogue_orders
node_dashboard -.->|"submits basket"| node_order_api
node_dashboard -.->|"updates orders"| node_order_updates
node_order_api -->|"checks customer"| node_role_guard
node_order_api -->|"writes order"| node_db_access
node_order_api -->|"logs order"| node_activity
node_order_updates -->|"updates order"| node_db_access
node_order_updates -->|"logs update"| node_activity
node_dashboard -.->|"requests stock"| node_purchase_create
node_dashboard -.->|"manages replenishment"| node_purchase_updates
node_purchase_create -->|"checks shopkeeper"| node_role_guard
node_purchase_create -->|"creates request"| node_db_access
node_purchase_create -->|"logs request"| node_activity
node_purchase_updates -->|"checks role"| node_role_guard
node_purchase_updates -->|"updates lifecycle"| node_db_access
node_purchase_updates -->|"logs changes"| node_activity
node_db_access -->|"reads and writes"| node_database
node_dashboard -->|"renders assistant"| node_voice_ui
node_voice_ui -->|"captures speech"| node_speech_provider
node_voice_ui -->|"submits command"| node_voice_commands
node_speech_provider -->|"sends audio"| node_transcription_api
node_transcription_api -->|"checks role"| node_role_guard
node_transcription_api -->|"forwards audio"| node_speech_service

click node_dashboard "https://github.com/phk006/bolovyapaari/blob/main/src/components/dashboard-client.tsx"
click node_session_api "https://github.com/phk006/bolovyapaari/blob/main/src/app/api/session/route.ts"
click node_session_logic "https://github.com/phk006/bolovyapaari/blob/main/src/lib/auth/session.ts"
click node_role_guard "https://github.com/phk006/bolovyapaari/blob/main/src/lib/auth/require-role.ts"
click node_catalogue_orders "https://github.com/phk006/bolovyapaari/blob/main/src/app/api/dashboard/route.ts"
click node_order_api "https://github.com/phk006/bolovyapaari/blob/main/src/app/api/orders/route.ts"
click node_order_updates "https://github.com/phk006/bolovyapaari/blob/main/src/app/api/orders/%5Bid%5D/route.ts"
click node_purchase_create "https://github.com/phk006/bolovyapaari/blob/main/src/app/api/purchase-orders/route.ts"
click node_purchase_updates "https://github.com/phk006/bolovyapaari/blob/main/src/app/api/purchase-orders/%5Bid%5D/route.ts"
click node_database "https://github.com/phk006/bolovyapaari/blob/main/db/init/001_schema.sql"
click node_db_access "https://github.com/phk006/bolovyapaari/blob/main/src/lib/db.ts"
click node_activity "https://github.com/phk006/bolovyapaari/blob/main/src/lib/activity.ts"
click node_voice_ui "https://github.com/phk006/bolovyapaari/blob/main/src/components/voice-assistant.tsx"
click node_voice_commands "https://github.com/phk006/bolovyapaari/blob/main/src/lib/customer-voice-commands.ts"
click node_speech_provider "https://github.com/phk006/bolovyapaari/blob/main/src/lib/speech-to-text/providers/local-whisper.ts"
click node_transcription_api "https://github.com/phk006/bolovyapaari/blob/main/src/app/api/speech-transcribe/route.ts"
click node_speech_service "https://github.com/phk006/bolovyapaari/blob/main/speech-service/app/main.py"

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_dashboard toneBlue
class node_session_api,node_session_logic,node_role_guard,node_database,node_db_access toneAmber
class node_catalogue_orders,node_order_api,node_order_updates toneMint
class node_purchase_create,node_purchase_updates toneRose
class node_voice_ui,node_voice_commands,node_speech_provider,node_transcription_api,node_speech_service,node_customer,node_shopkeeper,node_distributor toneIndigo
class node_activity toneTeal
```

## Components

### Application experience

- [Role dashboards](https://github.com/phk006/bolovyapaari/blob/main/src/components/dashboard-client.tsx): `src/components/dashboard-client.tsx`

### Role and session

- [Session API](https://github.com/phk006/bolovyapaari/blob/main/src/app/api/session/route.ts): `src/app/api/session/route.ts`
- [Signed sessions](https://github.com/phk006/bolovyapaari/blob/main/src/lib/auth/session.ts): `src/lib/auth/session.ts`
- [Role checks](https://github.com/phk006/bolovyapaari/blob/main/src/lib/auth/require-role.ts): `src/lib/auth/require-role.ts`

### Customer commerce

- [Catalogue and orders](https://github.com/phk006/bolovyapaari/blob/main/src/app/api/dashboard/route.ts): `src/app/api/dashboard/route.ts`
- [Order creation](https://github.com/phk006/bolovyapaari/blob/main/src/app/api/orders/route.ts): `src/app/api/orders/route.ts`
- [Order updates](https://github.com/phk006/bolovyapaari/blob/main/src/app/api/orders/%5Bid%5D/route.ts): `src/app/api/orders/[id]/route.ts`

### Wholesale replenishment

- [Replenishment requests](https://github.com/phk006/bolovyapaari/blob/main/src/app/api/purchase-orders/route.ts): `src/app/api/purchase-orders/route.ts`
- [Wholesale lifecycle](https://github.com/phk006/bolovyapaari/blob/main/src/app/api/purchase-orders/%5Bid%5D/route.ts): `src/app/api/purchase-orders/[id]/route.ts`

### Voice input

- [Voice assistant UI](https://github.com/phk006/bolovyapaari/blob/main/src/components/voice-assistant.tsx): `src/components/voice-assistant.tsx`
- [Voice command parser](https://github.com/phk006/bolovyapaari/blob/main/src/lib/customer-voice-commands.ts): `src/lib/customer-voice-commands.ts`
- [Local Whisper client](https://github.com/phk006/bolovyapaari/blob/main/src/lib/speech-to-text/providers/local-whisper.ts): `src/lib/speech-to-text/providers/local-whisper.ts`
- [Transcription API](https://github.com/phk006/bolovyapaari/blob/main/src/app/api/speech-transcribe/route.ts): `src/app/api/speech-transcribe/route.ts`
- [Whisper service](https://github.com/phk006/bolovyapaari/blob/main/speech-service/app/main.py): `speech-service/app/main.py`

### Other components

- **Customer**
- **Shopkeeper**
- **Distributor**
- [PostgreSQL commerce data](https://github.com/phk006/bolovyapaari/blob/main/db/init/001_schema.sql): `db/init/001_schema.sql`
- [Database transactions](https://github.com/phk006/bolovyapaari/blob/main/src/lib/db.ts): `src/lib/db.ts`
- [Activity logging](https://github.com/phk006/bolovyapaari/blob/main/src/lib/activity.ts): `src/lib/activity.ts`

## Connections

- Customer → Role dashboards: uses storefront (evidence: `README.md`)
- Shopkeeper → Role dashboards: uses workspace (evidence: `README.md`)
- Distributor → Role dashboards: uses workspace (evidence: `README.md`)
- Role dashboards → Session API: loads session (evidence: `src/components/dashboard-client.tsx`)
- Session API → Signed sessions: reads session (evidence: `src/app/api/session/route.ts`)
- Session API → Database transactions: queries users (evidence: `src/app/api/session/route.ts`)
- Role checks → Signed sessions: validates role (evidence: `src/lib/auth/require-role.ts`)
- Role dashboards → Catalogue and orders: loads dashboard
- Role dashboards → Order creation: submits basket
- Role dashboards → Order updates: updates orders
- Order creation → Role checks: checks customer (evidence: `src/app/api/orders/route.ts`)
- Order creation → Database transactions: writes order (evidence: `src/app/api/orders/route.ts`)
- Order creation → Activity logging: logs order (evidence: `src/app/api/orders/route.ts`)
- Order updates → Database transactions: updates order (evidence: `src/app/api/orders/[id]/route.ts`)
- Order updates → Activity logging: logs update (evidence: `src/app/api/orders/[id]/route.ts`)
- Role dashboards → Replenishment requests: requests stock
- Role dashboards → Wholesale lifecycle: manages replenishment
- Replenishment requests → Role checks: checks shopkeeper (evidence: `src/app/api/purchase-orders/route.ts`)
- Replenishment requests → Database transactions: creates request (evidence: `src/app/api/purchase-orders/route.ts`)
- Replenishment requests → Activity logging: logs request (evidence: `src/app/api/purchase-orders/route.ts`)
- Wholesale lifecycle → Role checks: checks role (evidence: `src/app/api/purchase-orders/[id]/route.ts`)
- Wholesale lifecycle → Database transactions: updates lifecycle (evidence: `src/app/api/purchase-orders/[id]/route.ts`)
- Wholesale lifecycle → Activity logging: logs changes (evidence: `src/app/api/purchase-orders/[id]/route.ts`)
- Database transactions → PostgreSQL commerce data: reads and writes (evidence: `src/lib/db.ts`)
- Role dashboards → Voice assistant UI: renders assistant (evidence: `src/components/dashboard-client.tsx`)
- Voice assistant UI → Local Whisper client: captures speech (evidence: `src/components/voice-assistant.tsx`)
- Voice assistant UI → Voice command parser: submits command (evidence: `src/components/dashboard-client.tsx`)
- Local Whisper client → Transcription API: sends audio (evidence: `README.md`)
- Transcription API → Role checks: checks role (evidence: `src/app/api/speech-transcribe/route.ts`)
- Transcription API → Whisper service: forwards audio (evidence: `src/app/api/speech-transcribe/route.ts`)
