# data-guru0/financial-agent-with-ai-governance architecture

> Architecture diagram of the GitHub repository data-guru0/financial-agent-with-ai-governance, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/data-guru0/financial-agent-with-ai-governance
- Repository: https://github.com/data-guru0/financial-agent-with-ai-governance

## Overview

Custodian is a governed invoice-processing and payment platform. A user submits invoice text or an image; the backend routes images through an isolated OCR sandbox, then runs the agent graph for extraction, risk assessment, approval, and payment. Policy decisions, ledger activity, and control-plane events are audited, while the console exposes operational controls. The README documents these capabilities; several agent and console implementations were not excerpted, so their internal links are omitted. Edges reflect shown calls or explicit documentation.

Main entry points: [`custodian-backend/app/graph.py`](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/graph.py) (Agent workflow), [`infra/policy-service/app/main.py`](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/infra/policy-service/app/main.py) (Policy decision service), [`custodian-backend/app/llm_clients.py`](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/llm_clients.py) (LLM gateway client), [`custodian-data-loader/main.py`](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-data-loader/main.py) (Dataset loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_intake["Invoice intake"]
  node_backend["Run API<br/>[main.py]"]
  node_sandbox["OCR sandbox runner<br/>[main.py]"]
  node_ocr["Sandbox OCR<br/>[ocr.py]"]
end

subgraph group_runtime["Agent runtime"]
  node_agentgraph["Agent workflow<br/>[graph.py]"]
  node_extract["Invoice extraction<br/>[extraction.py]"]
  node_risk["Risk scoring<br/>[risk_scoring.py]"]
  node_approval["Approval routing<br/>[approval.py]"]
  node_payment["Payment execution"]
  node_llm["LLM gateway client<br/>[llm_clients.py]"]
end

subgraph group_governance["Policy and oversight"]
  node_policy["Policy decision service<br/>[main.py]"]
  node_cedar["Cedar authorization<br/>[cedar_engine.py]"]
  node_temporal["Temporal limits<br/>[temporal.py]"]
  node_control["Kill switch<br/>[main.py]"]
  node_audit[("Tamper-proof audit<br/>[main.py]")]
end

subgraph group_finance["Finance data"]
  node_ledger[("Payment ledger<br/>[main.py]")]
  node_loader["Dataset loader<br/>[main.py]"]
  node_loadinvoices["Invoice dataset load<br/>[load_invoices.py]"]
  node_loadvendors["Vendor dataset load<br/>[load_vendors.py]"]
  node_validate["Dataset validation<br/>[validate.py]"]
end

subgraph group_operations["Operations console"]
  node_console["Operations console<br/>[page.tsx]"]
  node_killapi["Kill-switch API<br/>[route.ts]"]
  node_policyapi["Policy file API<br/>[route.ts]"]
end

node_user(("Invoice operator"))

node_user -->|"submits invoices"| node_backend
node_backend -->|"requests OCR"| node_sandbox
node_sandbox -->|"authorizes spawn"| node_policy
node_sandbox -->|"runs sandbox image"| node_ocr
node_backend -->|"starts workflow"| node_agentgraph
node_agentgraph -.->|"runs extraction"| node_extract
node_agentgraph -.->|"runs risk scoring"| node_risk
node_agentgraph -.->|"routes approval"| node_approval
node_agentgraph -.->|"executes payment"| node_payment
node_extract -.->|"uses model"| node_llm
node_risk -.->|"uses model"| node_llm
node_approval -.->|"uses model"| node_llm
node_payment -.->|"uses model"| node_llm
node_policy -->|"evaluates rules"| node_cedar
node_policy -->|"checks limits"| node_temporal
node_policy -->|"checks status"| node_control
node_policy -->|"records decisions"| node_audit
node_control -->|"records events"| node_audit
node_ledger -->|"records transactions"| node_audit
node_payment -.->|"records settled payment"| node_ledger
node_loader -->|"loads corpus"| node_loadinvoices
node_loader -->|"loads vendors"| node_loadvendors
node_loader -->|"validates data"| node_validate
node_console -.->|"manages controls"| node_killapi
node_killapi -->|"trips or resets"| node_control
node_policyapi -.->|"serves policy files"| node_console

click node_backend "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/main.py"
click node_sandbox "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-sandbox-runner/app/main.py"
click node_ocr "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-sandbox-ocr/ocr.py"
click node_agentgraph "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/graph.py"
click node_extract "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/nodes/extraction.py"
click node_risk "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/nodes/risk_scoring.py"
click node_approval "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/nodes/approval.py"
click node_payment "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/nodes/payment_execution.py"
click node_llm "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/llm_clients.py"
click node_policy "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/infra/policy-service/app/main.py"
click node_cedar "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/infra/policy-service/app/cedar_engine.py"
click node_temporal "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/infra/policy-service/app/temporal.py"
click node_control "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-control-plane/app/main.py"
click node_audit "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-audit-log/app/main.py"
click node_ledger "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-ledger/app/main.py"
click node_loader "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-data-loader/main.py"
click node_loadinvoices "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-data-loader/loader/load_invoices.py"
click node_loadvendors "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-data-loader/loader/load_vendors.py"
click node_validate "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-data-loader/loader/validate.py"
click node_console "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-console/app/page.tsx"
click node_killapi "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-console/app/api/kill-switch/route.ts"
click node_policyapi "https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-console/app/api/policies/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_backend,node_sandbox,node_ocr toneBlue
class node_agentgraph,node_extract,node_risk,node_approval,node_payment,node_llm toneAmber
class node_policy,node_cedar,node_temporal,node_control,node_audit toneMint
class node_ledger,node_loader,node_loadinvoices,node_loadvendors,node_validate toneRose
class node_console,node_killapi,node_policyapi,node_user toneIndigo
```

## Components

### Invoice intake

- [Run API](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/main.py): `custodian-backend/app/main.py`
- [OCR sandbox runner](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-sandbox-runner/app/main.py): `custodian-sandbox-runner/app/main.py`
- [Sandbox OCR](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-sandbox-ocr/ocr.py): `custodian-sandbox-ocr/ocr.py`

### Agent runtime

- [Agent workflow](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/graph.py): `custodian-backend/app/graph.py`
- [Invoice extraction](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/nodes/extraction.py): `custodian-backend/app/nodes/extraction.py`
- [Risk scoring](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/nodes/risk_scoring.py): `custodian-backend/app/nodes/risk_scoring.py`
- [Approval routing](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/nodes/approval.py): `custodian-backend/app/nodes/approval.py`
- [Payment execution](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/nodes/payment_execution.py): `custodian-backend/app/nodes/payment_execution.py`
- [LLM gateway client](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-backend/app/llm_clients.py): `custodian-backend/app/llm_clients.py`

### Policy and oversight

- [Policy decision service](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/infra/policy-service/app/main.py): `infra/policy-service/app/main.py`
- [Cedar authorization](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/infra/policy-service/app/cedar_engine.py): `infra/policy-service/app/cedar_engine.py`
- [Temporal limits](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/infra/policy-service/app/temporal.py): `infra/policy-service/app/temporal.py`
- [Kill switch](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-control-plane/app/main.py): `custodian-control-plane/app/main.py`
- [Tamper-proof audit](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-audit-log/app/main.py): `custodian-audit-log/app/main.py`

### Finance data

- [Payment ledger](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-ledger/app/main.py): `custodian-ledger/app/main.py`
- [Dataset loader](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-data-loader/main.py): `custodian-data-loader/main.py`
- [Invoice dataset load](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-data-loader/loader/load_invoices.py): `custodian-data-loader/loader/load_invoices.py`
- [Vendor dataset load](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-data-loader/loader/load_vendors.py): `custodian-data-loader/loader/load_vendors.py`
- [Dataset validation](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-data-loader/loader/validate.py): `custodian-data-loader/loader/validate.py`

### Operations console

- [Operations console](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-console/app/page.tsx): `custodian-console/app/page.tsx`
- [Kill-switch API](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-console/app/api/kill-switch/route.ts): `custodian-console/app/api/kill-switch/route.ts`
- [Policy file API](https://github.com/data-guru0/financial-agent-with-ai-governance/blob/main/custodian-console/app/api/policies/route.ts): `custodian-console/app/api/policies/route.ts`

### Other components

- **Invoice operator**

## Connections

- Invoice operator → Run API: submits invoices (evidence: `custodian-backend/app/main.py`)
- Run API → OCR sandbox runner: requests OCR (evidence: `custodian-backend/app/main.py`)
- OCR sandbox runner → Policy decision service: authorizes spawn (evidence: `custodian-sandbox-runner/app/main.py`)
- OCR sandbox runner → Sandbox OCR: runs sandbox image (evidence: `custodian-sandbox-runner/app/main.py`)
- Run API → Agent workflow: starts workflow (evidence: `custodian-backend/app/main.py`)
- Agent workflow → Invoice extraction: runs extraction
- Agent workflow → Risk scoring: runs risk scoring
- Agent workflow → Approval routing: routes approval
- Agent workflow → Payment execution: executes payment
- Invoice extraction → LLM gateway client: uses model
- Risk scoring → LLM gateway client: uses model
- Approval routing → LLM gateway client: uses model
- Payment execution → LLM gateway client: uses model
- Policy decision service → Cedar authorization: evaluates rules (evidence: `infra/policy-service/app/main.py`)
- Policy decision service → Temporal limits: checks limits (evidence: `infra/policy-service/app/main.py`)
- Policy decision service → Kill switch: checks status (evidence: `infra/policy-service/app/main.py`)
- Policy decision service → Tamper-proof audit: records decisions (evidence: `infra/policy-service/app/main.py`)
- Kill switch → Tamper-proof audit: records events (evidence: `custodian-control-plane/app/main.py`)
- Payment ledger → Tamper-proof audit: records transactions (evidence: `custodian-ledger/app/main.py`)
- Payment execution → Payment ledger: records settled payment (evidence: `custodian-ledger/app/main.py`)
- Dataset loader → Invoice dataset load: loads corpus (evidence: `custodian-data-loader/main.py`)
- Dataset loader → Vendor dataset load: loads vendors (evidence: `custodian-data-loader/main.py`)
- Dataset loader → Dataset validation: validates data (evidence: `custodian-data-loader/main.py`)
- Operations console → Kill-switch API: manages controls
- Kill-switch API → Kill switch: trips or resets (evidence: `custodian-console/app/api/kill-switch/route.ts`)
- Policy file API → Operations console: serves policy files
