# muneeb0346/d-khata architecture

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

- Interactive diagram: https://gitdiagram.com/muneeb0346/d-khata
- Repository: https://github.com/muneeb0346/d-khata

## Overview

D-Khata is a merchant-facing credit ledger with a customer-facing transaction-consensus flow. Merchants register customers, record credit, and share a customer-specific ledger link; customers verify or reject pending entries, and the ledger enforces a lock until resolution. The graph includes the main dashboard and public ledger, domain actions, and persistence/reconciliation. Several documented capabilities are represented at directory level where implementation excerpts were unavailable; those relationships are omitted unless the README or sampled source supports them.

Main entry points: [`src/server/actions.ts`](https://github.com/muneeb0346/d-khata/blob/main/src/server/actions.ts) (Server action exports), [`src/app/page.tsx`](https://github.com/muneeb0346/d-khata/blob/main/src/app/page.tsx) (Dashboard), [`src/components/dashboard/LedgerViewContent.tsx`](https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/LedgerViewContent.tsx) (Ledger details), [`src/server/actions/customer.ts`](https://github.com/muneeb0346/d-khata/blob/main/src/server/actions/customer.ts) (Customer actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_merchant["Merchant dashboard"]
  node_dashboard["Dashboard<br/>[page.tsx]"]
  node_customer_list["Customer list<br/>[CustomerList.tsx]"]
  node_customer_form["Customer form"]
  node_active_ledger["Active ledger view"]
  node_ledger_view["Ledger details"]
  node_ledger_forms["Ledger forms"]
  node_credit_form["Credit entry form<br/>[AddCreditForm.tsx]"]
  node_payment_form["Payment form<br/>[ReceivePayForm.tsx]"]
  node_delete_flow["Customer deletion"]
  node_share_hook["WhatsApp sharing"]
end

subgraph group_customer["Customer ledger"]
  node_public_ledger["Public ledger page<br/>[page.tsx]"]
  node_transactions["Transaction history"]
  node_balance_graph["Balance graph<br/>[BalanceGraph.tsx]"]
end

subgraph group_server["Domain operations"]
  node_action_barrel["Server action exports<br/>[actions.ts]"]
  node_customer_actions["Customer actions<br/>[customer.ts]"]
  node_ledger_actions["Ledger actions<br/>[ledger.ts]"]
end

subgraph group_data["Persistence and logic"]
  node_database[("PostgreSQL database<br/>[index.ts]")]
  node_schema["Data schema<br/>[schema.ts]"]
  node_reconcile["Ledger reconciliation<br/>[reconcile.ts]"]
  node_validation["Input validation<br/>[validation.ts]"]
  node_schemas["Action schemas<br/>[schemas.ts]"]
  node_formatters["Input and balance formatting<br/>[formatters.ts]"]
end

node_merchant_actor(("Merchant"))
node_whatsapp(("WhatsApp"))
node_customer_actor(("Customer"))

node_merchant_actor -->|"uses"| node_dashboard
node_dashboard -->|"renders"| node_customer_list
node_dashboard -->|"renders"| node_customer_form
node_dashboard -->|"opens"| node_active_ledger
node_dashboard -->|"fetches customers"| node_action_barrel
node_customer_form -->|"creates or edits"| node_action_barrel
node_customer_form -->|"formats input"| node_formatters
node_active_ledger -->|"renders"| node_ledger_view
node_active_ledger -->|"uses"| node_share_hook
node_share_hook -->|"shares link"| node_whatsapp
node_ledger_view -->|"renders"| node_transactions
node_ledger_view -->|"renders"| node_balance_graph
node_ledger_view -->|"opens forms"| node_ledger_forms
node_ledger_view -->|"renders"| node_delete_flow
node_ledger_forms -->|"renders"| node_credit_form
node_ledger_forms -->|"renders"| node_payment_form
node_ledger_forms -->|"submits actions"| node_action_barrel
node_delete_flow -->|"deletes customer"| node_action_barrel
node_customer_actor -->|"opens shared link"| node_public_ledger
node_public_ledger -->|"loads and resolves"| node_action_barrel
node_public_ledger -->|"renders"| node_transactions
node_public_ledger -->|"renders"| node_balance_graph
node_action_barrel -->|"exports"| node_customer_actions
node_action_barrel -->|"exports"| node_ledger_actions
node_customer_actions -->|"reads and writes"| node_database
node_customer_actions -->|"uses tables"| node_schema
node_customer_actions -->|"validates input"| node_validation
node_customer_actions -->|"uses schemas"| node_schemas
node_ledger_actions -->|"reads and writes"| node_database
node_ledger_actions -->|"uses tables"| node_schema
node_ledger_actions -->|"reconciles balances"| node_reconcile
node_ledger_actions -->|"validates actions"| node_schemas
node_database -->|"initializes tables"| node_schema

click node_dashboard "https://github.com/muneeb0346/d-khata/blob/main/src/app/page.tsx"
click node_customer_list "https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/CustomerList.tsx"
click node_customer_form "https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/NewCustomerForm.tsx"
click node_active_ledger "https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/ActiveLedgerView.tsx"
click node_ledger_view "https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/LedgerViewContent.tsx"
click node_ledger_forms "https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/LedgerFormSheet.tsx"
click node_credit_form "https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/AddCreditForm.tsx"
click node_payment_form "https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/ReceivePayForm.tsx"
click node_delete_flow "https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/DeleteCustomerFlow.tsx"
click node_share_hook "https://github.com/muneeb0346/d-khata/blob/main/src/hooks/useWhatsAppShare.ts"
click node_public_ledger "https://github.com/muneeb0346/d-khata/blob/main/src/app/khata/%5BcustomerId%5D/page.tsx"
click node_transactions "https://github.com/muneeb0346/d-khata/blob/main/src/components/khata/TransactionList.tsx"
click node_balance_graph "https://github.com/muneeb0346/d-khata/blob/main/src/components/charts/BalanceGraph.tsx"
click node_action_barrel "https://github.com/muneeb0346/d-khata/blob/main/src/server/actions.ts"
click node_customer_actions "https://github.com/muneeb0346/d-khata/blob/main/src/server/actions/customer.ts"
click node_ledger_actions "https://github.com/muneeb0346/d-khata/blob/main/src/server/actions/ledger.ts"
click node_database "https://github.com/muneeb0346/d-khata/blob/main/src/server/db/index.ts"
click node_schema "https://github.com/muneeb0346/d-khata/blob/main/src/server/db/schema.ts"
click node_reconcile "https://github.com/muneeb0346/d-khata/blob/main/src/server/db/reconcile.ts"
click node_validation "https://github.com/muneeb0346/d-khata/blob/main/src/server/lib/validation.ts"
click node_schemas "https://github.com/muneeb0346/d-khata/blob/main/src/server/lib/schemas.ts"
click node_formatters "https://github.com/muneeb0346/d-khata/blob/main/src/utils/formatters.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_dashboard,node_customer_list,node_customer_form,node_active_ledger,node_ledger_view,node_ledger_forms,node_credit_form,node_payment_form,node_delete_flow,node_share_hook toneBlue
class node_public_ledger,node_transactions,node_balance_graph toneAmber
class node_action_barrel,node_customer_actions,node_ledger_actions toneMint
class node_database,node_schema,node_reconcile,node_validation,node_schemas,node_formatters toneRose
class node_merchant_actor,node_whatsapp,node_customer_actor toneIndigo
```

## Components

### Merchant dashboard

- [Dashboard](https://github.com/muneeb0346/d-khata/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [Customer list](https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/CustomerList.tsx): `src/components/dashboard/CustomerList.tsx`
- [Customer form](https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/NewCustomerForm.tsx): `src/components/dashboard/NewCustomerForm.tsx`
- [Active ledger view](https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/ActiveLedgerView.tsx): `src/components/dashboard/ActiveLedgerView.tsx`
- [Ledger details](https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/LedgerViewContent.tsx): `src/components/dashboard/LedgerViewContent.tsx`
- [Ledger forms](https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/LedgerFormSheet.tsx): `src/components/dashboard/LedgerFormSheet.tsx`
- [Credit entry form](https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/AddCreditForm.tsx): `src/components/dashboard/AddCreditForm.tsx`
- [Payment form](https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/ReceivePayForm.tsx): `src/components/dashboard/ReceivePayForm.tsx`
- [Customer deletion](https://github.com/muneeb0346/d-khata/blob/main/src/components/dashboard/DeleteCustomerFlow.tsx): `src/components/dashboard/DeleteCustomerFlow.tsx`
- [WhatsApp sharing](https://github.com/muneeb0346/d-khata/blob/main/src/hooks/useWhatsAppShare.ts): `src/hooks/useWhatsAppShare.ts`

### Customer ledger

- [Public ledger page](https://github.com/muneeb0346/d-khata/blob/main/src/app/khata/%5BcustomerId%5D/page.tsx): `src/app/khata/[customerId]/page.tsx`
- [Transaction history](https://github.com/muneeb0346/d-khata/blob/main/src/components/khata/TransactionList.tsx): `src/components/khata/TransactionList.tsx`
- [Balance graph](https://github.com/muneeb0346/d-khata/blob/main/src/components/charts/BalanceGraph.tsx): `src/components/charts/BalanceGraph.tsx`

### Domain operations

- [Server action exports](https://github.com/muneeb0346/d-khata/blob/main/src/server/actions.ts): `src/server/actions.ts`
- [Customer actions](https://github.com/muneeb0346/d-khata/blob/main/src/server/actions/customer.ts): `src/server/actions/customer.ts`
- [Ledger actions](https://github.com/muneeb0346/d-khata/blob/main/src/server/actions/ledger.ts): `src/server/actions/ledger.ts`

### Persistence and logic

- [PostgreSQL database](https://github.com/muneeb0346/d-khata/blob/main/src/server/db/index.ts): `src/server/db/index.ts`
- [Data schema](https://github.com/muneeb0346/d-khata/blob/main/src/server/db/schema.ts): `src/server/db/schema.ts`
- [Ledger reconciliation](https://github.com/muneeb0346/d-khata/blob/main/src/server/db/reconcile.ts): `src/server/db/reconcile.ts`
- [Input validation](https://github.com/muneeb0346/d-khata/blob/main/src/server/lib/validation.ts): `src/server/lib/validation.ts`
- [Action schemas](https://github.com/muneeb0346/d-khata/blob/main/src/server/lib/schemas.ts): `src/server/lib/schemas.ts`
- [Input and balance formatting](https://github.com/muneeb0346/d-khata/blob/main/src/utils/formatters.ts): `src/utils/formatters.ts`

### Other components

- **Merchant**
- **WhatsApp**
- **Customer**

## Connections

- Merchant → Dashboard: uses (evidence: `README.md`)
- Dashboard → Customer list: renders (evidence: `src/app/page.tsx`)
- Dashboard → Customer form: renders (evidence: `src/app/page.tsx`)
- Dashboard → Active ledger view: opens (evidence: `src/app/page.tsx`)
- Dashboard → Server action exports: fetches customers (evidence: `src/app/page.tsx`)
- Customer form → Server action exports: creates or edits (evidence: `src/components/dashboard/NewCustomerForm.tsx`)
- Customer form → Input and balance formatting: formats input (evidence: `src/components/dashboard/NewCustomerForm.tsx`)
- Active ledger view → Ledger details: renders (evidence: `src/components/dashboard/ActiveLedgerView.tsx`)
- Active ledger view → WhatsApp sharing: uses (evidence: `src/components/dashboard/ActiveLedgerView.tsx`)
- WhatsApp sharing → WhatsApp: shares link (evidence: `README.md`)
- Ledger details → Transaction history: renders (evidence: `src/components/dashboard/LedgerViewContent.tsx`)
- Ledger details → Balance graph: renders (evidence: `src/components/dashboard/LedgerViewContent.tsx`)
- Ledger details → Ledger forms: opens forms (evidence: `src/components/dashboard/LedgerViewContent.tsx`)
- Ledger details → Customer deletion: renders (evidence: `src/components/dashboard/LedgerViewContent.tsx`)
- Ledger forms → Credit entry form: renders (evidence: `src/components/dashboard/LedgerFormSheet.tsx`)
- Ledger forms → Payment form: renders (evidence: `src/components/dashboard/LedgerFormSheet.tsx`)
- Ledger forms → Server action exports: submits actions (evidence: `src/components/dashboard/LedgerFormSheet.tsx`)
- Customer deletion → Server action exports: deletes customer (evidence: `src/components/dashboard/DeleteCustomerFlow.tsx`)
- Customer → Public ledger page: opens shared link (evidence: `README.md`)
- Public ledger page → Server action exports: loads and resolves (evidence: `src/app/khata/[customerId]/page.tsx`)
- Public ledger page → Transaction history: renders (evidence: `src/app/khata/[customerId]/page.tsx`)
- Public ledger page → Balance graph: renders (evidence: `src/app/khata/[customerId]/page.tsx`)
- Server action exports → Customer actions: exports (evidence: `src/server/actions.ts`)
- Server action exports → Ledger actions: exports (evidence: `src/server/actions.ts`)
- Customer actions → PostgreSQL database: reads and writes (evidence: `src/server/actions/customer.ts`)
- Customer actions → Data schema: uses tables (evidence: `src/server/actions/customer.ts`)
- Customer actions → Input validation: validates input (evidence: `src/server/actions/customer.ts`)
- Customer actions → Action schemas: uses schemas (evidence: `src/server/actions/customer.ts`)
- Ledger actions → PostgreSQL database: reads and writes (evidence: `src/server/actions/ledger.ts`)
- Ledger actions → Data schema: uses tables (evidence: `src/server/actions/ledger.ts`)
- Ledger actions → Ledger reconciliation: reconciles balances (evidence: `src/server/actions/ledger.ts`)
- Ledger actions → Action schemas: validates actions (evidence: `src/server/actions/ledger.ts`)
- PostgreSQL database → Data schema: initializes tables (evidence: `src/server/db/index.ts`)
