# sarveshms7/recoveryops architecture

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

- Interactive diagram: https://gitdiagram.com/sarveshms7/recoveryops
- Repository: https://github.com/sarveshms7/recoveryops

## Overview

RecoveryOps ingests and deduplicates revenue-at-risk events, scores recovery opportunity, assigns a randomized control group, allocates treatment capacity, then recommends and policy-checks actions before idempotent payment execution. PostgreSQL persists events, scores, decisions, executions, outbox work, and audit history. The API and dashboard expose funnel and incrementality views; offline ML training is a documented capability. Edges are based on excerpts, SOURCE INDEX references, or README statements; dashboard/API wiring and some integrations are documented but not visible in sampled implementation.

Main entry points: [`adapters/postgres/pg_event_repository.ts`](https://github.com/sarveshms7/recoveryops/blob/main/adapters/postgres/pg_event_repository.ts) (Event repository), [`application/execute_decision.ts`](https://github.com/sarveshms7/recoveryops/blob/main/application/execute_decision.ts) (Decision execution), [`dashboard/src/App.tsx`](https://github.com/sarveshms7/recoveryops/blob/main/dashboard/src/App.tsx) (Recovery dashboard), [`application/run_scoring_pass.ts`](https://github.com/sarveshms7/recoveryops/blob/main/application/run_scoring_pass.ts) (Scoring pass)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Recovery workflow"]
  node_ingest["Event ingestion<br/>[ingest_event.ts]"]
  node_scoring_pass["Scoring pass"]
  node_allocation_pass["Allocation pass"]
  node_execution["Decision execution"]
end

subgraph group_domain["Decision domain"]
  node_score_logic["Uplift scoring<br/>[scoring.ts]"]
  node_allocator["Budget allocator<br/>[allocator.ts]"]
  node_policy["Policy checks<br/>[policy.ts]"]
  node_state_machine["State transitions<br/>[state_machine.ts]"]
end

subgraph group_infrastructure["Persistence and adapters"]
  node_outbox["Outbox poller<br/>[poller.ts]"]
  node_repository["Event repository"]
  node_postgres[("PostgreSQL")]
  node_llm_adapter["Gemini client"]
  node_payment_adapter["Razorpay gateway"]
end

subgraph group_insights["Insights and modeling"]
  node_api["Funnel API<br/>[server.ts]"]
  node_dashboard["Recovery dashboard<br/>[App.tsx]"]
  node_event_list["Event list<br/>[EventList.tsx]"]
  node_funnel["Funnel chart<br/>[FunnelChart.tsx]"]
  node_incrementality["Incrementality panel"]
  node_ml_training["Offline model training<br/>[train.py]"]
  node_coefficients["Model coefficients<br/>[coefficients.json]"]
end

node_event_source(("Risk event source"))
node_gemini{{"Gemini API"}}
node_razorpay{{"Razorpay API"}}

node_event_source -->|"submits events"| node_ingest
node_ingest -->|"writes event and outbox"| node_repository
node_outbox -->|"polls outbox"| node_repository
node_scoring_pass -->|"loads and persists scores"| node_repository
node_scoring_pass -->|"computes scores"| node_score_logic
node_scoring_pass -->|"transitions events"| node_state_machine
node_allocation_pass -->|"loads eligible events"| node_repository
node_allocation_pass -->|"ranks recovery options"| node_allocator
node_allocation_pass -->|"transitions events"| node_state_machine
node_execution -->|"records execution"| node_repository
node_execution -->|"requests recommendation"| node_llm_adapter
node_execution -->|"checks action policy"| node_policy
node_execution -->|"executes action"| node_payment_adapter
node_execution -->|"transitions events"| node_state_machine
node_repository -->|"persists records"| node_postgres
node_repository -->|"validates transitions"| node_state_machine
node_llm_adapter -->|"requests analysis"| node_gemini
node_payment_adapter -->|"sends payment action"| node_razorpay
node_api -.->|"serves dashboard data"| node_dashboard
node_dashboard -->|"renders"| node_event_list
node_dashboard -->|"renders"| node_funnel
node_dashboard -->|"renders"| node_incrementality
node_ml_training -.->|"trains model"| node_coefficients
node_coefficients -.->|"supplies model weights"| node_scoring_pass

click node_ingest "https://github.com/sarveshms7/recoveryops/blob/main/application/ingest_event.ts"
click node_outbox "https://github.com/sarveshms7/recoveryops/blob/main/adapters/outbox/poller.ts"
click node_scoring_pass "https://github.com/sarveshms7/recoveryops/blob/main/application/run_scoring_pass.ts"
click node_allocation_pass "https://github.com/sarveshms7/recoveryops/blob/main/application/run_allocation_pass.ts"
click node_execution "https://github.com/sarveshms7/recoveryops/blob/main/application/execute_decision.ts"
click node_score_logic "https://github.com/sarveshms7/recoveryops/blob/main/domain/scoring.ts"
click node_allocator "https://github.com/sarveshms7/recoveryops/blob/main/domain/allocator.ts"
click node_policy "https://github.com/sarveshms7/recoveryops/blob/main/domain/policy.ts"
click node_state_machine "https://github.com/sarveshms7/recoveryops/blob/main/domain/state_machine.ts"
click node_repository "https://github.com/sarveshms7/recoveryops/blob/main/adapters/postgres/pg_event_repository.ts"
click node_llm_adapter "https://github.com/sarveshms7/recoveryops/blob/main/adapters/llm/gemini_llm_client.ts"
click node_payment_adapter "https://github.com/sarveshms7/recoveryops/blob/main/adapters/razorpay/razorpay_payment_gateway.ts"
click node_api "https://github.com/sarveshms7/recoveryops/blob/main/api/server.ts"
click node_dashboard "https://github.com/sarveshms7/recoveryops/blob/main/dashboard/src/App.tsx"
click node_event_list "https://github.com/sarveshms7/recoveryops/blob/main/dashboard/src/EventList.tsx"
click node_funnel "https://github.com/sarveshms7/recoveryops/blob/main/dashboard/src/FunnelChart.tsx"
click node_incrementality "https://github.com/sarveshms7/recoveryops/blob/main/dashboard/src/IncrementalityPanel.tsx"
click node_ml_training "https://github.com/sarveshms7/recoveryops/blob/main/ml/train.py"
click node_coefficients "https://github.com/sarveshms7/recoveryops/blob/main/ml/coefficients.json"

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_ingest,node_scoring_pass,node_allocation_pass,node_execution toneBlue
class node_score_logic,node_allocator,node_policy,node_state_machine toneAmber
class node_outbox,node_repository,node_postgres,node_llm_adapter,node_payment_adapter,node_gemini,node_razorpay toneMint
class node_api,node_dashboard,node_event_list,node_funnel,node_incrementality,node_ml_training,node_coefficients toneRose
class node_event_source toneIndigo
```

## Components

### Recovery workflow

- [Event ingestion](https://github.com/sarveshms7/recoveryops/blob/main/application/ingest_event.ts): `application/ingest_event.ts`
- [Scoring pass](https://github.com/sarveshms7/recoveryops/blob/main/application/run_scoring_pass.ts): `application/run_scoring_pass.ts`
- [Allocation pass](https://github.com/sarveshms7/recoveryops/blob/main/application/run_allocation_pass.ts): `application/run_allocation_pass.ts`
- [Decision execution](https://github.com/sarveshms7/recoveryops/blob/main/application/execute_decision.ts): `application/execute_decision.ts`

### Decision domain

- [Uplift scoring](https://github.com/sarveshms7/recoveryops/blob/main/domain/scoring.ts): `domain/scoring.ts`
- [Budget allocator](https://github.com/sarveshms7/recoveryops/blob/main/domain/allocator.ts): `domain/allocator.ts`
- [Policy checks](https://github.com/sarveshms7/recoveryops/blob/main/domain/policy.ts): `domain/policy.ts`
- [State transitions](https://github.com/sarveshms7/recoveryops/blob/main/domain/state_machine.ts): `domain/state_machine.ts`

### Persistence and adapters

- [Outbox poller](https://github.com/sarveshms7/recoveryops/blob/main/adapters/outbox/poller.ts): `adapters/outbox/poller.ts`
- [Event repository](https://github.com/sarveshms7/recoveryops/blob/main/adapters/postgres/pg_event_repository.ts): `adapters/postgres/pg_event_repository.ts`
- **PostgreSQL**
- [Gemini client](https://github.com/sarveshms7/recoveryops/blob/main/adapters/llm/gemini_llm_client.ts): `adapters/llm/gemini_llm_client.ts`
- [Razorpay gateway](https://github.com/sarveshms7/recoveryops/blob/main/adapters/razorpay/razorpay_payment_gateway.ts): `adapters/razorpay/razorpay_payment_gateway.ts`

### Insights and modeling

- [Funnel API](https://github.com/sarveshms7/recoveryops/blob/main/api/server.ts): `api/server.ts`
- [Recovery dashboard](https://github.com/sarveshms7/recoveryops/blob/main/dashboard/src/App.tsx): `dashboard/src/App.tsx`
- [Event list](https://github.com/sarveshms7/recoveryops/blob/main/dashboard/src/EventList.tsx): `dashboard/src/EventList.tsx`
- [Funnel chart](https://github.com/sarveshms7/recoveryops/blob/main/dashboard/src/FunnelChart.tsx): `dashboard/src/FunnelChart.tsx`
- [Incrementality panel](https://github.com/sarveshms7/recoveryops/blob/main/dashboard/src/IncrementalityPanel.tsx): `dashboard/src/IncrementalityPanel.tsx`
- [Offline model training](https://github.com/sarveshms7/recoveryops/blob/main/ml/train.py): `ml/train.py`
- [Model coefficients](https://github.com/sarveshms7/recoveryops/blob/main/ml/coefficients.json): `ml/coefficients.json`

### Other components

- **Risk event source**
- **Gemini API**
- **Razorpay API**

## Connections

- Risk event source → Event ingestion: submits events (evidence: `README.md`)
- Event ingestion → Event repository: writes event and outbox (evidence: `application/ingest_event.ts`)
- Outbox poller → Event repository: polls outbox (evidence: `adapters/outbox/poller.ts`)
- Scoring pass → Event repository: loads and persists scores (evidence: `application/run_scoring_pass.ts`)
- Scoring pass → Uplift scoring: computes scores (evidence: `application/run_scoring_pass.ts`)
- Scoring pass → State transitions: transitions events (evidence: `application/run_scoring_pass.ts`)
- Allocation pass → Event repository: loads eligible events (evidence: `application/run_allocation_pass.ts`)
- Allocation pass → Budget allocator: ranks recovery options (evidence: `application/run_allocation_pass.ts`)
- Allocation pass → State transitions: transitions events (evidence: `application/run_allocation_pass.ts`)
- Decision execution → Event repository: records execution (evidence: `application/execute_decision.ts`)
- Decision execution → Gemini client: requests recommendation (evidence: `application/execute_decision.ts`)
- Decision execution → Policy checks: checks action policy (evidence: `application/execute_decision.ts`)
- Decision execution → Razorpay gateway: executes action (evidence: `README.md`)
- Decision execution → State transitions: transitions events (evidence: `application/execute_decision.ts`)
- Event repository → PostgreSQL: persists records (evidence: `README.md`)
- Event repository → State transitions: validates transitions (evidence: `adapters/postgres/pg_event_repository.ts`)
- Gemini client → Gemini API: requests analysis (evidence: `adapters/llm/gemini_llm_client.ts`)
- Razorpay gateway → Razorpay API: sends payment action (evidence: `README.md`)
- Funnel API → Recovery dashboard: serves dashboard data (evidence: `README.md`)
- Recovery dashboard → Event list: renders (evidence: `dashboard/src/App.tsx`)
- Recovery dashboard → Funnel chart: renders (evidence: `dashboard/src/App.tsx`)
- Recovery dashboard → Incrementality panel: renders (evidence: `dashboard/src/App.tsx`)
- Offline model training → Model coefficients: trains model (evidence: `README.md`)
- Model coefficients → Scoring pass: supplies model weights (evidence: `README.md`)
