# asawaricode/settleloop architecture

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

## Overview

SettleLoop is a payment-recovery research and evaluation platform, not live payment infrastructure. Its main workflow generates synthetic mandates, simulates paired recovery policies, and evaluates their outcomes; an API and dashboard expose experiment operations. A separate, isolated Razorpay Test Mode branch handles signed webhooks and manual test-order creation. The graph reflects the supplied README and source index; unsampled subsystems are included where documented, but their internal call paths are not inferred.

Main entry points: [`src/recovery/smartPolicy.js`](https://github.com/asawaricode/settleloop/blob/main/src/recovery/smartPolicy.js) (Smart Policy), [`src/recovery/benchmarkRunner.js`](https://github.com/asawaricode/settleloop/blob/main/src/recovery/benchmarkRunner.js) (Paired Benchmark), [`src/recovery/recoveryEngine.js`](https://github.com/asawaricode/settleloop/blob/main/src/recovery/recoveryEngine.js) (Recovery Engine), [`src/api/routes.js`](https://github.com/asawaricode/settleloop/blob/main/src/api/routes.js) (Experiment API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experiments["Synthetic Experiments"]
  node_benchmark["Paired Benchmark<br/>[benchmarkRunner.js]"]
  node_simulator["Payment Simulator"]
  node_observation["Observation Boundary<br/>[observation.js]"]
  node_clock["Virtual Clock<br/>[simulatedClock.js]"]
end

subgraph group_recovery["Recovery Policies"]
  node_control["Control Policy<br/>[controlPolicy.js]"]
  node_fixed["Fixed Schedule<br/>[baselinePolicy.js]"]
  node_salary["Salary-Aware Policy"]
  node_smart["Smart Policy<br/>[smartPolicy.js]"]
  node_classifier["Failure Classifier"]
  node_agent["Smart Agent<br/>[smartAgent.js]"]
  node_guardrails["Safety Guardrails<br/>[guardrails.js]"]
  node_validator["Proposal Validator"]
  node_approval["Human Approval<br/>[humanApproval.js]"]
  node_engine["Recovery Engine<br/>[recoveryEngine.js]"]
  node_runner["Recovery Runner<br/>[recoveryRunner.js]"]
  node_state["Mandate State Machine"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluator["Benchmark Evaluator"]
  node_metrics["Experiment Metrics<br/>[metrics.js]"]
end

subgraph group_application["API And Dashboard"]
  node_api["Experiment API<br/>[routes.js]"]
  node_generator["Synthetic Data Generator"]
  node_server["Express Server<br/>[server.js]"]
  node_dashboard["Operator Dashboard<br/>[app.js]"]
end

subgraph group_razorpay["Razorpay Test Mode"]
  node_webhook["Signed Webhooks<br/>[razorpayWebhook.js]"]
  node_orders["Manual Test Orders<br/>[razorpayOrder.js]"]
end

node_researcher(("Researcher / Operator"))
node_supabase[("Supabase")]
node_razorpay["Razorpay Test Mode"]

node_researcher -->|"runs experiment"| node_benchmark
node_benchmark -->|"simulates outcomes"| node_simulator
node_benchmark -->|"evaluates arm"| node_control
node_benchmark -->|"evaluates arm"| node_fixed
node_benchmark -->|"evaluates arm"| node_salary
node_benchmark -->|"evaluates arm"| node_smart
node_simulator -->|"builds observation"| node_observation
node_simulator -.->|"uses virtual time"| node_clock
node_smart -->|"classifies failure"| node_classifier
node_smart -->|"requests proposal"| node_agent
node_agent -->|"validates proposal"| node_validator
node_smart -->|"checks proposal"| node_guardrails
node_smart -->|"requests review"| node_approval
node_smart -->|"simulates attempt"| node_simulator
node_smart -->|"checks transition"| node_state
node_engine -->|"dispatches policy"| node_control
node_engine -->|"dispatches policy"| node_fixed
node_engine -->|"dispatches policy"| node_salary
node_engine -->|"dispatches policy"| node_smart
node_runner -->|"processes mandates"| node_engine
node_runner -->|"advances simulation"| node_clock
node_evaluator -->|"runs paired trials"| node_benchmark
node_evaluator -.->|"computes results"| node_metrics
node_researcher -->|"requests operations"| node_api
node_api -->|"creates cohort"| node_generator
node_api -->|"runs recovery"| node_runner
node_api -->|"resolves review"| node_approval
node_server -->|"mounts routes"| node_api
node_server -->|"mounts endpoint"| node_webhook
node_server -->|"routes requests"| node_orders
node_server -->|"serves files"| node_dashboard
node_webhook -->|"stores events"| node_supabase
node_orders -->|"reads configuration"| node_supabase
node_orders -->|"creates test order"| node_razorpay
node_razorpay -->|"sends signed events"| node_webhook
node_generator -.->|"persists cohort"| node_supabase
node_metrics -.->|"uses database"| node_supabase

click node_benchmark "https://github.com/asawaricode/settleloop/blob/main/src/recovery/benchmarkRunner.js"
click node_simulator "https://github.com/asawaricode/settleloop/blob/main/src/simulators/paymentSimulator.js"
click node_observation "https://github.com/asawaricode/settleloop/blob/main/src/simulators/observation.js"
click node_clock "https://github.com/asawaricode/settleloop/blob/main/src/simulation/simulatedClock.js"
click node_control "https://github.com/asawaricode/settleloop/blob/main/src/recovery/controlPolicy.js"
click node_fixed "https://github.com/asawaricode/settleloop/blob/main/src/recovery/baselinePolicy.js"
click node_salary "https://github.com/asawaricode/settleloop/blob/main/src/recovery/salaryAwarePolicy.js"
click node_smart "https://github.com/asawaricode/settleloop/blob/main/src/recovery/smartPolicy.js"
click node_classifier "https://github.com/asawaricode/settleloop/blob/main/src/recovery/failureClassifier.js"
click node_agent "https://github.com/asawaricode/settleloop/blob/main/src/recovery/smartAgent.js"
click node_guardrails "https://github.com/asawaricode/settleloop/blob/main/src/recovery/guardrails.js"
click node_validator "https://github.com/asawaricode/settleloop/blob/main/src/recovery/proposalValidator.js"
click node_approval "https://github.com/asawaricode/settleloop/blob/main/src/recovery/humanApproval.js"
click node_engine "https://github.com/asawaricode/settleloop/blob/main/src/recovery/recoveryEngine.js"
click node_runner "https://github.com/asawaricode/settleloop/blob/main/src/recovery/recoveryRunner.js"
click node_state "https://github.com/asawaricode/settleloop/blob/main/src/stateMachine/mandateStateMachine.js"
click node_evaluator "https://github.com/asawaricode/settleloop/blob/main/src/evaluation/benchmarkEvaluator.js"
click node_metrics "https://github.com/asawaricode/settleloop/blob/main/src/evaluation/metrics.js"
click node_api "https://github.com/asawaricode/settleloop/blob/main/src/api/routes.js"
click node_generator "https://github.com/asawaricode/settleloop/blob/main/src/generators/syntheticDataGenerator.js"
click node_server "https://github.com/asawaricode/settleloop/blob/main/server.js"
click node_dashboard "https://github.com/asawaricode/settleloop/blob/main/public/dashboard/app.js"
click node_webhook "https://github.com/asawaricode/settleloop/blob/main/src/api/razorpayWebhook.js"
click node_orders "https://github.com/asawaricode/settleloop/blob/main/src/api/razorpayOrder.js"

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_benchmark,node_simulator,node_observation,node_clock toneBlue
class node_control,node_fixed,node_salary,node_smart,node_classifier,node_agent,node_guardrails,node_validator,node_approval,node_engine,node_runner,node_state,node_supabase toneAmber
class node_evaluator,node_metrics toneMint
class node_api,node_generator,node_server,node_dashboard toneRose
class node_webhook,node_orders,node_researcher,node_razorpay toneIndigo
```

## Components

### Synthetic Experiments

- [Paired Benchmark](https://github.com/asawaricode/settleloop/blob/main/src/recovery/benchmarkRunner.js): `src/recovery/benchmarkRunner.js`
- [Payment Simulator](https://github.com/asawaricode/settleloop/blob/main/src/simulators/paymentSimulator.js): `src/simulators/paymentSimulator.js`
- [Observation Boundary](https://github.com/asawaricode/settleloop/blob/main/src/simulators/observation.js): `src/simulators/observation.js`
- [Virtual Clock](https://github.com/asawaricode/settleloop/blob/main/src/simulation/simulatedClock.js): `src/simulation/simulatedClock.js`

### Recovery Policies

- [Control Policy](https://github.com/asawaricode/settleloop/blob/main/src/recovery/controlPolicy.js): `src/recovery/controlPolicy.js`
- [Fixed Schedule](https://github.com/asawaricode/settleloop/blob/main/src/recovery/baselinePolicy.js): `src/recovery/baselinePolicy.js`
- [Salary-Aware Policy](https://github.com/asawaricode/settleloop/blob/main/src/recovery/salaryAwarePolicy.js): `src/recovery/salaryAwarePolicy.js`
- [Smart Policy](https://github.com/asawaricode/settleloop/blob/main/src/recovery/smartPolicy.js): `src/recovery/smartPolicy.js`
- [Failure Classifier](https://github.com/asawaricode/settleloop/blob/main/src/recovery/failureClassifier.js): `src/recovery/failureClassifier.js`
- [Smart Agent](https://github.com/asawaricode/settleloop/blob/main/src/recovery/smartAgent.js): `src/recovery/smartAgent.js`
- [Safety Guardrails](https://github.com/asawaricode/settleloop/blob/main/src/recovery/guardrails.js): `src/recovery/guardrails.js`
- [Proposal Validator](https://github.com/asawaricode/settleloop/blob/main/src/recovery/proposalValidator.js): `src/recovery/proposalValidator.js`
- [Human Approval](https://github.com/asawaricode/settleloop/blob/main/src/recovery/humanApproval.js): `src/recovery/humanApproval.js`
- [Recovery Engine](https://github.com/asawaricode/settleloop/blob/main/src/recovery/recoveryEngine.js): `src/recovery/recoveryEngine.js`
- [Recovery Runner](https://github.com/asawaricode/settleloop/blob/main/src/recovery/recoveryRunner.js): `src/recovery/recoveryRunner.js`
- [Mandate State Machine](https://github.com/asawaricode/settleloop/blob/main/src/stateMachine/mandateStateMachine.js): `src/stateMachine/mandateStateMachine.js`

### Evaluation

- [Benchmark Evaluator](https://github.com/asawaricode/settleloop/blob/main/src/evaluation/benchmarkEvaluator.js): `src/evaluation/benchmarkEvaluator.js`
- [Experiment Metrics](https://github.com/asawaricode/settleloop/blob/main/src/evaluation/metrics.js): `src/evaluation/metrics.js`

### API And Dashboard

- [Experiment API](https://github.com/asawaricode/settleloop/blob/main/src/api/routes.js): `src/api/routes.js`
- [Synthetic Data Generator](https://github.com/asawaricode/settleloop/blob/main/src/generators/syntheticDataGenerator.js): `src/generators/syntheticDataGenerator.js`
- [Express Server](https://github.com/asawaricode/settleloop/blob/main/server.js): `server.js`
- [Operator Dashboard](https://github.com/asawaricode/settleloop/blob/main/public/dashboard/app.js): `public/dashboard/app.js`

### Razorpay Test Mode

- [Signed Webhooks](https://github.com/asawaricode/settleloop/blob/main/src/api/razorpayWebhook.js): `src/api/razorpayWebhook.js`
- [Manual Test Orders](https://github.com/asawaricode/settleloop/blob/main/src/api/razorpayOrder.js): `src/api/razorpayOrder.js`

### Other components

- **Researcher / Operator**
- **Supabase**
- **Razorpay Test Mode**

## Connections

- Researcher / Operator → Paired Benchmark: runs experiment
- Paired Benchmark → Payment Simulator: simulates outcomes (evidence: `src/recovery/benchmarkRunner.js`)
- Paired Benchmark → Control Policy: evaluates arm (evidence: `src/recovery/benchmarkRunner.js`)
- Paired Benchmark → Fixed Schedule: evaluates arm (evidence: `src/recovery/benchmarkRunner.js`)
- Paired Benchmark → Salary-Aware Policy: evaluates arm (evidence: `src/recovery/benchmarkRunner.js`)
- Paired Benchmark → Smart Policy: evaluates arm (evidence: `src/recovery/benchmarkRunner.js`)
- Payment Simulator → Observation Boundary: builds observation (evidence: `src/simulators/paymentSimulator.js`)
- Payment Simulator → Virtual Clock: uses virtual time
- Smart Policy → Failure Classifier: classifies failure (evidence: `src/recovery/smartPolicy.js`)
- Smart Policy → Smart Agent: requests proposal (evidence: `src/recovery/smartPolicy.js`)
- Smart Agent → Proposal Validator: validates proposal (evidence: `src/recovery/smartAgent.js`)
- Smart Policy → Safety Guardrails: checks proposal (evidence: `src/recovery/smartPolicy.js`)
- Smart Policy → Human Approval: requests review (evidence: `src/recovery/smartPolicy.js`)
- Smart Policy → Payment Simulator: simulates attempt (evidence: `src/recovery/smartPolicy.js`)
- Smart Policy → Mandate State Machine: checks transition (evidence: `src/recovery/smartPolicy.js`)
- Recovery Engine → Control Policy: dispatches policy (evidence: `src/recovery/recoveryEngine.js`)
- Recovery Engine → Fixed Schedule: dispatches policy (evidence: `src/recovery/recoveryEngine.js`)
- Recovery Engine → Salary-Aware Policy: dispatches policy (evidence: `src/recovery/recoveryEngine.js`)
- Recovery Engine → Smart Policy: dispatches policy (evidence: `src/recovery/recoveryEngine.js`)
- Recovery Runner → Recovery Engine: processes mandates (evidence: `src/recovery/recoveryRunner.js`)
- Recovery Runner → Virtual Clock: advances simulation (evidence: `src/recovery/recoveryRunner.js`)
- Benchmark Evaluator → Paired Benchmark: runs paired trials (evidence: `src/evaluation/benchmarkEvaluator.js`)
- Benchmark Evaluator → Experiment Metrics: computes results
- Researcher / Operator → Experiment API: requests operations
- Experiment API → Synthetic Data Generator: creates cohort (evidence: `src/api/routes.js`)
- Experiment API → Recovery Runner: runs recovery (evidence: `src/api/routes.js`)
- Experiment API → Human Approval: resolves review (evidence: `src/api/routes.js`)
- Express Server → Experiment API: mounts routes (evidence: `server.js`)
- Express Server → Signed Webhooks: mounts endpoint (evidence: `server.js`)
- Express Server → Manual Test Orders: routes requests (evidence: `server.js`)
- Express Server → Operator Dashboard: serves files (evidence: `server.js`)
- Signed Webhooks → Supabase: stores events (evidence: `src/api/razorpayWebhook.js`)
- Manual Test Orders → Supabase: reads configuration (evidence: `src/api/razorpayOrder.js`)
- Manual Test Orders → Razorpay Test Mode: creates test order
- Razorpay Test Mode → Signed Webhooks: sends signed events
- Synthetic Data Generator → Supabase: persists cohort
- Experiment Metrics → Supabase: uses database
