# pushkarjain93/ledgr architecture

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

- Interactive diagram: https://gitdiagram.com/pushkarjain93/ledgr
- Repository: https://github.com/pushkarjain93/ledgr

## Overview

Ledgr is an AI-assisted reconciliation product for e-commerce merchants. A reviewer signs in, syncs merchant records, and receives a deterministic reconciliation; unresolved records become persistent cases for AI-assisted investigation and human review. Reviewers can add notes, request evidence, and draft—but not send—messages. The frontend also presents dashboards, reports, transactions, and settings. Backend orchestration details are limited because api.py was not sampled; those links rely on the README’s architecture description.

Main entry points: [`api.py`](https://github.com/pushkarjain93/ledgr/blob/main/api.py) (HTTP orchestration), [`frontend/src/App.tsx`](https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/App.tsx) (Ledgr web app), [`frontend/src/lib/api.ts`](https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/lib/api.ts) (Typed API client), [`case_engine.py`](https://github.com/pushkarjain93/ledgr/blob/main/case_engine.py) (Case lifecycle and AI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Merchant interface"]
  node_frontend["Ledgr web app<br/>[App.tsx]"]
  node_appstate["Session and app state<br/>[AppContext.tsx]"]
  node_api_client["Typed API client<br/>[api.ts]"]
  node_workspaces["Reconciliation views"]
  node_case_review["Case review<br/>[CaseDetailPage.tsx]"]
  node_reports["Reports and metrics<br/>[ReportsPage.tsx]"]
  node_transactions["Transactions view"]
end

subgraph group_transport["API and access"]
  node_api["HTTP orchestration<br/>[api.py]"]
  node_auth["Demo authentication<br/>[auth.py]"]
end

subgraph group_recon["Reconciliation domain"]
  node_matching["Tiered matching<br/>[engine.py]"]
  node_remittance["COD remittance join<br/>[remittance.py]"]
end

subgraph group_investigation["Case investigation"]
  node_case_engine["Case lifecycle and AI<br/>[case_engine.py]"]
  node_ai_client["AI provider failover<br/>[ai_client.py]"]
end

subgraph group_persistence["State and providers"]
  node_state[("Merchant state store<br/>[state_store.py]")]
  node_shopify["Shopify integration<br/>[shopify_client.py]"]
  node_razorpay["Razorpay integration<br/>[razorpay_client.py]"]
  node_disk[("JSON state files")]
end

node_merchant(("Merchant reviewer"))
node_providers{{"AI providers"}}

node_merchant -->|"uses"| node_frontend
node_frontend -->|"hosts"| node_appstate
node_appstate -->|"requests data"| node_api_client
node_frontend -->|"routes to"| node_workspaces
node_frontend -->|"routes to"| node_case_review
node_frontend -->|"routes to"| node_reports
node_frontend -->|"routes to"| node_transactions
node_reports -->|"fetches reports"| node_api_client
node_case_review -->|"loads case"| node_api_client
node_api_client -->|"HTTP JSON"| node_api
node_api -.->|"authenticates"| node_auth
node_api -->|"orchestrates matching"| node_matching
node_api -->|"orchestrates cases"| node_case_engine
node_matching -.->|"COD matching"| node_remittance
node_case_engine -->|"investigates cases"| node_ai_client
node_case_engine -->|"persists cases"| node_state
node_api -->|"reads merchant state"| node_state
node_state -->|"stores JSON"| node_disk
node_api -.->|"syncs store data"| node_shopify
node_api -.->|"syncs settlements"| node_razorpay
node_ai_client -->|"fails over"| node_providers

click node_frontend "https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/App.tsx"
click node_appstate "https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/context/AppContext.tsx"
click node_api_client "https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/lib/api.ts"
click node_workspaces "https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/pages/ReconciliationsPage.tsx"
click node_case_review "https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/pages/CaseDetailPage.tsx"
click node_reports "https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/pages/ReportsPage.tsx"
click node_transactions "https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/pages/TransactionsPage.tsx"
click node_api "https://github.com/pushkarjain93/ledgr/blob/main/api.py"
click node_auth "https://github.com/pushkarjain93/ledgr/blob/main/auth.py"
click node_matching "https://github.com/pushkarjain93/ledgr/blob/main/engine.py"
click node_remittance "https://github.com/pushkarjain93/ledgr/blob/main/remittance.py"
click node_case_engine "https://github.com/pushkarjain93/ledgr/blob/main/case_engine.py"
click node_ai_client "https://github.com/pushkarjain93/ledgr/blob/main/ai_client.py"
click node_state "https://github.com/pushkarjain93/ledgr/blob/main/state_store.py"
click node_shopify "https://github.com/pushkarjain93/ledgr/blob/main/shopify_client.py"
click node_razorpay "https://github.com/pushkarjain93/ledgr/blob/main/razorpay_client.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_frontend,node_appstate,node_api_client,node_workspaces,node_case_review,node_reports,node_transactions,node_merchant toneBlue
class node_api,node_auth toneAmber
class node_matching,node_remittance toneMint
class node_case_engine,node_ai_client toneRose
class node_state,node_shopify,node_razorpay,node_disk,node_providers toneIndigo
```

## Components

### Merchant interface

- [Ledgr web app](https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Session and app state](https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/context/AppContext.tsx): `frontend/src/context/AppContext.tsx`
- [Typed API client](https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`
- [Reconciliation views](https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/pages/ReconciliationsPage.tsx): `frontend/src/pages/ReconciliationsPage.tsx`
- [Case review](https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/pages/CaseDetailPage.tsx): `frontend/src/pages/CaseDetailPage.tsx`
- [Reports and metrics](https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/pages/ReportsPage.tsx): `frontend/src/pages/ReportsPage.tsx`
- [Transactions view](https://github.com/pushkarjain93/ledgr/blob/main/frontend/src/pages/TransactionsPage.tsx): `frontend/src/pages/TransactionsPage.tsx`

### API and access

- [HTTP orchestration](https://github.com/pushkarjain93/ledgr/blob/main/api.py): `api.py`
- [Demo authentication](https://github.com/pushkarjain93/ledgr/blob/main/auth.py): `auth.py`

### Reconciliation domain

- [Tiered matching](https://github.com/pushkarjain93/ledgr/blob/main/engine.py): `engine.py`
- [COD remittance join](https://github.com/pushkarjain93/ledgr/blob/main/remittance.py): `remittance.py`

### Case investigation

- [Case lifecycle and AI](https://github.com/pushkarjain93/ledgr/blob/main/case_engine.py): `case_engine.py`
- [AI provider failover](https://github.com/pushkarjain93/ledgr/blob/main/ai_client.py): `ai_client.py`

### State and providers

- [Merchant state store](https://github.com/pushkarjain93/ledgr/blob/main/state_store.py): `state_store.py`
- [Shopify integration](https://github.com/pushkarjain93/ledgr/blob/main/shopify_client.py): `shopify_client.py`
- [Razorpay integration](https://github.com/pushkarjain93/ledgr/blob/main/razorpay_client.py): `razorpay_client.py`
- **JSON state files**

### Other components

- **Merchant reviewer**
- **AI providers**

## Connections

- Merchant reviewer → Ledgr web app: uses
- Ledgr web app → Session and app state: hosts (evidence: `frontend/src/App.tsx`)
- Session and app state → Typed API client: requests data (evidence: `frontend/src/context/AppContext.tsx`)
- Ledgr web app → Reconciliation views: routes to (evidence: `frontend/src/App.tsx`)
- Ledgr web app → Case review: routes to (evidence: `frontend/src/App.tsx`)
- Ledgr web app → Reports and metrics: routes to (evidence: `frontend/src/App.tsx`)
- Ledgr web app → Transactions view: routes to (evidence: `frontend/src/App.tsx`)
- Reports and metrics → Typed API client: fetches reports (evidence: `frontend/src/pages/ReportsPage.tsx`)
- Case review → Typed API client: loads case (evidence: `frontend/src/pages/CaseDetailPage.tsx`)
- Typed API client → HTTP orchestration: HTTP JSON
- HTTP orchestration → Demo authentication: authenticates
- HTTP orchestration → Tiered matching: orchestrates matching
- HTTP orchestration → Case lifecycle and AI: orchestrates cases
- Tiered matching → COD remittance join: COD matching
- Case lifecycle and AI → AI provider failover: investigates cases (evidence: `case_engine.py`)
- Case lifecycle and AI → Merchant state store: persists cases (evidence: `case_engine.py`)
- HTTP orchestration → Merchant state store: reads merchant state
- Merchant state store → JSON state files: stores JSON
- HTTP orchestration → Shopify integration: syncs store data
- HTTP orchestration → Razorpay integration: syncs settlements
- AI provider failover → AI providers: fails over (evidence: `ai_client.py`)
