# iamgiridharan/ai-revenue-recovery-agent architecture

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

- Interactive diagram: https://gitdiagram.com/iamgiridharan/ai-revenue-recovery-agent
- Repository: https://github.com/iamgiridharan/ai-revenue-recovery-agent

## Overview

AI Revenue Recovery Agent provides a merchant dashboard and a controlled failed-payment recovery workflow: cases are assessed with ML, agent recommendations are checked by deterministic policy, approved actions may execute through Razorpay Test Mode, and payment outcomes and decisions are audited. The graph also includes simulation, value-aware scoring, and dashboard analytics. Several backend implementations were not sampled, so their documented capabilities are shown without asserting unverified internal calls.

Main entry points: [`frontend/src/services/api.js`](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/services/api.js) (REST API client), [`frontend/src/App.jsx`](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/App.jsx) (Dashboard application), [`backend/app/services/recovery_service.py`](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/recovery_service.py) (Recovery execution), [`backend/app/services/ml_service.py`](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/ml_service.py) (ML inference service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Merchant dashboard"]
  node_app["Dashboard application<br/>[App.jsx]"]
  node_api_client["REST API client<br/>[api.js]"]
  node_case_views["Case views<br/>[CaseDetail.jsx]"]
  node_dashboard_views["Dashboard and analytics<br/>[Dashboard.jsx]"]
  node_policy_view["Policy settings<br/>[Policy.jsx]"]
end

subgraph group_backend["Recovery backend"]
  node_case_api["Cases API<br/>[cases.py]"]
  node_agent_api["Agent API<br/>[agent.py]"]
  node_policy_api["Policy API<br/>[policy.py]"]
  node_dashboard_api["Dashboard API<br/>[dashboard.py]"]
  node_simulation_api["Simulation API<br/>[simulation.py]"]
  node_webhook_handler["Webhook handler<br/>[webhooks.py]"]
  node_agent["Agent orchestration<br/>[agent_service.py]"]
  node_policy["Deterministic policy<br/>[policy_engine.py]"]
  node_recovery["Recovery execution"]
  node_simulation["Synthetic recovery simulation"]
  node_value_scoring["Value-aware scoring<br/>[value_service.py]"]
  node_dashboard_service["Dashboard aggregates"]
end

subgraph group_ml["ML capabilities"]
  node_ml_service["ML inference service<br/>[ml_service.py]"]
  node_ml_training["Training pipeline<br/>[pipeline.py]"]
  node_synthetic_data["Synthetic dataset<br/>[data_generator.py]"]
  node_preprocessing["Feature preprocessing<br/>[preprocessing.py]"]
  node_model["Recovery model<br/>[model.py]"]
end

subgraph group_data["Persistence"]
  node_database[("Application database<br/>[database.py]")]
  node_webhook_ledger["Webhook idempotency ledger<br/>[webhook_event.py]"]
end

node_merchant(("Merchant"))
node_payment_provider["Razorpay Test Mode"]

node_merchant -->|"uses"| node_app
node_app -->|"routes to"| node_case_views
node_app -->|"routes to"| node_dashboard_views
node_app -->|"routes to"| node_policy_view
node_case_views -->|"requests"| node_api_client
node_dashboard_views -->|"requests"| node_api_client
node_api_client -->|"calls cases endpoints"| node_case_api
node_api_client -->|"calls dashboard endpoints"| node_dashboard_api
node_api_client -->|"calls policy endpoints"| node_policy_api
node_case_api -.->|"orchestrates diagnosis"| node_agent
node_agent -.->|"gets predictions"| node_ml_service
node_agent -->|"requests authorization"| node_policy
node_policy -->|"authorizes actions"| node_recovery
node_recovery -->|"executes approved recovery"| node_payment_provider
node_payment_provider -->|"sends payment events"| node_webhook_handler
node_webhook_handler -->|"processes outcomes"| node_recovery
node_webhook_handler -->|"records deliveries"| node_webhook_ledger
node_webhook_ledger -->|"persists ledger"| node_database
node_recovery -.->|"records actions and audit"| node_database
node_dashboard_api -.->|"aggregates metrics"| node_dashboard_service
node_dashboard_service -->|"uses scoring"| node_value_scoring
node_simulation_api -.->|"runs simulation"| node_simulation
node_simulation -->|"requests predictions"| node_ml_service
node_simulation -->|"checks policy"| node_policy
node_ml_training -->|"generates dataset"| node_synthetic_data
node_ml_training -->|"preprocesses data"| node_preprocessing
node_ml_training -->|"trains and evaluates"| node_model
node_ml_service -.->|"prepares inference"| node_preprocessing
node_ml_service -.->|"predicts recovery"| node_model

click node_app "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/App.jsx"
click node_api_client "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/services/api.js"
click node_case_views "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/pages/CaseDetail.jsx"
click node_dashboard_views "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/pages/Dashboard.jsx"
click node_policy_view "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/pages/Policy.jsx"
click node_case_api "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/cases.py"
click node_agent_api "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/agent.py"
click node_policy_api "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/policy.py"
click node_dashboard_api "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/dashboard.py"
click node_simulation_api "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/simulation.py"
click node_webhook_handler "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/webhooks.py"
click node_agent "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/agent_service.py"
click node_policy "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/policy_engine.py"
click node_recovery "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/recovery_service.py"
click node_simulation "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/simulation_service.py"
click node_value_scoring "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/value_service.py"
click node_dashboard_service "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/dashboard_service.py"
click node_ml_service "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/ml_service.py"
click node_ml_training "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/ml/pipeline.py"
click node_synthetic_data "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/ml/data_generator.py"
click node_preprocessing "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/ml/preprocessing.py"
click node_model "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/ml/model.py"
click node_database "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/core/database.py"
click node_webhook_ledger "https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/models/webhook_event.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_app,node_api_client,node_case_views,node_dashboard_views,node_policy_view toneBlue
class node_case_api,node_agent_api,node_policy_api,node_dashboard_api,node_simulation_api,node_webhook_handler,node_agent,node_policy,node_recovery,node_simulation,node_value_scoring,node_dashboard_service toneAmber
class node_ml_service,node_ml_training,node_synthetic_data,node_preprocessing,node_model toneMint
class node_database,node_webhook_ledger toneRose
class node_merchant,node_payment_provider toneIndigo
```

## Components

### Merchant dashboard

- [Dashboard application](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [REST API client](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`
- [Case views](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/pages/CaseDetail.jsx): `frontend/src/pages/CaseDetail.jsx`
- [Dashboard and analytics](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [Policy settings](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/frontend/src/pages/Policy.jsx): `frontend/src/pages/Policy.jsx`

### Recovery backend

- [Cases API](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/cases.py): `backend/app/api/cases.py`
- [Agent API](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/agent.py): `backend/app/api/agent.py`
- [Policy API](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/policy.py): `backend/app/api/policy.py`
- [Dashboard API](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/dashboard.py): `backend/app/api/dashboard.py`
- [Simulation API](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/simulation.py): `backend/app/api/simulation.py`
- [Webhook handler](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/api/webhooks.py): `backend/app/api/webhooks.py`
- [Agent orchestration](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/agent_service.py): `backend/app/services/agent_service.py`
- [Deterministic policy](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/policy_engine.py): `backend/app/services/policy_engine.py`
- [Recovery execution](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/recovery_service.py): `backend/app/services/recovery_service.py`
- [Synthetic recovery simulation](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/simulation_service.py): `backend/app/services/simulation_service.py`
- [Value-aware scoring](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/value_service.py): `backend/app/services/value_service.py`
- [Dashboard aggregates](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/dashboard_service.py): `backend/app/services/dashboard_service.py`

### ML capabilities

- [ML inference service](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/services/ml_service.py): `backend/app/services/ml_service.py`
- [Training pipeline](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/ml/pipeline.py): `ml/pipeline.py`
- [Synthetic dataset](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/ml/data_generator.py): `ml/data_generator.py`
- [Feature preprocessing](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/ml/preprocessing.py): `ml/preprocessing.py`
- [Recovery model](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/ml/model.py): `ml/model.py`

### Persistence

- [Application database](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/core/database.py): `backend/app/core/database.py`
- [Webhook idempotency ledger](https://github.com/iamgiridharan/ai-revenue-recovery-agent/blob/main/backend/app/models/webhook_event.py): `backend/app/models/webhook_event.py`

### Other components

- **Merchant**
- **Razorpay Test Mode**

## Connections

- Merchant → Dashboard application: uses
- Dashboard application → Case views: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard application → Dashboard and analytics: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard application → Policy settings: routes to (evidence: `frontend/src/App.jsx`)
- Case views → REST API client: requests (evidence: `frontend/src/pages/CaseDetail.jsx`)
- Dashboard and analytics → REST API client: requests (evidence: `frontend/src/pages/Dashboard.jsx`)
- REST API client → Cases API: calls cases endpoints (evidence: `frontend/src/services/api.js`)
- REST API client → Dashboard API: calls dashboard endpoints (evidence: `frontend/src/services/api.js`)
- REST API client → Policy API: calls policy endpoints (evidence: `frontend/src/services/api.js`)
- Cases API → Agent orchestration: orchestrates diagnosis
- Agent orchestration → ML inference service: gets predictions
- Agent orchestration → Deterministic policy: requests authorization
- Deterministic policy → Recovery execution: authorizes actions (evidence: `backend/app/services/recovery_service.py`)
- Recovery execution → Razorpay Test Mode: executes approved recovery
- Razorpay Test Mode → Webhook handler: sends payment events
- Webhook handler → Recovery execution: processes outcomes (evidence: `backend/app/api/webhooks.py`)
- Webhook handler → Webhook idempotency ledger: records deliveries (evidence: `backend/app/api/webhooks.py`)
- Webhook idempotency ledger → Application database: persists ledger (evidence: `backend/app/models/webhook_event.py`)
- Recovery execution → Application database: records actions and audit
- Dashboard API → Dashboard aggregates: aggregates metrics
- Dashboard aggregates → Value-aware scoring: uses scoring (evidence: `backend/app/services/dashboard_service.py`)
- Simulation API → Synthetic recovery simulation: runs simulation
- Synthetic recovery simulation → ML inference service: requests predictions (evidence: `backend/app/services/simulation_service.py`)
- Synthetic recovery simulation → Deterministic policy: checks policy (evidence: `backend/app/services/simulation_service.py`)
- Training pipeline → Synthetic dataset: generates dataset (evidence: `ml/pipeline.py`)
- Training pipeline → Feature preprocessing: preprocesses data (evidence: `ml/pipeline.py`)
- Training pipeline → Recovery model: trains and evaluates (evidence: `ml/pipeline.py`)
- ML inference service → Feature preprocessing: prepares inference
- ML inference service → Recovery model: predicts recovery
