# zephel01/coderouter architecture

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

- Interactive diagram: https://gitdiagram.com/zephel01/coderouter
- Repository: https://github.com/zephel01/coderouter

## Overview

CodeRouter is a local LLM gateway for coding agents. Requests enter through Anthropic- or OpenAI-compatible APIs, are assigned a profile, and pass through provider fallback to an upstream model; the gateway repairs and filters responses where needed. Separate capabilities cover long-running safeguards, diagnosis and observability, language-aware cost routing, and a browser-based backend launcher. The source index and excerpts support the central routing relationships; several guard and launcher internals were not sampled, so their connections are limited to documented capabilities.

Main entry points: [`coderouter/routing/fallback.py`](https://github.com/zephel01/coderouter/blob/main/coderouter/routing/fallback.py) (Fallback engine), [`coderouter/ingress/app.py`](https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/app.py) (Application setup), [`coderouter/ingress/anthropic_routes.py`](https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/anthropic_routes.py) (Anthropic API), [`coderouter/ingress/openai_routes.py`](https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/openai_routes.py) (OpenAI API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and operations"]
  node_anthropic_api["Anthropic API"]
  node_openai_api["OpenAI API<br/>[openai_routes.py]"]
  node_app["Application setup<br/>[app.py]"]
end

subgraph group_routing["Routing and providers"]
  node_config["Configuration<br/>[loader.py]"]
  node_schemas["Config schemas<br/>[schemas.py]"]
  node_auto_route["Auto routing<br/>[auto_router.py]"]
  node_capability["Capability handling<br/>[capability.py]"]
  node_fallback["Fallback engine<br/>[fallback.py]"]
  node_adapter_base["Adapter interface<br/>[base.py]"]
  node_anthropic_adapter["Anthropic adapter"]
  node_openai_adapter["OpenAI adapter<br/>[openai_compat.py]"]
  node_filters["Output filters<br/>[output_filters.py]"]
end

subgraph group_reliability["Runtime safeguards"]
  node_guards["Runtime guards"]
  node_tokens["Token estimation"]
  node_language_tax["Language tax<br/>[language_tax.py]"]
end

subgraph group_observability["Diagnosis and observability"]
  node_doctor["Provider diagnosis<br/>[doctor.py]"]
  node_audit[("Audit and replay<br/>[audit_log.py]")]
  node_request_log[("Request log<br/>[request_log.py]")]
  node_metrics["Metrics<br/>[collector.py]"]
  node_dashboard["Dashboard"]
end

subgraph group_launcher["Backend launcher"]
  node_launcher_ui["Launcher routes<br/>[launcher_routes.py]"]
  node_launcher_devices["Device detection"]
  node_launcher_speculative["Speculative options"]
end

node_agent(("Coding agent"))
node_upstream(("Model providers"))

node_agent -->|"sends requests"| node_anthropic_api
node_agent -->|"sends requests"| node_openai_api
node_anthropic_api -->|"dispatches"| node_fallback
node_openai_api -->|"dispatches"| node_fallback
node_app -->|"registers routes"| node_anthropic_api
node_app -->|"registers routes"| node_openai_api
node_app -->|"registers routes"| node_dashboard
node_app -->|"registers routes"| node_launcher_ui
node_config -->|"validates config"| node_schemas
node_anthropic_api -->|"classifies requests"| node_auto_route
node_openai_api -->|"classifies requests"| node_auto_route
node_auto_route -->|"selects profile"| node_fallback
node_anthropic_api -->|"normalizes requests"| node_capability
node_fallback -->|"calls adapters"| node_adapter_base
node_anthropic_adapter -->|"implements"| node_adapter_base
node_openai_adapter -->|"implements"| node_adapter_base
node_anthropic_adapter -->|"sends requests"| node_upstream
node_fallback -->|"applies safeguards"| node_guards
node_guards -->|"estimates context"| node_tokens
node_auto_route -->|"uses tax signals"| node_language_tax
node_language_tax -->|"uses estimates"| node_tokens
node_fallback -.->|"cleans output"| node_filters
node_doctor -->|"probes providers"| node_upstream
node_fallback -.->|"records events"| node_audit
node_fallback -.->|"records requests"| node_request_log
node_app -->|"initializes metrics"| node_metrics
node_dashboard -.->|"shows activity"| node_audit
node_launcher_ui -->|"detects hardware"| node_launcher_devices
node_launcher_ui -->|"resolves options"| node_launcher_speculative

click node_anthropic_api "https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/anthropic_routes.py"
click node_openai_api "https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/openai_routes.py"
click node_app "https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/app.py"
click node_config "https://github.com/zephel01/coderouter/blob/main/coderouter/config/loader.py"
click node_schemas "https://github.com/zephel01/coderouter/blob/main/coderouter/config/schemas.py"
click node_auto_route "https://github.com/zephel01/coderouter/blob/main/coderouter/routing/auto_router.py"
click node_capability "https://github.com/zephel01/coderouter/blob/main/coderouter/routing/capability.py"
click node_fallback "https://github.com/zephel01/coderouter/blob/main/coderouter/routing/fallback.py"
click node_adapter_base "https://github.com/zephel01/coderouter/blob/main/coderouter/adapters/base.py"
click node_anthropic_adapter "https://github.com/zephel01/coderouter/blob/main/coderouter/adapters/anthropic_native.py"
click node_openai_adapter "https://github.com/zephel01/coderouter/blob/main/coderouter/adapters/openai_compat.py"
click node_filters "https://github.com/zephel01/coderouter/blob/main/coderouter/output_filters.py"
click node_guards "https://github.com/zephel01/coderouter/tree/main/coderouter/guards"
click node_tokens "https://github.com/zephel01/coderouter/blob/main/coderouter/token_estimation.py"
click node_language_tax "https://github.com/zephel01/coderouter/blob/main/coderouter/language_tax.py"
click node_doctor "https://github.com/zephel01/coderouter/blob/main/coderouter/doctor.py"
click node_audit "https://github.com/zephel01/coderouter/blob/main/coderouter/state/audit_log.py"
click node_request_log "https://github.com/zephel01/coderouter/blob/main/coderouter/state/request_log.py"
click node_metrics "https://github.com/zephel01/coderouter/blob/main/coderouter/metrics/collector.py"
click node_dashboard "https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/dashboard_routes.py"
click node_launcher_ui "https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/launcher_routes.py"
click node_launcher_devices "https://github.com/zephel01/coderouter/blob/main/coderouter/launcher_devices.py"
click node_launcher_speculative "https://github.com/zephel01/coderouter/blob/main/coderouter/launcher_speculative.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_anthropic_api,node_openai_api,node_app toneBlue
class node_config,node_schemas,node_auto_route,node_capability,node_fallback,node_adapter_base,node_anthropic_adapter,node_openai_adapter,node_filters toneAmber
class node_guards,node_tokens,node_language_tax toneMint
class node_doctor,node_audit,node_request_log,node_metrics,node_dashboard toneRose
class node_launcher_ui,node_launcher_devices,node_launcher_speculative,node_agent,node_upstream toneIndigo
```

## Components

### API and operations

- [Anthropic API](https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/anthropic_routes.py): `coderouter/ingress/anthropic_routes.py`
- [OpenAI API](https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/openai_routes.py): `coderouter/ingress/openai_routes.py`
- [Application setup](https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/app.py): `coderouter/ingress/app.py`

### Routing and providers

- [Configuration](https://github.com/zephel01/coderouter/blob/main/coderouter/config/loader.py): `coderouter/config/loader.py`
- [Config schemas](https://github.com/zephel01/coderouter/blob/main/coderouter/config/schemas.py): `coderouter/config/schemas.py`
- [Auto routing](https://github.com/zephel01/coderouter/blob/main/coderouter/routing/auto_router.py): `coderouter/routing/auto_router.py`
- [Capability handling](https://github.com/zephel01/coderouter/blob/main/coderouter/routing/capability.py): `coderouter/routing/capability.py`
- [Fallback engine](https://github.com/zephel01/coderouter/blob/main/coderouter/routing/fallback.py): `coderouter/routing/fallback.py`
- [Adapter interface](https://github.com/zephel01/coderouter/blob/main/coderouter/adapters/base.py): `coderouter/adapters/base.py`
- [Anthropic adapter](https://github.com/zephel01/coderouter/blob/main/coderouter/adapters/anthropic_native.py): `coderouter/adapters/anthropic_native.py`
- [OpenAI adapter](https://github.com/zephel01/coderouter/blob/main/coderouter/adapters/openai_compat.py): `coderouter/adapters/openai_compat.py`
- [Output filters](https://github.com/zephel01/coderouter/blob/main/coderouter/output_filters.py): `coderouter/output_filters.py`

### Runtime safeguards

- [Runtime guards](https://github.com/zephel01/coderouter/tree/main/coderouter/guards): `coderouter/guards`
- [Token estimation](https://github.com/zephel01/coderouter/blob/main/coderouter/token_estimation.py): `coderouter/token_estimation.py`
- [Language tax](https://github.com/zephel01/coderouter/blob/main/coderouter/language_tax.py): `coderouter/language_tax.py`

### Diagnosis and observability

- [Provider diagnosis](https://github.com/zephel01/coderouter/blob/main/coderouter/doctor.py): `coderouter/doctor.py`
- [Audit and replay](https://github.com/zephel01/coderouter/blob/main/coderouter/state/audit_log.py): `coderouter/state/audit_log.py`
- [Request log](https://github.com/zephel01/coderouter/blob/main/coderouter/state/request_log.py): `coderouter/state/request_log.py`
- [Metrics](https://github.com/zephel01/coderouter/blob/main/coderouter/metrics/collector.py): `coderouter/metrics/collector.py`
- [Dashboard](https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/dashboard_routes.py): `coderouter/ingress/dashboard_routes.py`

### Backend launcher

- [Launcher routes](https://github.com/zephel01/coderouter/blob/main/coderouter/ingress/launcher_routes.py): `coderouter/ingress/launcher_routes.py`
- [Device detection](https://github.com/zephel01/coderouter/blob/main/coderouter/launcher_devices.py): `coderouter/launcher_devices.py`
- [Speculative options](https://github.com/zephel01/coderouter/blob/main/coderouter/launcher_speculative.py): `coderouter/launcher_speculative.py`

### Other components

- **Coding agent**
- **Model providers**

## Connections

- Coding agent → Anthropic API: sends requests (evidence: `README.md`)
- Coding agent → OpenAI API: sends requests (evidence: `README.md`)
- Anthropic API → Fallback engine: dispatches (evidence: `coderouter/ingress/anthropic_routes.py`)
- OpenAI API → Fallback engine: dispatches (evidence: `coderouter/ingress/openai_routes.py`)
- Application setup → Anthropic API: registers routes (evidence: `coderouter/ingress/app.py`)
- Application setup → OpenAI API: registers routes (evidence: `coderouter/ingress/app.py`)
- Application setup → Dashboard: registers routes (evidence: `coderouter/ingress/app.py`)
- Application setup → Launcher routes: registers routes (evidence: `coderouter/ingress/app.py`)
- Configuration → Config schemas: validates config (evidence: `coderouter/config/loader.py`)
- Anthropic API → Auto routing: classifies requests (evidence: `coderouter/ingress/anthropic_routes.py`)
- OpenAI API → Auto routing: classifies requests (evidence: `coderouter/ingress/openai_routes.py`)
- Auto routing → Fallback engine: selects profile
- Anthropic API → Capability handling: normalizes requests (evidence: `coderouter/ingress/anthropic_routes.py`)
- Fallback engine → Adapter interface: calls adapters (evidence: `coderouter/routing/fallback.py`)
- Anthropic adapter → Adapter interface: implements (evidence: `coderouter/adapters/anthropic_native.py`)
- OpenAI adapter → Adapter interface: implements (evidence: `coderouter/adapters/openai_compat.py`)
- Anthropic adapter → Model providers: sends requests (evidence: `coderouter/adapters/anthropic_native.py`)
- Fallback engine → Runtime guards: applies safeguards (evidence: `coderouter/routing/fallback.py`)
- Runtime guards → Token estimation: estimates context (evidence: `coderouter/guards/context_budget.py`)
- Auto routing → Language tax: uses tax signals (evidence: `coderouter/routing/auto_router.py`)
- Language tax → Token estimation: uses estimates (evidence: `coderouter/language_tax.py`)
- Fallback engine → Output filters: cleans output
- Provider diagnosis → Model providers: probes providers (evidence: `coderouter/doctor.py`)
- Fallback engine → Audit and replay: records events
- Fallback engine → Request log: records requests
- Application setup → Metrics: initializes metrics (evidence: `coderouter/ingress/app.py`)
- Dashboard → Audit and replay: shows activity
- Launcher routes → Device detection: detects hardware (evidence: `coderouter/ingress/launcher_routes.py`)
- Launcher routes → Speculative options: resolves options (evidence: `coderouter/ingress/launcher_routes.py`)
