# abhinav-phi/reflex architecture

> Architecture diagram of the GitHub repository abhinav-phi/reflex, 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/abhinav-phi/reflex
- Repository: https://github.com/abhinav-phi/reflex

## Overview

Reflex is a bounded AI revenue-recovery agent for failed subscription payments. Its principal workflow ingests Razorpay webhooks or simulated replay events, diagnoses the decline, ranks recovery actions by expected value, applies deterministic guardrails, then executes or routes actions for approval while recording outcomes and an auditable ledger. The React command center exposes operational controls, approvals, audit, and evaluation results; the evaluation pipeline is a separate product capability. Several subsystem links follow the README architecture because their implementation files were not excerpted.

Main entry points: [`apps/web/src/App.tsx`](https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/App.tsx) (Web Application), [`apps/web/src/lib/api.ts`](https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/lib/api.ts) (API Client), [`packages/brain/ev.py`](https://github.com/abhinav-phi/reflex/blob/main/packages/brain/ev.py) (EV Policy), [`apps/api/main.py`](https://github.com/abhinav-phi/reflex/blob/main/apps/api/main.py) (FastAPI Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_intake["Pulse Intake"]
  node_ingest["Webhook Intake<br/>[ingest_service.py]"]
  node_diagnosis["Root-Cause Diagnosis<br/>[diagnosis.py]"]
  node_llm["LLM Judgment<br/>[llm_client.py]"]
end

subgraph group_decision["Decisioning"]
  node_brain["EV Policy<br/>[ev.py]"]
  node_trainer["Policy Training<br/>[trainer.py]"]
  node_shield["Guardrails<br/>[guardrails.py]"]
end

subgraph group_execution["Execution &amp; Proof"]
  node_approvals["Approval Queue<br/>[approvals.py]"]
  node_dispatcher["Action Dispatcher<br/>[dispatcher.py]"]
  node_razorpay_api["Razorpay Actions<br/>[razorpay.py]"]
  node_channels["Channel Executors<br/>[channels.py]"]
  node_outcomes["Outcome Attribution<br/>[outcomes.py]"]
  node_ledger[("Hash-Chained Ledger<br/>[chain.py]")]
  node_evaluation["Evaluation Proof<br/>[pipeline.py]"]
end

subgraph group_platform["API &amp; State"]
  node_api["FastAPI Service<br/>[main.py]"]
  node_postgres[("PostgreSQL<br/>[db.py]")]
  node_redis["Redis Events"]
end

subgraph group_console["Operator Console"]
  node_web_app["Web Application<br/>[App.tsx]"]
  node_dashboard["Recovery Dashboard<br/>[Dashboard.tsx]"]
  node_approvals_ui["Approvals View<br/>[Approvals.tsx]"]
  node_audit_ui["Audit View<br/>[Audit.tsx]"]
  node_ops_ui["Operations Console<br/>[Ops.tsx]"]
  node_results_ui["Evaluation Results<br/>[Results.tsx]"]
  node_api_client["API Client<br/>[api.ts]"]
  node_stream["Live Event Stream<br/>[useStream.ts]"]
  node_ui_state["UI State<br/>[store.ts]"]
end

node_razorpay_webhooks(("Razorpay Webhooks"))
node_replay(("Replay Engine"))

node_razorpay_webhooks -->|"sends webhooks"| node_ingest
node_replay -->|"replays events"| node_ingest
node_ingest -->|"queues diagnosis"| node_diagnosis
node_diagnosis -->|"judges ambiguous cases"| node_llm
node_diagnosis -->|"provides diagnosis"| node_brain
node_brain -->|"proposes actions"| node_shield
node_shield -->|"requests approval"| node_approvals
node_shield -->|"permits actions"| node_dispatcher
node_dispatcher -->|"executes payments"| node_razorpay_api
node_dispatcher -->|"sends messages"| node_channels
node_razorpay_api -->|"records actions"| node_ledger
node_channels -->|"records actions"| node_ledger
node_razorpay_api -->|"reports outcomes"| node_outcomes
node_channels -->|"reports outcomes"| node_outcomes
node_outcomes -->|"updates policy"| node_brain
node_brain -.->|"tunes policy"| node_trainer
node_evaluation -.->|"supplies results"| node_results_ui
node_api -->|"persists records"| node_postgres
node_api -->|"publishes live events"| node_redis
node_web_app -->|"routes to"| node_dashboard
node_web_app -->|"routes to"| node_approvals_ui
node_web_app -->|"routes to"| node_audit_ui
node_web_app -->|"routes to"| node_ops_ui
node_web_app -->|"routes to"| node_results_ui
node_dashboard -->|"requests metrics"| node_api_client
node_approvals_ui -->|"requests approvals"| node_api_client
node_audit_ui -->|"requests audit data"| node_api_client
node_ops_ui -->|"controls operation"| node_api_client
node_api_client -->|"calls REST API"| node_api
node_stream -->|"subscribes via SSE"| node_api
node_stream -->|"updates live state"| node_ui_state

click node_ingest "https://github.com/abhinav-phi/reflex/blob/main/apps/api/ingest_service.py"
click node_diagnosis "https://github.com/abhinav-phi/reflex/blob/main/apps/workers/diagnosis.py"
click node_llm "https://github.com/abhinav-phi/reflex/blob/main/apps/workers/llm_client.py"
click node_brain "https://github.com/abhinav-phi/reflex/blob/main/packages/brain/ev.py"
click node_trainer "https://github.com/abhinav-phi/reflex/blob/main/packages/brain/trainer.py"
click node_shield "https://github.com/abhinav-phi/reflex/blob/main/packages/shield/guardrails.py"
click node_approvals "https://github.com/abhinav-phi/reflex/blob/main/apps/api/routes/approvals.py"
click node_dispatcher "https://github.com/abhinav-phi/reflex/blob/main/apps/workers/dispatcher.py"
click node_razorpay_api "https://github.com/abhinav-phi/reflex/blob/main/packages/connectors/razorpay.py"
click node_channels "https://github.com/abhinav-phi/reflex/blob/main/packages/connectors/channels.py"
click node_outcomes "https://github.com/abhinav-phi/reflex/blob/main/apps/workers/outcomes.py"
click node_ledger "https://github.com/abhinav-phi/reflex/blob/main/packages/ledger/chain.py"
click node_evaluation "https://github.com/abhinav-phi/reflex/blob/main/apps/eval/pipeline.py"
click node_api "https://github.com/abhinav-phi/reflex/blob/main/apps/api/main.py"
click node_postgres "https://github.com/abhinav-phi/reflex/blob/main/apps/api/db.py"
click node_web_app "https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/App.tsx"
click node_dashboard "https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/pages/Dashboard.tsx"
click node_approvals_ui "https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/pages/Approvals.tsx"
click node_audit_ui "https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/pages/Audit.tsx"
click node_ops_ui "https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/pages/Ops.tsx"
click node_results_ui "https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/pages/Results.tsx"
click node_api_client "https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/lib/api.ts"
click node_stream "https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/hooks/useStream.ts"
click node_ui_state "https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/store.ts"

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_diagnosis,node_llm toneBlue
class node_brain,node_trainer,node_shield toneAmber
class node_approvals,node_dispatcher,node_razorpay_api,node_channels,node_outcomes,node_ledger,node_evaluation,node_razorpay_webhooks toneMint
class node_api,node_postgres,node_redis toneRose
class node_web_app,node_dashboard,node_approvals_ui,node_audit_ui,node_ops_ui,node_results_ui,node_api_client,node_stream,node_ui_state,node_replay toneIndigo
```

## Components

### Pulse Intake

- [Webhook Intake](https://github.com/abhinav-phi/reflex/blob/main/apps/api/ingest_service.py): `apps/api/ingest_service.py`
- [Root-Cause Diagnosis](https://github.com/abhinav-phi/reflex/blob/main/apps/workers/diagnosis.py): `apps/workers/diagnosis.py`
- [LLM Judgment](https://github.com/abhinav-phi/reflex/blob/main/apps/workers/llm_client.py): `apps/workers/llm_client.py`

### Decisioning

- [EV Policy](https://github.com/abhinav-phi/reflex/blob/main/packages/brain/ev.py): `packages/brain/ev.py`
- [Policy Training](https://github.com/abhinav-phi/reflex/blob/main/packages/brain/trainer.py): `packages/brain/trainer.py`
- [Guardrails](https://github.com/abhinav-phi/reflex/blob/main/packages/shield/guardrails.py): `packages/shield/guardrails.py`

### Execution & Proof

- [Approval Queue](https://github.com/abhinav-phi/reflex/blob/main/apps/api/routes/approvals.py): `apps/api/routes/approvals.py`
- [Action Dispatcher](https://github.com/abhinav-phi/reflex/blob/main/apps/workers/dispatcher.py): `apps/workers/dispatcher.py`
- [Razorpay Actions](https://github.com/abhinav-phi/reflex/blob/main/packages/connectors/razorpay.py): `packages/connectors/razorpay.py`
- [Channel Executors](https://github.com/abhinav-phi/reflex/blob/main/packages/connectors/channels.py): `packages/connectors/channels.py`
- [Outcome Attribution](https://github.com/abhinav-phi/reflex/blob/main/apps/workers/outcomes.py): `apps/workers/outcomes.py`
- [Hash-Chained Ledger](https://github.com/abhinav-phi/reflex/blob/main/packages/ledger/chain.py): `packages/ledger/chain.py`
- [Evaluation Proof](https://github.com/abhinav-phi/reflex/blob/main/apps/eval/pipeline.py): `apps/eval/pipeline.py`

### API & State

- [FastAPI Service](https://github.com/abhinav-phi/reflex/blob/main/apps/api/main.py): `apps/api/main.py`
- [PostgreSQL](https://github.com/abhinav-phi/reflex/blob/main/apps/api/db.py): `apps/api/db.py`
- **Redis Events**

### Operator Console

- [Web Application](https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/App.tsx): `apps/web/src/App.tsx`
- [Recovery Dashboard](https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/pages/Dashboard.tsx): `apps/web/src/pages/Dashboard.tsx`
- [Approvals View](https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/pages/Approvals.tsx): `apps/web/src/pages/Approvals.tsx`
- [Audit View](https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/pages/Audit.tsx): `apps/web/src/pages/Audit.tsx`
- [Operations Console](https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/pages/Ops.tsx): `apps/web/src/pages/Ops.tsx`
- [Evaluation Results](https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/pages/Results.tsx): `apps/web/src/pages/Results.tsx`
- [API Client](https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/lib/api.ts): `apps/web/src/lib/api.ts`
- [Live Event Stream](https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/hooks/useStream.ts): `apps/web/src/hooks/useStream.ts`
- [UI State](https://github.com/abhinav-phi/reflex/blob/main/apps/web/src/store.ts): `apps/web/src/store.ts`

### Other components

- **Razorpay Webhooks**
- **Replay Engine**

## Connections

- Razorpay Webhooks → Webhook Intake: sends webhooks (evidence: `README.md`)
- Replay Engine → Webhook Intake: replays events (evidence: `README.md`)
- Webhook Intake → Root-Cause Diagnosis: queues diagnosis (evidence: `README.md`)
- Root-Cause Diagnosis → LLM Judgment: judges ambiguous cases (evidence: `README.md`)
- Root-Cause Diagnosis → EV Policy: provides diagnosis (evidence: `README.md`)
- EV Policy → Guardrails: proposes actions (evidence: `README.md`)
- Guardrails → Approval Queue: requests approval (evidence: `README.md`)
- Guardrails → Action Dispatcher: permits actions (evidence: `README.md`)
- Action Dispatcher → Razorpay Actions: executes payments (evidence: `README.md`)
- Action Dispatcher → Channel Executors: sends messages (evidence: `README.md`)
- Razorpay Actions → Hash-Chained Ledger: records actions (evidence: `README.md`)
- Channel Executors → Hash-Chained Ledger: records actions (evidence: `README.md`)
- Razorpay Actions → Outcome Attribution: reports outcomes (evidence: `README.md`)
- Channel Executors → Outcome Attribution: reports outcomes (evidence: `README.md`)
- Outcome Attribution → EV Policy: updates policy (evidence: `README.md`)
- EV Policy → Policy Training: tunes policy
- Evaluation Proof → Evaluation Results: supplies results
- FastAPI Service → PostgreSQL: persists records (evidence: `README.md`)
- FastAPI Service → Redis Events: publishes live events (evidence: `README.md`)
- Web Application → Recovery Dashboard: routes to (evidence: `apps/web/src/App.tsx`)
- Web Application → Approvals View: routes to (evidence: `apps/web/src/App.tsx`)
- Web Application → Audit View: routes to (evidence: `apps/web/src/App.tsx`)
- Web Application → Operations Console: routes to (evidence: `apps/web/src/App.tsx`)
- Web Application → Evaluation Results: routes to (evidence: `apps/web/src/App.tsx`)
- Recovery Dashboard → API Client: requests metrics (evidence: `apps/web/src/pages/Dashboard.tsx`)
- Approvals View → API Client: requests approvals (evidence: `apps/web/src/pages/Approvals.tsx`)
- Audit View → API Client: requests audit data (evidence: `apps/web/src/pages/Audit.tsx`)
- Operations Console → API Client: controls operation (evidence: `apps/web/src/pages/Ops.tsx`)
- API Client → FastAPI Service: calls REST API (evidence: `README.md`)
- Live Event Stream → FastAPI Service: subscribes via SSE (evidence: `README.md`)
- Live Event Stream → UI State: updates live state (evidence: `apps/web/src/hooks/useStream.ts`)
