# yashtyagee/pratyavartan architecture

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

- Interactive diagram: https://gitdiagram.com/yashtyagee/pratyavartan
- Repository: https://github.com/yashtyagee/pratyavartan

## Overview

Pratyavartan is an autonomous payment-recovery service for failed merchant transactions, with a FastAPI backend and a Next.js merchant console. Its main workflow ingests and validates failure events, records pending payment state, diagnoses failures, applies compliance stopping rules, then selects recovery, monitoring, or escalation. Successful customer payments return through a signed webhook and update stored state. The console also exposes live audit and recovery information and lets merchants run simulations. Backend orchestration and storage links follow the README architecture; unsampled subsystem wiring is omitted where uncertain.

Main entry points: [`main.py`](https://github.com/yashtyagee/pratyavartan/blob/main/main.py) (API gateway), [`orchestrator.py`](https://github.com/yashtyagee/pratyavartan/blob/main/orchestrator.py) (Recovery orchestrator), [`db.py`](https://github.com/yashtyagee/pratyavartan/blob/main/db.py) (Payment and audit ledger), [`razorpay_service.py`](https://github.com/yashtyagee/pratyavartan/blob/main/razorpay_service.py) (Payment actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_recovery["Recovery workflow"]
  node_backend["API gateway<br/>[main.py]"]
  node_orchestrator["Recovery orchestrator<br/>[orchestrator.py]"]
  node_diagnosis["AI diagnosis<br/>[ai_agent.py]"]
end

subgraph group_state["State and compliance"]
  node_database[("Payment and audit ledger<br/>[db.py]")]
  node_compliance["Compliance gate<br/>[compliance_gate.py]"]
  node_memory["Customer memory<br/>[memory.py]"]
end

subgraph group_integrations["External services"]
  node_payment_ops["Payment actions"]
  node_voice["Voice synthesis<br/>[voice_engine.py]"]
end

subgraph group_console["Merchant console"]
  node_console_page["War room<br/>[page.tsx]"]
  node_console_api["Console data hooks<br/>[console-api.ts]"]
  node_simulation["Simulation playground"]
  node_landing["Product experience<br/>[page.tsx]"]
end

node_merchant(("Merchant"))
node_customer(("Customer"))
node_razorpay{{"Razorpay"}}
node_paytm{{"Paytm"}}
node_speech_provider{{"Sarvam / gTTS"}}
node_payment_links{{"Razorpay APIs"}}

node_razorpay -->|"sends failure webhook"| node_backend
node_paytm -->|"sends callbacks"| node_backend
node_merchant -->|"starts simulations"| node_simulation
node_simulation -->|"calls simulation endpoints"| node_backend
node_backend -->|"records payment state"| node_database
node_backend -->|"starts recovery"| node_orchestrator
node_orchestrator -->|"checks stopping rules"| node_compliance
node_orchestrator -->|"requests diagnosis"| node_diagnosis
node_orchestrator -->|"dispatches recovery actions"| node_payment_ops
node_payment_ops -->|"creates payment links"| node_payment_links
node_payment_ops -->|"logs recovery events"| node_database
node_orchestrator -->|"requests voice outreach"| node_voice
node_voice -->|"synthesizes audio"| node_speech_provider
node_voice -->|"logs voice events"| node_database
node_customer -->|"completes payment"| node_payment_links
node_razorpay -->|"sends signed payment result"| node_backend
node_backend -->|"updates recovered status"| node_database
node_console_page -->|"loads live data"| node_console_api
node_console_api -->|"polls console endpoints"| node_backend
node_merchant -->|"views operations"| node_console_page
node_landing -.->|"links to console"| node_console_page
node_orchestrator -.->|"uses customer context"| node_memory

click node_backend "https://github.com/yashtyagee/pratyavartan/blob/main/main.py"
click node_orchestrator "https://github.com/yashtyagee/pratyavartan/blob/main/orchestrator.py"
click node_diagnosis "https://github.com/yashtyagee/pratyavartan/blob/main/ai_agent.py"
click node_payment_ops "https://github.com/yashtyagee/pratyavartan/blob/main/razorpay_service.py"
click node_voice "https://github.com/yashtyagee/pratyavartan/blob/main/voice_engine.py"
click node_database "https://github.com/yashtyagee/pratyavartan/blob/main/db.py"
click node_compliance "https://github.com/yashtyagee/pratyavartan/blob/main/compliance_gate.py"
click node_memory "https://github.com/yashtyagee/pratyavartan/blob/main/memory.py"
click node_console_page "https://github.com/yashtyagee/pratyavartan/blob/main/revive-site/src/app/console/page.tsx"
click node_console_api "https://github.com/yashtyagee/pratyavartan/blob/main/revive-site/src/lib/console-api.ts"
click node_simulation "https://github.com/yashtyagee/pratyavartan/blob/main/revive-site/src/components/console/simulation-playground.tsx"
click node_landing "https://github.com/yashtyagee/pratyavartan/blob/main/revive-site/src/app/page.tsx"

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_backend,node_orchestrator,node_diagnosis toneBlue
class node_database,node_compliance,node_memory toneAmber
class node_payment_ops,node_voice,node_payment_links toneMint
class node_console_page,node_console_api,node_simulation,node_landing toneRose
class node_merchant,node_customer,node_razorpay,node_paytm,node_speech_provider toneIndigo
```

## Components

### Recovery workflow

- [API gateway](https://github.com/yashtyagee/pratyavartan/blob/main/main.py): `main.py`
- [Recovery orchestrator](https://github.com/yashtyagee/pratyavartan/blob/main/orchestrator.py): `orchestrator.py`
- [AI diagnosis](https://github.com/yashtyagee/pratyavartan/blob/main/ai_agent.py): `ai_agent.py`

### State and compliance

- [Payment and audit ledger](https://github.com/yashtyagee/pratyavartan/blob/main/db.py): `db.py`
- [Compliance gate](https://github.com/yashtyagee/pratyavartan/blob/main/compliance_gate.py): `compliance_gate.py`
- [Customer memory](https://github.com/yashtyagee/pratyavartan/blob/main/memory.py): `memory.py`

### External services

- [Payment actions](https://github.com/yashtyagee/pratyavartan/blob/main/razorpay_service.py): `razorpay_service.py`
- [Voice synthesis](https://github.com/yashtyagee/pratyavartan/blob/main/voice_engine.py): `voice_engine.py`

### Merchant console

- [War room](https://github.com/yashtyagee/pratyavartan/blob/main/revive-site/src/app/console/page.tsx): `revive-site/src/app/console/page.tsx`
- [Console data hooks](https://github.com/yashtyagee/pratyavartan/blob/main/revive-site/src/lib/console-api.ts): `revive-site/src/lib/console-api.ts`
- [Simulation playground](https://github.com/yashtyagee/pratyavartan/blob/main/revive-site/src/components/console/simulation-playground.tsx): `revive-site/src/components/console/simulation-playground.tsx`
- [Product experience](https://github.com/yashtyagee/pratyavartan/blob/main/revive-site/src/app/page.tsx): `revive-site/src/app/page.tsx`

### Other components

- **Merchant**
- **Customer**
- **Razorpay**
- **Paytm**
- **Sarvam / gTTS**
- **Razorpay APIs**

## Connections

- Razorpay → API gateway: sends failure webhook
- Paytm → API gateway: sends callbacks
- Merchant → Simulation playground: starts simulations
- Simulation playground → API gateway: calls simulation endpoints
- API gateway → Payment and audit ledger: records payment state
- API gateway → Recovery orchestrator: starts recovery
- Recovery orchestrator → Compliance gate: checks stopping rules
- Recovery orchestrator → AI diagnosis: requests diagnosis
- Recovery orchestrator → Payment actions: dispatches recovery actions
- Payment actions → Razorpay APIs: creates payment links
- Payment actions → Payment and audit ledger: logs recovery events
- Recovery orchestrator → Voice synthesis: requests voice outreach
- Voice synthesis → Sarvam / gTTS: synthesizes audio
- Voice synthesis → Payment and audit ledger: logs voice events
- Customer → Razorpay APIs: completes payment
- Razorpay → API gateway: sends signed payment result
- API gateway → Payment and audit ledger: updates recovered status
- War room → Console data hooks: loads live data
- Console data hooks → API gateway: polls console endpoints
- Merchant → War room: views operations
- Product experience → War room: links to console
- Recovery orchestrator → Customer memory: uses customer context
