# indra2215/razorpay architecture

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

- Interactive diagram: https://gitdiagram.com/indra2215/razorpay
- Repository: https://github.com/indra2215/razorpay

## Overview

The Payment State Recovery Engine is a FastAPI/SQLite service with a dashboard for investigating payment-state drift and safely handling repairs. Its main workflow is to expose a case, reconstruct its evidence timeline, obtain a typed diagnosis, then pass any proposed action through deterministic invariant and idempotency checks before execution and audit. Separate capabilities include synthetic scenario seeding, batch evaluation, Razorpay order creation, and signed webhook ingestion. The excerpts establish the API orchestration and core decision boundaries; some timeline, evaluation, and UI internals were not shown, so those relationships are limited to documented behavior.

Main entry points: [`app/main.py`](https://github.com/indra2215/razorpay/blob/main/app/main.py) (FastAPI service), [`app/repair.py`](https://github.com/indra2215/razorpay/blob/main/app/repair.py) (Deterministic repair gate), [`app/db.py`](https://github.com/indra2215/razorpay/blob/main/app/db.py) (SQLite ledger), [`app/ai.py`](https://github.com/indra2215/razorpay/blob/main/app/ai.py) (Typed diagnosis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and dashboard"]
  node_api["FastAPI service<br/>[main.py]"]
  node_dashboard["Case dashboard<br/>[index.html]"]
  node_evaluation["Batch evaluation<br/>[main.py]"]
end

subgraph group_analysis["Evidence and diagnosis"]
  node_timeline["Case timeline<br/>[main.py]"]
  node_diagnosis["Typed diagnosis<br/>[ai.py]"]
end

subgraph group_safety["Repair safety"]
  node_domain["Scenarios and invariants<br/>[domain.py]"]
  node_repair["Deterministic repair gate<br/>[repair.py]"]
  node_ledger[("SQLite ledger<br/>[db.py]")]
end

subgraph group_integrations["Payment integrations"]
  node_orders["Order creation<br/>[main.py]"]
  node_webhooks["Webhook ingestion<br/>[main.py]"]
end

node_merchant(("Merchant user"))
node_razorpay{{"Razorpay"}}
node_model{{"OpenAI-compatible model"}}

node_merchant -->|"uses"| node_api
node_api -->|"serves"| node_dashboard
node_api -->|"reconstructs"| node_timeline
node_timeline -.->|"reads evidence"| node_ledger
node_api -->|"requests diagnosis"| node_diagnosis
node_diagnosis -->|"requests diagnosis"| node_model
node_api -->|"submits action"| node_repair
node_repair -->|"checks invariants"| node_domain
node_repair -->|"records repair"| node_ledger
node_api -->|"reads and writes"| node_ledger
node_api -->|"runs batch"| node_evaluation
node_evaluation -.->|"diagnoses cases"| node_diagnosis
node_evaluation -.->|"tests repairs"| node_repair
node_api -->|"routes request"| node_orders
node_orders -->|"creates order"| node_razorpay
node_razorpay -.->|"sends events"| node_webhooks
node_webhooks -->|"stores event"| node_ledger

click node_api "https://github.com/indra2215/razorpay/blob/main/app/main.py"
click node_dashboard "https://github.com/indra2215/razorpay/blob/main/static/index.html"
click node_evaluation "https://github.com/indra2215/razorpay/blob/main/app/main.py"
click node_timeline "https://github.com/indra2215/razorpay/blob/main/app/main.py"
click node_diagnosis "https://github.com/indra2215/razorpay/blob/main/app/ai.py"
click node_domain "https://github.com/indra2215/razorpay/blob/main/app/domain.py"
click node_repair "https://github.com/indra2215/razorpay/blob/main/app/repair.py"
click node_ledger "https://github.com/indra2215/razorpay/blob/main/app/db.py"
click node_orders "https://github.com/indra2215/razorpay/blob/main/app/main.py"
click node_webhooks "https://github.com/indra2215/razorpay/blob/main/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_api,node_dashboard,node_evaluation,node_merchant toneBlue
class node_timeline,node_diagnosis toneAmber
class node_domain,node_repair,node_ledger toneMint
class node_orders,node_webhooks toneRose
class node_razorpay,node_model toneIndigo
```

## Components

### API and dashboard

- [FastAPI service](https://github.com/indra2215/razorpay/blob/main/app/main.py): `app/main.py`
- [Case dashboard](https://github.com/indra2215/razorpay/blob/main/static/index.html): `static/index.html`
- [Batch evaluation](https://github.com/indra2215/razorpay/blob/main/app/main.py): `app/main.py`

### Evidence and diagnosis

- [Case timeline](https://github.com/indra2215/razorpay/blob/main/app/main.py): `app/main.py`
- [Typed diagnosis](https://github.com/indra2215/razorpay/blob/main/app/ai.py): `app/ai.py`

### Repair safety

- [Scenarios and invariants](https://github.com/indra2215/razorpay/blob/main/app/domain.py): `app/domain.py`
- [Deterministic repair gate](https://github.com/indra2215/razorpay/blob/main/app/repair.py): `app/repair.py`
- [SQLite ledger](https://github.com/indra2215/razorpay/blob/main/app/db.py): `app/db.py`

### Payment integrations

- [Order creation](https://github.com/indra2215/razorpay/blob/main/app/main.py): `app/main.py`
- [Webhook ingestion](https://github.com/indra2215/razorpay/blob/main/app/main.py): `app/main.py`

### Other components

- **Merchant user**
- **Razorpay**
- **OpenAI-compatible model**

## Connections

- Merchant user → FastAPI service: uses (evidence: `README.md`)
- FastAPI service → Case dashboard: serves (evidence: `README.md`)
- FastAPI service → Case timeline: reconstructs (evidence: `app/main.py`)
- Case timeline → SQLite ledger: reads evidence (evidence: `app/main.py`)
- FastAPI service → Typed diagnosis: requests diagnosis (evidence: `app/main.py`)
- Typed diagnosis → OpenAI-compatible model: requests diagnosis (evidence: `app/ai.py`)
- FastAPI service → Deterministic repair gate: submits action (evidence: `app/main.py`)
- Deterministic repair gate → Scenarios and invariants: checks invariants (evidence: `app/repair.py`)
- Deterministic repair gate → SQLite ledger: records repair (evidence: `app/repair.py`)
- FastAPI service → SQLite ledger: reads and writes (evidence: `app/main.py`)
- FastAPI service → Batch evaluation: runs batch (evidence: `README.md`)
- Batch evaluation → Typed diagnosis: diagnoses cases (evidence: `app/main.py`)
- Batch evaluation → Deterministic repair gate: tests repairs (evidence: `app/main.py`)
- FastAPI service → Order creation: routes request (evidence: `app/main.py`)
- Order creation → Razorpay: creates order (evidence: `app/main.py`)
- Razorpay → Webhook ingestion: sends events (evidence: `README.md`)
- Webhook ingestion → SQLite ledger: stores event (evidence: `app/main.py`)
