# soham5bagh/fraudlens architecture

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

## Overview

FraudLens is a human-led fraud investigation desk for synthetic Indian payment data: a local Python engine prepares and scores a seeded book, while the Next.js desk serves queued cases and lets analysts investigate fresh seeded payments in-browser. The workflow ends with a person recording approve, hold, escalate, or block; the agent recommends but does not act. The graph preserves the documented evaluation, reporting, guided-demo, and live-investigation branches. Most source was not excerpted, so internal links rely on the README’s architecture description; UI/API links are included only where documented or excerpted.

Main entry points: [`components/investigate-desk.tsx`](https://github.com/soham5bagh/fraudlens/blob/main/components/investigate-desk.tsx) (Investigation desk), [`engine/agent.py`](https://github.com/soham5bagh/fraudlens/blob/main/engine/agent.py) (Investigation agent), [`engine/metrics.py`](https://github.com/soham5bagh/fraudlens/blob/main/engine/metrics.py) (Scorecard metrics), [`engine/flagging.py`](https://github.com/soham5bagh/fraudlens/blob/main/engine/flagging.py) (Payment flagger)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_engine["Python book engine"]
  node_generator["Book generator<br/>[generate.py]"]
  node_ledger[("SQLite ledger")]
  node_flagger["Payment flagger<br/>[flagging.py]"]
  node_python_agent["Investigation agent<br/>[agent.py]"]
  node_evaluation["Label evaluation<br/>[evaluate.py]"]
  node_metrics_engine["Scorecard metrics<br/>[metrics.py]"]
  node_reporting["Book reports<br/>[reports.py]"]
end

subgraph group_desk["Analyst desk"]
  node_queue_api["Queue API<br/>[route.ts]"]
  node_case_api["Case API<br/>[route.ts]"]
  node_metrics_api["Metrics API<br/>[route.ts]"]
  node_report_api["Report API<br/>[route.ts]"]
  node_queue_ui["Review queue<br/>[queue-board.tsx]"]
  node_case_ui["Case file<br/>[case-file.tsx]"]
  node_metrics_ui["Results scorecard<br/>[metrics-board.tsx]"]
  node_guided_demo["Guided demo<br/>[demo-walk.tsx]"]
  node_decision_api["Decision API<br/>[route.ts]"]
end

subgraph group_live["Live investigation"]
  node_live_page["Live page<br/>[page.tsx]"]
  node_live_desk["Investigation desk"]
  node_live_generator["Seeded payment builder<br/>[generate.ts]"]
  node_live_engine["Browser investigator<br/>[investigate.ts]"]
end

subgraph group_data["Seeded data and decisions"]
  node_seed_files["Committed case data"]
  node_browser_store[("Browser decisions")]
end

node_analyst(("Analyst"))

node_generator -->|"writes ledger"| node_ledger
node_ledger -->|"supplies payments"| node_flagger
node_flagger -->|"flags cases"| node_python_agent
node_python_agent -->|"exports cases"| node_seed_files
node_python_agent -->|"scores investigations"| node_metrics_engine
node_metrics_engine -->|"exports results"| node_seed_files
node_evaluation -->|"evaluates labels"| node_metrics_engine
node_seed_files -->|"serves queue data"| node_queue_api
node_seed_files -->|"serves case data"| node_case_api
node_seed_files -->|"serves metrics"| node_metrics_api
node_queue_ui -->|"presents cases"| node_analyst
node_case_ui -->|"shows evidence"| node_analyst
node_metrics_ui -->|"presents results"| node_analyst
node_guided_demo -->|"walks scenarios"| node_analyst
node_analyst -->|"records action"| node_decision_api
node_decision_api -->|"appends decisions"| node_browser_store
node_analyst -->|"opens investigation"| node_live_page
node_live_page -->|"renders desk"| node_live_desk
node_live_desk -->|"builds payment"| node_live_generator
node_live_desk -->|"runs investigation"| node_live_engine
node_live_desk -->|"shows recommendation"| node_analyst
node_report_api -->|"downloads report"| node_analyst
node_metrics_api -.->|"provides scorecard"| node_metrics_ui
node_queue_api -.->|"provides queue"| node_queue_ui
node_case_api -.->|"provides case"| node_case_ui

click node_generator "https://github.com/soham5bagh/fraudlens/blob/main/engine/generate.py"
click node_flagger "https://github.com/soham5bagh/fraudlens/blob/main/engine/flagging.py"
click node_python_agent "https://github.com/soham5bagh/fraudlens/blob/main/engine/agent.py"
click node_evaluation "https://github.com/soham5bagh/fraudlens/blob/main/engine/evaluate.py"
click node_metrics_engine "https://github.com/soham5bagh/fraudlens/blob/main/engine/metrics.py"
click node_reporting "https://github.com/soham5bagh/fraudlens/blob/main/engine/reports.py"
click node_queue_api "https://github.com/soham5bagh/fraudlens/blob/main/app/api/queue/route.ts"
click node_case_api "https://github.com/soham5bagh/fraudlens/blob/main/app/api/cases/%5Bid%5D/route.ts"
click node_metrics_api "https://github.com/soham5bagh/fraudlens/blob/main/app/api/metrics/route.ts"
click node_report_api "https://github.com/soham5bagh/fraudlens/blob/main/app/api/report/route.ts"
click node_queue_ui "https://github.com/soham5bagh/fraudlens/blob/main/components/queue-board.tsx"
click node_case_ui "https://github.com/soham5bagh/fraudlens/blob/main/components/case-file.tsx"
click node_metrics_ui "https://github.com/soham5bagh/fraudlens/blob/main/components/metrics-board.tsx"
click node_guided_demo "https://github.com/soham5bagh/fraudlens/blob/main/components/demo-walk.tsx"
click node_live_page "https://github.com/soham5bagh/fraudlens/blob/main/app/investigate/page.tsx"
click node_live_desk "https://github.com/soham5bagh/fraudlens/blob/main/components/investigate-desk.tsx"
click node_live_generator "https://github.com/soham5bagh/fraudlens/blob/main/lib/live/generate.ts"
click node_live_engine "https://github.com/soham5bagh/fraudlens/blob/main/lib/live/investigate.ts"
click node_decision_api "https://github.com/soham5bagh/fraudlens/blob/main/app/api/decisions/route.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_generator,node_ledger,node_flagger,node_python_agent,node_evaluation,node_metrics_engine,node_reporting toneBlue
class node_queue_api,node_case_api,node_metrics_api,node_report_api,node_queue_ui,node_case_ui,node_metrics_ui,node_guided_demo,node_decision_api toneAmber
class node_live_page,node_live_desk,node_live_generator,node_live_engine toneMint
class node_seed_files,node_browser_store toneRose
class node_analyst toneIndigo
```

## Components

### Python book engine

- [Book generator](https://github.com/soham5bagh/fraudlens/blob/main/engine/generate.py): `engine/generate.py`
- **SQLite ledger**
- [Payment flagger](https://github.com/soham5bagh/fraudlens/blob/main/engine/flagging.py): `engine/flagging.py`
- [Investigation agent](https://github.com/soham5bagh/fraudlens/blob/main/engine/agent.py): `engine/agent.py`
- [Label evaluation](https://github.com/soham5bagh/fraudlens/blob/main/engine/evaluate.py): `engine/evaluate.py`
- [Scorecard metrics](https://github.com/soham5bagh/fraudlens/blob/main/engine/metrics.py): `engine/metrics.py`
- [Book reports](https://github.com/soham5bagh/fraudlens/blob/main/engine/reports.py): `engine/reports.py`

### Analyst desk

- [Queue API](https://github.com/soham5bagh/fraudlens/blob/main/app/api/queue/route.ts): `app/api/queue/route.ts`
- [Case API](https://github.com/soham5bagh/fraudlens/blob/main/app/api/cases/%5Bid%5D/route.ts): `app/api/cases/[id]/route.ts`
- [Metrics API](https://github.com/soham5bagh/fraudlens/blob/main/app/api/metrics/route.ts): `app/api/metrics/route.ts`
- [Report API](https://github.com/soham5bagh/fraudlens/blob/main/app/api/report/route.ts): `app/api/report/route.ts`
- [Review queue](https://github.com/soham5bagh/fraudlens/blob/main/components/queue-board.tsx): `components/queue-board.tsx`
- [Case file](https://github.com/soham5bagh/fraudlens/blob/main/components/case-file.tsx): `components/case-file.tsx`
- [Results scorecard](https://github.com/soham5bagh/fraudlens/blob/main/components/metrics-board.tsx): `components/metrics-board.tsx`
- [Guided demo](https://github.com/soham5bagh/fraudlens/blob/main/components/demo-walk.tsx): `components/demo-walk.tsx`
- [Decision API](https://github.com/soham5bagh/fraudlens/blob/main/app/api/decisions/route.ts): `app/api/decisions/route.ts`

### Live investigation

- [Live page](https://github.com/soham5bagh/fraudlens/blob/main/app/investigate/page.tsx): `app/investigate/page.tsx`
- [Investigation desk](https://github.com/soham5bagh/fraudlens/blob/main/components/investigate-desk.tsx): `components/investigate-desk.tsx`
- [Seeded payment builder](https://github.com/soham5bagh/fraudlens/blob/main/lib/live/generate.ts): `lib/live/generate.ts`
- [Browser investigator](https://github.com/soham5bagh/fraudlens/blob/main/lib/live/investigate.ts): `lib/live/investigate.ts`

### Seeded data and decisions

- **Committed case data**
- **Browser decisions**

### Other components

- **Analyst**

## Connections

- Book generator → SQLite ledger: writes ledger (evidence: `README.md`)
- SQLite ledger → Payment flagger: supplies payments (evidence: `README.md`)
- Payment flagger → Investigation agent: flags cases (evidence: `README.md`)
- Investigation agent → Committed case data: exports cases (evidence: `README.md`)
- Investigation agent → Scorecard metrics: scores investigations (evidence: `README.md`)
- Scorecard metrics → Committed case data: exports results (evidence: `README.md`)
- Label evaluation → Scorecard metrics: evaluates labels (evidence: `README.md`)
- Committed case data → Queue API: serves queue data (evidence: `README.md`)
- Committed case data → Case API: serves case data (evidence: `app/api/cases/[id]/route.ts`)
- Committed case data → Metrics API: serves metrics (evidence: `app/api/metrics/route.ts`)
- Review queue → Analyst: presents cases (evidence: `README.md`)
- Case file → Analyst: shows evidence (evidence: `README.md`)
- Results scorecard → Analyst: presents results (evidence: `README.md`)
- Guided demo → Analyst: walks scenarios (evidence: `README.md`)
- Analyst → Decision API: records action (evidence: `README.md`)
- Decision API → Browser decisions: appends decisions (evidence: `README.md`)
- Analyst → Live page: opens investigation (evidence: `README.md`)
- Live page → Investigation desk: renders desk (evidence: `app/investigate/page.tsx`)
- Investigation desk → Seeded payment builder: builds payment (evidence: `README.md`)
- Investigation desk → Browser investigator: runs investigation (evidence: `README.md`)
- Investigation desk → Analyst: shows recommendation (evidence: `README.md`)
- Report API → Analyst: downloads report (evidence: `README.md`)
- Metrics API → Results scorecard: provides scorecard
- Queue API → Review queue: provides queue
- Case API → Case file: provides case
