# navj62/elekhajokha architecture

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

- Interactive diagram: https://gitdiagram.com/navj62/elekhajokha
- Repository: https://github.com/navj62/elekhajokha

## Overview

E-Lekha-Jokha is a multi-tenant pledge-shop SaaS. Shop staff authenticate, record customers and jewellery-backed loans, track interest and LTV risk, then release or sell pledges; acquired items can enter inventory. Owners also review operational analytics, reports, notifications and tasks, while customers can view a read-only portal. Access depends on a Razorpay subscription. The graph combines documented product capabilities with sampled routes and UI modules; several domain-to-route links are dashed where implementation wiring was not excerpted.

Main entry points: [`lib/prisma.ts`](https://github.com/navj62/elekhajokha/blob/main/lib/prisma.ts) (Prisma client), [`lib/calculateLTV.ts`](https://github.com/navj62/elekhajokha/blob/main/lib/calculateLTV.ts) (Interest and LTV), [`app/api/access/route.ts`](https://github.com/navj62/elekhajokha/blob/main/app/api/access/route.ts) (Access service), [`app/api/customers/[customerId]/pledges`](https://github.com/navj62/elekhajokha/tree/main/app/api/customers/%5BcustomerId%5D/pledges) (Pledge services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Identity and access"]
  node_subscription_ui["Subscription guard"]
  node_access_api["Access service<br/>[route.ts]"]
end

subgraph group_pledges["Customer pledges"]
  node_customers_ui["Customer workspace"]
  node_pledge_api["Pledge services"]
  node_pledge_math["Interest and LTV<br/>[calculateLTV.ts]"]
  node_portal["Customer portal<br/>[page.tsx]"]
end

subgraph group_operations["Shop operations"]
  node_inventory_ui["Inventory workspace"]
  node_inventory_api["Inventory services<br/>[route.ts]"]
  node_tasks["Tasks and notices"]
  node_notifications["Notification services<br/>[route.ts]"]
end

subgraph group_insights["Analytics and reporting"]
  node_dashboard["Shop dashboard<br/>[page.tsx]"]
  node_reports["Reports"]
  node_risk_job["Risk evaluation<br/>[route.ts]"]
  node_price_job["Metal price updates<br/>[route.ts]"]
end

subgraph group_platform["Persistence and integrations"]
  node_clerk{{"Clerk identity"}}
  node_razorpay{{"Razorpay billing"}}
  node_cloudinary{{"Cloudinary media"}}
  node_database[("PostgreSQL")]
  node_prisma["Prisma client<br/>[prisma.ts]"]
end

node_staff(("Shop staff"))

node_staff -->|"manages customers"| node_customers_ui
node_customers_ui -.->|"manages pledges"| node_pledge_api
node_pledge_api -->|"queries data"| node_prisma
node_prisma -->|"persists records"| node_database
node_pledge_api -.->|"uses valuation"| node_pledge_math
node_pledge_api -.->|"records pledge sales"| node_inventory_api
node_customers_ui -.->|"shares customer view"| node_portal
node_portal -->|"reads pledge data"| node_prisma
node_portal -->|"calculates interest"| node_pledge_math
node_staff -->|"manages inventory"| node_inventory_ui
node_inventory_ui -.->|"loads inventory"| node_inventory_api
node_inventory_api -->|"stores inventory"| node_prisma
node_inventory_api -->|"uploads photos"| node_cloudinary
node_staff -->|"tracks work"| node_tasks
node_staff -->|"reviews shop"| node_dashboard
node_dashboard -.->|"loads snapshot"| node_prisma
node_dashboard -.->|"shows risk"| node_pledge_math
node_dashboard -.->|"opens reports"| node_reports
node_staff -->|"reviews reports"| node_reports
node_risk_job -->|"evaluates LTV"| node_pledge_math
node_risk_job -->|"reads pledges"| node_prisma
node_risk_job -.->|"creates alerts"| node_notifications
node_price_job -.->|"updates valuations"| node_pledge_math
node_staff -->|"checks access"| node_subscription_ui
node_subscription_ui -.->|"requests access"| node_access_api
node_subscription_ui -->|"checks identity"| node_clerk
node_access_api -->|"authenticates user"| node_clerk
node_access_api -->|"checks subscription"| node_razorpay
node_access_api -->|"reads subscription"| node_prisma
node_notifications -->|"reads alerts"| node_prisma

click node_customers_ui "https://github.com/navj62/elekhajokha/tree/main/app/(CustomersDetails)"
click node_pledge_api "https://github.com/navj62/elekhajokha/tree/main/app/api/customers/%5BcustomerId%5D/pledges"
click node_pledge_math "https://github.com/navj62/elekhajokha/blob/main/lib/calculateLTV.ts"
click node_portal "https://github.com/navj62/elekhajokha/blob/main/app/view/%5Btoken%5D/page.tsx"
click node_inventory_ui "https://github.com/navj62/elekhajokha/tree/main/app/(UserDetails)/inventory"
click node_inventory_api "https://github.com/navj62/elekhajokha/blob/main/app/api/inventory/route.ts"
click node_tasks "https://github.com/navj62/elekhajokha/tree/main/app/(UserDetails)/tasks"
click node_notifications "https://github.com/navj62/elekhajokha/blob/main/app/api/notifications/route.ts"
click node_dashboard "https://github.com/navj62/elekhajokha/blob/main/app/(UserDetails)/dashboard/page.tsx"
click node_reports "https://github.com/navj62/elekhajokha/tree/main/app/reports"
click node_risk_job "https://github.com/navj62/elekhajokha/blob/main/app/api/cron/evaluate-risk/route.ts"
click node_price_job "https://github.com/navj62/elekhajokha/blob/main/app/api/cron/update-prices/route.ts"
click node_subscription_ui "https://github.com/navj62/elekhajokha/blob/main/components/SubscriptionGuard.tsx"
click node_access_api "https://github.com/navj62/elekhajokha/blob/main/app/api/access/route.ts"
click node_prisma "https://github.com/navj62/elekhajokha/blob/main/lib/prisma.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_subscription_ui,node_access_api toneBlue
class node_customers_ui,node_pledge_api,node_pledge_math,node_portal toneAmber
class node_inventory_ui,node_inventory_api,node_tasks,node_notifications toneMint
class node_dashboard,node_reports,node_risk_job,node_price_job toneRose
class node_clerk,node_razorpay,node_cloudinary,node_database,node_prisma,node_staff toneIndigo
```

## Components

### Identity and access

- [Subscription guard](https://github.com/navj62/elekhajokha/blob/main/components/SubscriptionGuard.tsx): `components/SubscriptionGuard.tsx`
- [Access service](https://github.com/navj62/elekhajokha/blob/main/app/api/access/route.ts): `app/api/access/route.ts`

### Customer pledges

- [Customer workspace](https://github.com/navj62/elekhajokha/tree/main/app/(CustomersDetails)): `app/(CustomersDetails)`
- [Pledge services](https://github.com/navj62/elekhajokha/tree/main/app/api/customers/%5BcustomerId%5D/pledges): `app/api/customers/[customerId]/pledges`
- [Interest and LTV](https://github.com/navj62/elekhajokha/blob/main/lib/calculateLTV.ts): `lib/calculateLTV.ts`
- [Customer portal](https://github.com/navj62/elekhajokha/blob/main/app/view/%5Btoken%5D/page.tsx): `app/view/[token]/page.tsx`

### Shop operations

- [Inventory workspace](https://github.com/navj62/elekhajokha/tree/main/app/(UserDetails)/inventory): `app/(UserDetails)/inventory`
- [Inventory services](https://github.com/navj62/elekhajokha/blob/main/app/api/inventory/route.ts): `app/api/inventory/route.ts`
- [Tasks and notices](https://github.com/navj62/elekhajokha/tree/main/app/(UserDetails)/tasks): `app/(UserDetails)/tasks`
- [Notification services](https://github.com/navj62/elekhajokha/blob/main/app/api/notifications/route.ts): `app/api/notifications/route.ts`

### Analytics and reporting

- [Shop dashboard](https://github.com/navj62/elekhajokha/blob/main/app/(UserDetails)/dashboard/page.tsx): `app/(UserDetails)/dashboard/page.tsx`
- [Reports](https://github.com/navj62/elekhajokha/tree/main/app/reports): `app/reports`
- [Risk evaluation](https://github.com/navj62/elekhajokha/blob/main/app/api/cron/evaluate-risk/route.ts): `app/api/cron/evaluate-risk/route.ts`
- [Metal price updates](https://github.com/navj62/elekhajokha/blob/main/app/api/cron/update-prices/route.ts): `app/api/cron/update-prices/route.ts`

### Persistence and integrations

- **Clerk identity**
- **Razorpay billing**
- **Cloudinary media**
- **PostgreSQL**
- [Prisma client](https://github.com/navj62/elekhajokha/blob/main/lib/prisma.ts): `lib/prisma.ts`

### Other components

- **Shop staff**

## Connections

- Shop staff → Customer workspace: manages customers (evidence: `README.md`)
- Customer workspace → Pledge services: manages pledges
- Pledge services → Prisma client: queries data
- Prisma client → PostgreSQL: persists records (evidence: `lib/prisma.ts`)
- Pledge services → Interest and LTV: uses valuation
- Pledge services → Inventory services: records pledge sales
- Customer workspace → Customer portal: shares customer view
- Customer portal → Prisma client: reads pledge data (evidence: `app/view/[token]/page.tsx`)
- Customer portal → Interest and LTV: calculates interest (evidence: `app/view/[token]/page.tsx`)
- Shop staff → Inventory workspace: manages inventory (evidence: `README.md`)
- Inventory workspace → Inventory services: loads inventory
- Inventory services → Prisma client: stores inventory (evidence: `app/api/inventory/route.ts`)
- Inventory services → Cloudinary media: uploads photos (evidence: `app/api/inventory/route.ts`)
- Shop staff → Tasks and notices: tracks work (evidence: `README.md`)
- Shop staff → Shop dashboard: reviews shop (evidence: `README.md`)
- Shop dashboard → Prisma client: loads snapshot
- Shop dashboard → Interest and LTV: shows risk
- Shop dashboard → Reports: opens reports
- Shop staff → Reports: reviews reports (evidence: `README.md`)
- Risk evaluation → Interest and LTV: evaluates LTV (evidence: `app/api/cron/evaluate-risk/route.ts`)
- Risk evaluation → Prisma client: reads pledges (evidence: `app/api/cron/evaluate-risk/route.ts`)
- Risk evaluation → Notification services: creates alerts
- Metal price updates → Interest and LTV: updates valuations
- Shop staff → Subscription guard: checks access (evidence: `README.md`)
- Subscription guard → Access service: requests access
- Subscription guard → Clerk identity: checks identity
- Access service → Clerk identity: authenticates user (evidence: `app/api/access/route.ts`)
- Access service → Razorpay billing: checks subscription (evidence: `app/api/access/route.ts`)
- Access service → Prisma client: reads subscription (evidence: `app/api/access/route.ts`)
- Notification services → Prisma client: reads alerts (evidence: `app/api/notifications/route.ts`)
