# meter-token-prediction/meter architecture

> Architecture diagram of the GitHub repository meter-token-prediction/meter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/meter-token-prediction/meter
- Repository: https://github.com/meter-token-prediction/meter

## Overview

Meter is an inference proxy and spend-control plane. An application sends model requests to the proxy, which estimates cost, checks budgets and breaker state, routes the call to a provider, and records priced usage for analysis. Separately, the treasurer monitors wallet runway and can purchase credits under a mandate; the dashboard presents scoped ledger and treasury activity. The README also documents waste analysis and a private try-it-yourself judge console. Some subsystem wiring is inferred only from documented capabilities, so uncertain internal links are omitted.

Main entry points: [`proxy/app.py`](https://github.com/meter-token-prediction/meter/blob/main/proxy/app.py) (Inference proxy), [`dashboard/src/lib/db.ts`](https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/lib/db.ts) (Dashboard queries), [`treasury/treasurer.py`](https://github.com/meter-token-prediction/meter/blob/main/treasury/treasurer.py) (Runway treasurer), [`dashboard/src/components/judge/JudgeConsole.tsx`](https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/components/judge/JudgeConsole.tsx) (Try-it console)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference control"]
  node_proxy["Inference proxy<br/>[app.py]"]
  node_predictor["Cost predictor<br/>[engine.py]"]
  node_budget["Budget enforcement<br/>[budget.py]"]
  node_breaker["Circuit breaker<br/>[breaker.py]"]
  node_provider["Provider routing<br/>[providers.py]"]
  node_pricing["Usage pricing<br/>[pricing.py]"]
end

subgraph group_finance["Treasury"]
  node_treasurer["Runway treasurer<br/>[treasurer.py]"]
  node_treasurydb[("Treasury records<br/>[db.py]")]
  node_mandate["Mandate execution<br/>[prava.py]"]
  node_prava["Prava payment rail"]
  node_linq["Linq messaging"]
end

subgraph group_analysis["Analysis"]
  node_ledger[("Usage ledger<br/>[db.py]")]
  node_optimizer["Waste analysis<br/>[optimize.py]"]
end

subgraph group_console["Dashboard and demo"]
  node_dashboard["Control Room<br/>[page.tsx]"]
  node_dashboarddb["Dashboard queries<br/>[db.ts]"]
  node_liveapi["Live logs API<br/>[route.ts]"]
  node_treasuryapi["Treasury events API<br/>[route.ts]"]
  node_poller["Live polling<br/>[usePoll.ts]"]
  node_judgeui["Try-it console<br/>[JudgeConsole.tsx]"]
  node_judgeapi["Judge API<br/>[routes.py]"]
  node_sessions["Private sessions<br/>[sessions.py]"]
end

node_application(("Application"))
node_user(("Dashboard user"))

node_application -->|"sends requests"| node_proxy
node_proxy -->|"estimates cost"| node_predictor
node_proxy -->|"checks limits"| node_budget
node_proxy -->|"checks breaker"| node_breaker
node_proxy -->|"routes calls"| node_provider
node_provider -->|"returns response"| node_application
node_proxy -->|"prices usage"| node_pricing
node_proxy -->|"records calls"| node_ledger
node_ledger -.->|"supplies usage"| node_optimizer
node_dashboard -->|"loads views"| node_dashboarddb
node_dashboarddb -->|"queries ledger"| node_ledger
node_poller -->|"fetches logs"| node_liveapi
node_liveapi -->|"reads logs"| node_dashboarddb
node_poller -->|"fetches events"| node_treasuryapi
node_treasuryapi -->|"reads events"| node_dashboarddb
node_treasurer -->|"reads wallet state"| node_treasurydb
node_treasurer -->|"requests top-up"| node_mandate
node_mandate -->|"executes purchase"| node_prava
node_treasurer -.->|"sends alert"| node_linq
node_user -->|"starts session"| node_judgeui
node_judgeui -->|"calls console API"| node_judgeapi
node_judgeapi -->|"resolves session"| node_sessions
node_judgeapi -->|"runs prompt"| node_proxy
node_judgeui -->|"views scoped data"| node_dashboard

click node_proxy "https://github.com/meter-token-prediction/meter/blob/main/proxy/app.py"
click node_predictor "https://github.com/meter-token-prediction/meter/blob/main/predictor/engine.py"
click node_budget "https://github.com/meter-token-prediction/meter/blob/main/proxy/budget.py"
click node_breaker "https://github.com/meter-token-prediction/meter/blob/main/proxy/breaker.py"
click node_provider "https://github.com/meter-token-prediction/meter/blob/main/proxy/providers.py"
click node_pricing "https://github.com/meter-token-prediction/meter/blob/main/proxy/pricing.py"
click node_ledger "https://github.com/meter-token-prediction/meter/blob/main/proxy/db.py"
click node_optimizer "https://github.com/meter-token-prediction/meter/blob/main/predictor/optimize.py"
click node_dashboard "https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/app/(dashboard)/dashboard/page.tsx"
click node_dashboarddb "https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/lib/db.ts"
click node_liveapi "https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/app/api/live-logs/route.ts"
click node_treasuryapi "https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/app/api/treasury-events/route.ts"
click node_poller "https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/lib/usePoll.ts"
click node_treasurer "https://github.com/meter-token-prediction/meter/blob/main/treasury/treasurer.py"
click node_treasurydb "https://github.com/meter-token-prediction/meter/blob/main/treasury/db.py"
click node_mandate "https://github.com/meter-token-prediction/meter/blob/main/treasury/prava.py"
click node_judgeui "https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/components/judge/JudgeConsole.tsx"
click node_judgeapi "https://github.com/meter-token-prediction/meter/blob/main/judge/routes.py"
click node_sessions "https://github.com/meter-token-prediction/meter/blob/main/judge/sessions.py"

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_proxy,node_predictor,node_budget,node_breaker,node_provider,node_pricing,node_user toneBlue
class node_treasurer,node_treasurydb,node_mandate,node_prava,node_linq toneAmber
class node_ledger,node_optimizer toneMint
class node_dashboard,node_dashboarddb,node_liveapi,node_treasuryapi,node_poller,node_judgeui,node_judgeapi,node_sessions toneRose
class node_application toneIndigo
```

## Components

### Inference control

- [Inference proxy](https://github.com/meter-token-prediction/meter/blob/main/proxy/app.py): `proxy/app.py`
- [Cost predictor](https://github.com/meter-token-prediction/meter/blob/main/predictor/engine.py): `predictor/engine.py`
- [Budget enforcement](https://github.com/meter-token-prediction/meter/blob/main/proxy/budget.py): `proxy/budget.py`
- [Circuit breaker](https://github.com/meter-token-prediction/meter/blob/main/proxy/breaker.py): `proxy/breaker.py`
- [Provider routing](https://github.com/meter-token-prediction/meter/blob/main/proxy/providers.py): `proxy/providers.py`
- [Usage pricing](https://github.com/meter-token-prediction/meter/blob/main/proxy/pricing.py): `proxy/pricing.py`

### Treasury

- [Runway treasurer](https://github.com/meter-token-prediction/meter/blob/main/treasury/treasurer.py): `treasury/treasurer.py`
- [Treasury records](https://github.com/meter-token-prediction/meter/blob/main/treasury/db.py): `treasury/db.py`
- [Mandate execution](https://github.com/meter-token-prediction/meter/blob/main/treasury/prava.py): `treasury/prava.py`
- **Prava payment rail**
- **Linq messaging**

### Analysis

- [Usage ledger](https://github.com/meter-token-prediction/meter/blob/main/proxy/db.py): `proxy/db.py`
- [Waste analysis](https://github.com/meter-token-prediction/meter/blob/main/predictor/optimize.py): `predictor/optimize.py`

### Dashboard and demo

- [Control Room](https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/app/(dashboard)/dashboard/page.tsx): `dashboard/src/app/(dashboard)/dashboard/page.tsx`
- [Dashboard queries](https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/lib/db.ts): `dashboard/src/lib/db.ts`
- [Live logs API](https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/app/api/live-logs/route.ts): `dashboard/src/app/api/live-logs/route.ts`
- [Treasury events API](https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/app/api/treasury-events/route.ts): `dashboard/src/app/api/treasury-events/route.ts`
- [Live polling](https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/lib/usePoll.ts): `dashboard/src/lib/usePoll.ts`
- [Try-it console](https://github.com/meter-token-prediction/meter/blob/main/dashboard/src/components/judge/JudgeConsole.tsx): `dashboard/src/components/judge/JudgeConsole.tsx`
- [Judge API](https://github.com/meter-token-prediction/meter/blob/main/judge/routes.py): `judge/routes.py`
- [Private sessions](https://github.com/meter-token-prediction/meter/blob/main/judge/sessions.py): `judge/sessions.py`

### Other components

- **Application**
- **Dashboard user**

## Connections

- Application → Inference proxy: sends requests
- Inference proxy → Cost predictor: estimates cost
- Inference proxy → Budget enforcement: checks limits
- Inference proxy → Circuit breaker: checks breaker
- Inference proxy → Provider routing: routes calls
- Provider routing → Application: returns response
- Inference proxy → Usage pricing: prices usage
- Inference proxy → Usage ledger: records calls
- Usage ledger → Waste analysis: supplies usage
- Control Room → Dashboard queries: loads views
- Dashboard queries → Usage ledger: queries ledger
- Live polling → Live logs API: fetches logs
- Live logs API → Dashboard queries: reads logs
- Live polling → Treasury events API: fetches events
- Treasury events API → Dashboard queries: reads events
- Runway treasurer → Treasury records: reads wallet state
- Runway treasurer → Mandate execution: requests top-up
- Mandate execution → Prava payment rail: executes purchase
- Runway treasurer → Linq messaging: sends alert
- Dashboard user → Try-it console: starts session
- Try-it console → Judge API: calls console API
- Judge API → Private sessions: resolves session
- Judge API → Inference proxy: runs prompt
- Try-it console → Control Room: views scoped data
