# nilesh1381/pratyavartan architecture

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

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

## Overview

Pratyavartan is an autonomous payment-failure recovery service with a separate Next.js landing experience. Its documented main workflow ingests failures, applies bounded diagnosis and recovery actions, then records payment outcomes and audit events. The graph preserves documented recovery, mandate, voice, monitoring, and merchant-assurance capabilities. Backend relationships are supported by excerpts, the source index, or README; some internals and the landing page’s component wiring were not sampled, so those links are omitted.

Main entry points: [`orchestrator.py`](https://github.com/nilesh1381/pratyavartan/blob/main/orchestrator.py) (Recovery orchestration), [`main.py`](https://github.com/nilesh1381/pratyavartan/blob/main/main.py) (Webhook and API), [`db.py`](https://github.com/nilesh1381/pratyavartan/blob/main/db.py) (Payment state), [`ai_agent.py`](https://github.com/nilesh1381/pratyavartan/blob/main/ai_agent.py) (AI diagnosis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_recovery["Recovery runtime"]
  node_api["Webhook and API<br/>[main.py]"]
  node_orchestrator["Recovery orchestration<br/>[orchestrator.py]"]
  node_diagnosis["AI diagnosis<br/>[ai_agent.py]"]
  node_recovery_actions["Payment recovery actions"]
  node_mandates["Mandate retries<br/>[orchestrator.py]"]
  node_promises["Promise follow-ups<br/>[orchestrator.py]"]
  node_voice["Voice outreach<br/>[ai_agent.py]"]
end

subgraph group_assurance["State and assurance"]
  node_state[("Payment state<br/>[db.py]")]
  node_audit[("Hash-chained audit ledger<br/>[db.py]")]
  node_assurance_api["Merchant assurance API<br/>[main.py]"]
end

subgraph group_experience["User experiences"]
  node_war_room["Merchant war room<br/>[main.py]"]
  node_landing["Landing experience<br/>[page.tsx]"]
end

subgraph group_integrations["External services"]
  node_razorpay["Razorpay payments"]
  node_llm["LLM provider"]
  node_speech["gTTS"]
end

node_merchant(("Merchant"))

node_razorpay -->|"sends webhooks"| node_api
node_api -->|"ingests failures"| node_state
node_api -->|"dispatches workflow"| node_orchestrator
node_orchestrator -->|"requests diagnosis"| node_diagnosis
node_diagnosis -.->|"queries diagnosis"| node_llm
node_orchestrator -->|"dispatches actions"| node_recovery_actions
node_recovery_actions -->|"creates payment links"| node_razorpay
node_orchestrator -->|"schedules retries"| node_mandates
node_orchestrator -->|"sends follow-ups"| node_promises
node_orchestrator -.->|"generates scripts"| node_voice
node_voice -->|"synthesizes audio"| node_speech
node_api -->|"marks recovered"| node_state
node_api -->|"logs events"| node_audit
node_orchestrator -->|"reads payment state"| node_state
node_orchestrator -.->|"records decisions"| node_audit
node_api -->|"serves metrics"| node_assurance_api
node_merchant -->|"reviews recovery"| node_war_room
node_merchant -->|"visits landing page"| node_landing

click node_api "https://github.com/nilesh1381/pratyavartan/blob/main/main.py"
click node_orchestrator "https://github.com/nilesh1381/pratyavartan/blob/main/orchestrator.py"
click node_diagnosis "https://github.com/nilesh1381/pratyavartan/blob/main/ai_agent.py"
click node_recovery_actions "https://github.com/nilesh1381/pratyavartan/blob/main/razorpay_service.py"
click node_mandates "https://github.com/nilesh1381/pratyavartan/blob/main/orchestrator.py"
click node_promises "https://github.com/nilesh1381/pratyavartan/blob/main/orchestrator.py"
click node_voice "https://github.com/nilesh1381/pratyavartan/blob/main/ai_agent.py"
click node_state "https://github.com/nilesh1381/pratyavartan/blob/main/db.py"
click node_audit "https://github.com/nilesh1381/pratyavartan/blob/main/db.py"
click node_assurance_api "https://github.com/nilesh1381/pratyavartan/blob/main/main.py"
click node_war_room "https://github.com/nilesh1381/pratyavartan/blob/main/main.py"
click node_landing "https://github.com/nilesh1381/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_api,node_orchestrator,node_diagnosis,node_recovery_actions,node_mandates,node_promises,node_voice toneBlue
class node_state,node_audit,node_assurance_api toneAmber
class node_war_room,node_landing toneMint
class node_razorpay,node_llm,node_speech toneRose
class node_merchant toneIndigo
```

## Components

### Recovery runtime

- [Webhook and API](https://github.com/nilesh1381/pratyavartan/blob/main/main.py): `main.py`
- [Recovery orchestration](https://github.com/nilesh1381/pratyavartan/blob/main/orchestrator.py): `orchestrator.py`
- [AI diagnosis](https://github.com/nilesh1381/pratyavartan/blob/main/ai_agent.py): `ai_agent.py`
- [Payment recovery actions](https://github.com/nilesh1381/pratyavartan/blob/main/razorpay_service.py): `razorpay_service.py`
- [Mandate retries](https://github.com/nilesh1381/pratyavartan/blob/main/orchestrator.py): `orchestrator.py`
- [Promise follow-ups](https://github.com/nilesh1381/pratyavartan/blob/main/orchestrator.py): `orchestrator.py`
- [Voice outreach](https://github.com/nilesh1381/pratyavartan/blob/main/ai_agent.py): `ai_agent.py`

### State and assurance

- [Payment state](https://github.com/nilesh1381/pratyavartan/blob/main/db.py): `db.py`
- [Hash-chained audit ledger](https://github.com/nilesh1381/pratyavartan/blob/main/db.py): `db.py`
- [Merchant assurance API](https://github.com/nilesh1381/pratyavartan/blob/main/main.py): `main.py`

### User experiences

- [Merchant war room](https://github.com/nilesh1381/pratyavartan/blob/main/main.py): `main.py`
- [Landing experience](https://github.com/nilesh1381/pratyavartan/blob/main/revive-site/src/app/page.tsx): `revive-site/src/app/page.tsx`

### External services

- **Razorpay payments**
- **LLM provider**
- **gTTS**

### Other components

- **Merchant**

## Connections

- Razorpay payments → Webhook and API: sends webhooks
- Webhook and API → Payment state: ingests failures (evidence: `main.py`)
- Webhook and API → Recovery orchestration: dispatches workflow (evidence: `main.py`)
- Recovery orchestration → AI diagnosis: requests diagnosis (evidence: `orchestrator.py`)
- AI diagnosis → LLM provider: queries diagnosis
- Recovery orchestration → Payment recovery actions: dispatches actions (evidence: `orchestrator.py`)
- Payment recovery actions → Razorpay payments: creates payment links
- Recovery orchestration → Mandate retries: schedules retries (evidence: `check_ai.py`)
- Recovery orchestration → Promise follow-ups: sends follow-ups (evidence: `orchestrator.py`)
- Recovery orchestration → Voice outreach: generates scripts (evidence: `orchestrator.py`)
- Voice outreach → gTTS: synthesizes audio
- Webhook and API → Payment state: marks recovered (evidence: `main.py`)
- Webhook and API → Hash-chained audit ledger: logs events (evidence: `main.py`)
- Recovery orchestration → Payment state: reads payment state (evidence: `orchestrator.py`)
- Recovery orchestration → Hash-chained audit ledger: records decisions (evidence: `orchestrator.py`)
- Webhook and API → Merchant assurance API: serves metrics (evidence: `main.py`)
- Merchant → Merchant war room: reviews recovery
- Merchant → Landing experience: visits landing page
