# yanstd888/9routerx architecture

> Architecture diagram of the GitHub repository yanstd888/9routerx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yanstd888/9routerx
- Repository: https://github.com/yanstd888/9routerx

## Overview

9RouterX is a self-hosted Go LLM gateway with an embedded Svelte dashboard. A client sends a compatible inference request to the local gateway; the gateway handles compatibility and policy, routes it to a provider, and returns the response. Its broader product includes provider connections, quota-aware cascades, token reduction, governance, caching, health recovery, and operational dashboards. The README supports the product-level flow and capabilities; sampled source shows dashboard routing and API-client responsibilities, but not the gateway’s internal call chain, so those links are omitted or marked unverified.

Main entry points: [`internal/handlers/chat`](https://github.com/yanstd888/9routerx/tree/main/internal/handlers/chat) (Chat Routing), [`internal/proxy`](https://github.com/yanstd888/9routerx/tree/main/internal/proxy) (Provider Execution), [`internal/handlers/router.go`](https://github.com/yanstd888/9routerx/blob/main/internal/handlers/router.go) (API Routes), [`internal/app/server.go`](https://github.com/yanstd888/9routerx/blob/main/internal/app/server.go) (Local Gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway and Routing"]
  node_gateway["Local Gateway<br/>[server.go]"]
  node_api_routes["API Routes<br/>[router.go]"]
  node_translation["Format Translation<br/>[client_format.go]"]
  node_chat["Chat Routing"]
  node_proxy["Provider Execution"]
  node_tokensaver["Token Saver"]
  node_compression["Output Compression"]
end

subgraph group_providers["Providers and Accounts"]
  node_connections["Provider Connections"]
  node_provider_registry["Provider Catalog"]
end

subgraph group_governance["Governance and Reliability"]
  node_governance["Keys and Guardrails"]
  node_budget["Per-key Budgets"]
  node_health["Health and Recovery"]
  node_cache["Request Caches"]
end

subgraph group_operations["Operations and Dashboard"]
  node_database[("SQLite State")]
  node_dashboard["Web Dashboard<br/>[App.svelte]"]
  node_dashboard_api["Dashboard API Client<br/>[client.ts]"]
  node_admin_handlers["Admin Handlers<br/>[routes.go]"]
  node_mcp_a2a["MCP and A2A"]
  node_mitm["MITM Inspector<br/>[server.go]"]
end

node_client(("AI Client"))
node_upstream{{"AI Providers"}}

node_client -->|"sends requests"| node_gateway
node_gateway -.->|"routes requests"| node_api_routes
node_api_routes -.->|"adapts formats"| node_translation
node_api_routes -.->|"dispatches inference"| node_chat
node_chat -.->|"forwards upstream"| node_proxy
node_proxy -->|"sends provider calls"| node_upstream
node_proxy -.->|"returns responses"| node_client
node_chat -->|"reduces context"| node_tokensaver
node_chat -->|"compresses output"| node_compression
node_client -->|"configures gateway"| node_dashboard
node_dashboard -->|"calls API"| node_dashboard_api
node_dashboard_api -->|"requests admin operations"| node_admin_handlers
node_admin_handlers -.->|"reads and writes"| node_database
node_connections -.->|"stores credentials"| node_database
node_provider_registry -.->|"selects providers"| node_proxy
node_chat -->|"enforces policies"| node_governance
node_chat -->|"checks spend limits"| node_budget
node_chat -->|"avoids degraded nodes"| node_health
node_chat -->|"checks semantic cache"| node_cache
node_client -->|"uses tool protocols"| node_mcp_a2a
node_upstream -.->|"traffic inspection"| node_mitm

click node_gateway "https://github.com/yanstd888/9routerx/blob/main/internal/app/server.go"
click node_api_routes "https://github.com/yanstd888/9routerx/blob/main/internal/handlers/router.go"
click node_translation "https://github.com/yanstd888/9routerx/blob/main/internal/translator/client_format.go"
click node_chat "https://github.com/yanstd888/9routerx/tree/main/internal/handlers/chat"
click node_proxy "https://github.com/yanstd888/9routerx/tree/main/internal/proxy"
click node_tokensaver "https://github.com/yanstd888/9routerx/tree/main/internal/tokensaver"
click node_compression "https://github.com/yanstd888/9routerx/tree/main/internal/compression"
click node_connections "https://github.com/yanstd888/9routerx/tree/main/internal/handlers/oauth"
click node_provider_registry "https://github.com/yanstd888/9routerx/tree/main/internal/providers"
click node_database "https://github.com/yanstd888/9routerx/tree/main/internal/db"
click node_governance "https://github.com/yanstd888/9routerx/tree/main/internal/guardrails"
click node_budget "https://github.com/yanstd888/9routerx/tree/main/internal/budget"
click node_health "https://github.com/yanstd888/9routerx/tree/main/internal/resilience"
click node_cache "https://github.com/yanstd888/9routerx/tree/main/internal/semanticcache"
click node_dashboard "https://github.com/yanstd888/9routerx/blob/main/web/src/App.svelte"
click node_dashboard_api "https://github.com/yanstd888/9routerx/blob/main/web/src/api/client.ts"
click node_admin_handlers "https://github.com/yanstd888/9routerx/blob/main/internal/handlers/dashboard/routes.go"
click node_mcp_a2a "https://github.com/yanstd888/9routerx/tree/main/internal/mcpserver"
click node_mitm "https://github.com/yanstd888/9routerx/blob/main/internal/mitm/server.go"

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_gateway,node_api_routes,node_translation,node_chat,node_proxy,node_tokensaver,node_compression,node_client toneBlue
class node_connections,node_provider_registry toneAmber
class node_governance,node_budget,node_health,node_cache toneMint
class node_database,node_dashboard,node_dashboard_api,node_admin_handlers,node_mcp_a2a,node_mitm toneRose
class node_upstream toneIndigo
```

## Components

### Gateway and Routing

- [Local Gateway](https://github.com/yanstd888/9routerx/blob/main/internal/app/server.go): `internal/app/server.go`
- [API Routes](https://github.com/yanstd888/9routerx/blob/main/internal/handlers/router.go): `internal/handlers/router.go`
- [Format Translation](https://github.com/yanstd888/9routerx/blob/main/internal/translator/client_format.go): `internal/translator/client_format.go`
- [Chat Routing](https://github.com/yanstd888/9routerx/tree/main/internal/handlers/chat): `internal/handlers/chat`
- [Provider Execution](https://github.com/yanstd888/9routerx/tree/main/internal/proxy): `internal/proxy`
- [Token Saver](https://github.com/yanstd888/9routerx/tree/main/internal/tokensaver): `internal/tokensaver`
- [Output Compression](https://github.com/yanstd888/9routerx/tree/main/internal/compression): `internal/compression`

### Providers and Accounts

- [Provider Connections](https://github.com/yanstd888/9routerx/tree/main/internal/handlers/oauth): `internal/handlers/oauth`
- [Provider Catalog](https://github.com/yanstd888/9routerx/tree/main/internal/providers): `internal/providers`

### Governance and Reliability

- [Keys and Guardrails](https://github.com/yanstd888/9routerx/tree/main/internal/guardrails): `internal/guardrails`
- [Per-key Budgets](https://github.com/yanstd888/9routerx/tree/main/internal/budget): `internal/budget`
- [Health and Recovery](https://github.com/yanstd888/9routerx/tree/main/internal/resilience): `internal/resilience`
- [Request Caches](https://github.com/yanstd888/9routerx/tree/main/internal/semanticcache): `internal/semanticcache`

### Operations and Dashboard

- [SQLite State](https://github.com/yanstd888/9routerx/tree/main/internal/db): `internal/db`
- [Web Dashboard](https://github.com/yanstd888/9routerx/blob/main/web/src/App.svelte): `web/src/App.svelte`
- [Dashboard API Client](https://github.com/yanstd888/9routerx/blob/main/web/src/api/client.ts): `web/src/api/client.ts`
- [Admin Handlers](https://github.com/yanstd888/9routerx/blob/main/internal/handlers/dashboard/routes.go): `internal/handlers/dashboard/routes.go`
- [MCP and A2A](https://github.com/yanstd888/9routerx/tree/main/internal/mcpserver): `internal/mcpserver`
- [MITM Inspector](https://github.com/yanstd888/9routerx/blob/main/internal/mitm/server.go): `internal/mitm/server.go`

### Other components

- **AI Client**
- **AI Providers**

## Connections

- AI Client → Local Gateway: sends requests (evidence: `README.md`)
- Local Gateway → API Routes: routes requests
- API Routes → Format Translation: adapts formats
- API Routes → Chat Routing: dispatches inference
- Chat Routing → Provider Execution: forwards upstream
- Provider Execution → AI Providers: sends provider calls (evidence: `README.md`)
- Provider Execution → AI Client: returns responses
- Chat Routing → Token Saver: reduces context (evidence: `README.md`)
- Chat Routing → Output Compression: compresses output (evidence: `README.md`)
- AI Client → Web Dashboard: configures gateway (evidence: `README.md`)
- Web Dashboard → Dashboard API Client: calls API (evidence: `web/src/App.svelte`)
- Dashboard API Client → Admin Handlers: requests admin operations (evidence: `web/src/api/client.ts`)
- Admin Handlers → SQLite State: reads and writes
- Provider Connections → SQLite State: stores credentials
- Provider Catalog → Provider Execution: selects providers
- Chat Routing → Keys and Guardrails: enforces policies (evidence: `README.md`)
- Chat Routing → Per-key Budgets: checks spend limits (evidence: `README.md`)
- Chat Routing → Health and Recovery: avoids degraded nodes (evidence: `README.md`)
- Chat Routing → Request Caches: checks semantic cache (evidence: `README.md`)
- AI Client → MCP and A2A: uses tool protocols (evidence: `README.md`)
- AI Providers → MITM Inspector: traffic inspection
