# jrastit/agent-router architecture

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

- Interactive diagram: https://gitdiagram.com/jrastit/agent-router
- Repository: https://github.com/jrastit/agent-router

## Overview

AgentRouter’s primary product is a reusable 0G model-routing and provenance toolkit; the Next.js application is a demonstration surface rather than the main artifact. The documented workflow is to discover model routes, apply caller policy deterministically, execute through 0G Compute, and preserve evidence using storage and chain provenance. The repository also exposes an example LLM-job and payment-evidence application. Some toolkit integrations and application subsystems are represented from README capabilities and the file tree; their internal wiring was not sampled, so those links are documented rather than inferred from imports.

Main entry points: [`src/lib/llm-jobs/submission.ts`](https://github.com/jrastit/agent-router/blob/main/src/lib/llm-jobs/submission.ts) (LLM Job Submission), [`src/toolkit/router.ts`](https://github.com/jrastit/agent-router/blob/main/src/toolkit/router.ts) (Policy Router), [`src/toolkit/compute/0g-router.ts`](https://github.com/jrastit/agent-router/blob/main/src/toolkit/compute/0g-router.ts) (0G Compute), [`src/toolkit/receipt.ts`](https://github.com/jrastit/agent-router/blob/main/src/toolkit/receipt.ts) (Routing Receipt)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_toolkit["Reusable Toolkit"]
  node_model_catalog["Model Catalog<br/>[0g-router.ts]"]
  node_router["Policy Router<br/>[router.ts]"]
  node_contracts["Toolkit Contracts<br/>[contracts.ts]"]
end

subgraph group_runtime["0G Runtime"]
  node_compute["0G Compute<br/>[0g-router.ts]"]
  node_storage["0G Storage<br/>[0g.ts]"]
  node_receipt["Routing Receipt<br/>[receipt.ts]"]
  node_chain["0G Chain Proof<br/>[0g-chain.ts]"]
end

subgraph group_example["Example Application"]
  node_example_ui["Example UI<br/>[page.tsx]"]
  node_planner["Requirement Planner<br/>[planner.ts]"]
  node_discovery["Provider Discovery<br/>[graph.ts]"]
  node_jobs["LLM Job Submission<br/>[submission.ts]"]
  node_execution["Job Execution"]
  node_supabase[("Supabase State")]
end

subgraph group_evidence["Evidence Services"]
  node_hedera["HBAR Settlement<br/>[settle.ts]"]
  node_projection["Activity Projection<br/>[graph.ts]"]
  node_mcp["Graph Evidence MCP<br/>[server.ts]"]
  node_graph_client["Graph Evidence Client<br/>[graph-client.ts]"]
end

node_agent(("Agent Developer"))

node_agent -->|"uses toolkit"| node_model_catalog
node_model_catalog -->|"supplies routes"| node_router
node_router -->|"selects route"| node_compute
node_compute -->|"records execution"| node_receipt
node_storage -->|"stores evidence"| node_receipt
node_receipt -->|"anchors hash"| node_chain
node_chain -->|"verifies receipt"| node_agent
node_agent -->|"tries example"| node_example_ui
node_example_ui -.->|"submits request"| node_planner
node_planner -->|"derives requirements"| node_discovery
node_discovery -->|"offers candidates"| node_jobs
node_jobs -.->|"creates job"| node_execution
node_execution -.->|"persists state"| node_supabase
node_jobs -->|"settles payment"| node_hedera
node_hedera -->|"emits audit events"| node_projection
node_projection -.->|"indexes evidence"| node_graph_client
node_graph_client -->|"provides evidence tools"| node_mcp
node_contracts -->|"defines interfaces"| node_router
node_contracts -->|"defines adapter"| node_compute

click node_model_catalog "https://github.com/jrastit/agent-router/blob/main/src/toolkit/catalog/0g-router.ts"
click node_router "https://github.com/jrastit/agent-router/blob/main/src/toolkit/router.ts"
click node_contracts "https://github.com/jrastit/agent-router/blob/main/src/toolkit/contracts.ts"
click node_compute "https://github.com/jrastit/agent-router/blob/main/src/toolkit/compute/0g-router.ts"
click node_storage "https://github.com/jrastit/agent-router/blob/main/src/toolkit/storage/0g.ts"
click node_receipt "https://github.com/jrastit/agent-router/blob/main/src/toolkit/receipt.ts"
click node_chain "https://github.com/jrastit/agent-router/blob/main/src/toolkit/provenance/0g-chain.ts"
click node_example_ui "https://github.com/jrastit/agent-router/blob/main/src/app/page.tsx"
click node_planner "https://github.com/jrastit/agent-router/blob/main/src/lib/planner/planner.ts"
click node_discovery "https://github.com/jrastit/agent-router/blob/main/src/lib/discovery/graph.ts"
click node_jobs "https://github.com/jrastit/agent-router/blob/main/src/lib/llm-jobs/submission.ts"
click node_execution "https://github.com/jrastit/agent-router/blob/main/src/lib/llm-jobs/supabase-execution.ts"
click node_hedera "https://github.com/jrastit/agent-router/blob/main/src/lib/payment/settle.ts"
click node_projection "https://github.com/jrastit/agent-router/blob/main/src/lib/projection/graph.ts"
click node_mcp "https://github.com/jrastit/agent-router/blob/main/src/mcp/graph-evidence/server.ts"
click node_graph_client "https://github.com/jrastit/agent-router/blob/main/src/mcp/graph-evidence/graph-client.ts"
click node_supabase "https://github.com/jrastit/agent-router/blob/main/src/lib/llm-jobs/supabase-execution.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_model_catalog,node_router,node_contracts toneBlue
class node_compute,node_storage,node_receipt,node_chain toneAmber
class node_example_ui,node_planner,node_discovery,node_jobs,node_execution,node_supabase toneMint
class node_hedera,node_projection,node_mcp,node_graph_client toneRose
class node_agent toneIndigo
```

## Components

### Reusable Toolkit

- [Model Catalog](https://github.com/jrastit/agent-router/blob/main/src/toolkit/catalog/0g-router.ts): `src/toolkit/catalog/0g-router.ts`
- [Policy Router](https://github.com/jrastit/agent-router/blob/main/src/toolkit/router.ts): `src/toolkit/router.ts`
- [Toolkit Contracts](https://github.com/jrastit/agent-router/blob/main/src/toolkit/contracts.ts): `src/toolkit/contracts.ts`

### 0G Runtime

- [0G Compute](https://github.com/jrastit/agent-router/blob/main/src/toolkit/compute/0g-router.ts): `src/toolkit/compute/0g-router.ts`
- [0G Storage](https://github.com/jrastit/agent-router/blob/main/src/toolkit/storage/0g.ts): `src/toolkit/storage/0g.ts`
- [Routing Receipt](https://github.com/jrastit/agent-router/blob/main/src/toolkit/receipt.ts): `src/toolkit/receipt.ts`
- [0G Chain Proof](https://github.com/jrastit/agent-router/blob/main/src/toolkit/provenance/0g-chain.ts): `src/toolkit/provenance/0g-chain.ts`

### Example Application

- [Example UI](https://github.com/jrastit/agent-router/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [Requirement Planner](https://github.com/jrastit/agent-router/blob/main/src/lib/planner/planner.ts): `src/lib/planner/planner.ts`
- [Provider Discovery](https://github.com/jrastit/agent-router/blob/main/src/lib/discovery/graph.ts): `src/lib/discovery/graph.ts`
- [LLM Job Submission](https://github.com/jrastit/agent-router/blob/main/src/lib/llm-jobs/submission.ts): `src/lib/llm-jobs/submission.ts`
- [Job Execution](https://github.com/jrastit/agent-router/blob/main/src/lib/llm-jobs/supabase-execution.ts): `src/lib/llm-jobs/supabase-execution.ts`
- [Supabase State](https://github.com/jrastit/agent-router/blob/main/src/lib/llm-jobs/supabase-execution.ts): `src/lib/llm-jobs/supabase-execution.ts`

### Evidence Services

- [HBAR Settlement](https://github.com/jrastit/agent-router/blob/main/src/lib/payment/settle.ts): `src/lib/payment/settle.ts`
- [Activity Projection](https://github.com/jrastit/agent-router/blob/main/src/lib/projection/graph.ts): `src/lib/projection/graph.ts`
- [Graph Evidence MCP](https://github.com/jrastit/agent-router/blob/main/src/mcp/graph-evidence/server.ts): `src/mcp/graph-evidence/server.ts`
- [Graph Evidence Client](https://github.com/jrastit/agent-router/blob/main/src/mcp/graph-evidence/graph-client.ts): `src/mcp/graph-evidence/graph-client.ts`

### Other components

- **Agent Developer**

## Connections

- Agent Developer → Model Catalog: uses toolkit (evidence: `README.md`)
- Model Catalog → Policy Router: supplies routes (evidence: `README.md`)
- Policy Router → 0G Compute: selects route (evidence: `README.md`)
- 0G Compute → Routing Receipt: records execution (evidence: `README.md`)
- 0G Storage → Routing Receipt: stores evidence (evidence: `README.md`)
- Routing Receipt → 0G Chain Proof: anchors hash (evidence: `README.md`)
- 0G Chain Proof → Agent Developer: verifies receipt (evidence: `README.md`)
- Agent Developer → Example UI: tries example (evidence: `README.md`)
- Example UI → Requirement Planner: submits request
- Requirement Planner → Provider Discovery: derives requirements (evidence: `README.md`)
- Provider Discovery → LLM Job Submission: offers candidates (evidence: `README.md`)
- LLM Job Submission → Job Execution: creates job
- Job Execution → Supabase State: persists state
- LLM Job Submission → HBAR Settlement: settles payment (evidence: `README.md`)
- HBAR Settlement → Activity Projection: emits audit events (evidence: `README.md`)
- Activity Projection → Graph Evidence Client: indexes evidence
- Graph Evidence Client → Graph Evidence MCP: provides evidence tools (evidence: `src/mcp/graph-evidence/server.ts`)
- Toolkit Contracts → Policy Router: defines interfaces (evidence: `src/toolkit/router.ts`)
- Toolkit Contracts → 0G Compute: defines adapter (evidence: `src/toolkit/compute/0g-router.ts`)
