# thusinh1969/brighto_router architecture

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

- Interactive diagram: https://gitdiagram.com/thusinh1969/brighto_router
- Repository: https://github.com/thusinh1969/brighto_router

## Overview

BrighTO-Router is a self-hosted Rust LLM gateway and model load balancer. Its main workflow accepts a client request, authenticates and applies policy, selects a configured backend, proxies the request, and records usage. The graph also includes the admin portal, protocol translation, and configuration/observability layers. Some endpoint families and integrations are documented in the README but their detailed implementations were not sampled; those are represented at the shared handler boundary.

Main entry points: [`src/handlers.rs`](https://github.com/thusinh1969/brighto_router/blob/main/src/handlers.rs) (HTTP handlers), [`src/proxy/mod.rs`](https://github.com/thusinh1969/brighto_router/blob/main/src/proxy/mod.rs) (Backend proxy), [`src/admin/mod.rs`](https://github.com/thusinh1969/brighto_router/blob/main/src/admin/mod.rs) (Admin API and portal), [`src/config/mod.rs`](https://github.com/thusinh1969/brighto_router/blob/main/src/config/mod.rs) (Config loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_traffic["Request traffic"]
  node_handlers["HTTP handlers<br/>[handlers.rs]"]
  node_proxy["Backend proxy<br/>[mod.rs]"]
  node_runtime["Router process<br/>[main.rs]"]
end

subgraph group_routing["Routing and protocols"]
  node_route["Route selection<br/>[mod.rs]"]
  node_bridge["Anthropic bridge<br/>[mod.rs]"]
  node_compat["DeepSeek compatibility<br/>[mod.rs]"]
  node_endpoint_families["API endpoint families<br/>[contract.rs]"]
end

subgraph group_policy["Access and operations"]
  node_auth["Key authentication<br/>[auth.rs]"]
  node_budget["Budgets and limits<br/>[mod.rs]"]
  node_admin["Admin API and portal<br/>[mod.rs]"]
end

subgraph group_state["Configuration and records"]
  node_config["Config loader<br/>[mod.rs]"]
  node_postgres[("PostgreSQL")]
  node_ledger["Usage ledger<br/>[mod.rs]"]
  node_metrics["Metrics<br/>[metrics.rs]"]
end

node_client(("API client"))
node_backend["Model providers"]

node_client -->|"sends requests"| node_handlers
node_handlers -->|"authenticates with"| node_auth
node_handlers -->|"checks limits"| node_budget
node_handlers -->|"selects route"| node_route
node_handlers -->|"forwards through"| node_proxy
node_proxy -->|"proxies requests"| node_backend
node_handlers -->|"translates opted-in traffic"| node_bridge
node_proxy -->|"applies compatibility shim"| node_compat
node_client -->|"uses supported APIs"| node_endpoint_families
node_admin -.->|"manages configuration"| node_config
node_admin -.->|"reads and writes admin data"| node_postgres
node_config -->|"loads configuration"| node_postgres
node_proxy -->|"reports usage"| node_ledger
node_ledger -->|"writes usage records"| node_postgres
node_proxy -->|"updates metrics"| node_metrics
node_runtime -.->|"serves API"| node_handlers

click node_handlers "https://github.com/thusinh1969/brighto_router/blob/main/src/handlers.rs"
click node_auth "https://github.com/thusinh1969/brighto_router/blob/main/src/auth.rs"
click node_budget "https://github.com/thusinh1969/brighto_router/blob/main/src/budget/mod.rs"
click node_route "https://github.com/thusinh1969/brighto_router/blob/main/src/route/mod.rs"
click node_proxy "https://github.com/thusinh1969/brighto_router/blob/main/src/proxy/mod.rs"
click node_bridge "https://github.com/thusinh1969/brighto_router/blob/main/src/bridge/mod.rs"
click node_compat "https://github.com/thusinh1969/brighto_router/blob/main/src/compat/mod.rs"
click node_endpoint_families "https://github.com/thusinh1969/brighto_router/blob/main/src/contract.rs"
click node_admin "https://github.com/thusinh1969/brighto_router/blob/main/src/admin/mod.rs"
click node_config "https://github.com/thusinh1969/brighto_router/blob/main/src/config/mod.rs"
click node_ledger "https://github.com/thusinh1969/brighto_router/blob/main/src/ledger/mod.rs"
click node_metrics "https://github.com/thusinh1969/brighto_router/blob/main/src/metrics.rs"
click node_runtime "https://github.com/thusinh1969/brighto_router/blob/main/src/main.rs"

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_handlers,node_proxy,node_runtime,node_client toneBlue
class node_route,node_bridge,node_compat,node_endpoint_families toneAmber
class node_auth,node_budget,node_admin toneMint
class node_config,node_postgres,node_ledger,node_metrics toneRose
class node_backend toneIndigo
```

## Components

### Request traffic

- [HTTP handlers](https://github.com/thusinh1969/brighto_router/blob/main/src/handlers.rs): `src/handlers.rs`
- [Backend proxy](https://github.com/thusinh1969/brighto_router/blob/main/src/proxy/mod.rs): `src/proxy/mod.rs`
- [Router process](https://github.com/thusinh1969/brighto_router/blob/main/src/main.rs): `src/main.rs`

### Routing and protocols

- [Route selection](https://github.com/thusinh1969/brighto_router/blob/main/src/route/mod.rs): `src/route/mod.rs`
- [Anthropic bridge](https://github.com/thusinh1969/brighto_router/blob/main/src/bridge/mod.rs): `src/bridge/mod.rs`
- [DeepSeek compatibility](https://github.com/thusinh1969/brighto_router/blob/main/src/compat/mod.rs): `src/compat/mod.rs`
- [API endpoint families](https://github.com/thusinh1969/brighto_router/blob/main/src/contract.rs): `src/contract.rs`

### Access and operations

- [Key authentication](https://github.com/thusinh1969/brighto_router/blob/main/src/auth.rs): `src/auth.rs`
- [Budgets and limits](https://github.com/thusinh1969/brighto_router/blob/main/src/budget/mod.rs): `src/budget/mod.rs`
- [Admin API and portal](https://github.com/thusinh1969/brighto_router/blob/main/src/admin/mod.rs): `src/admin/mod.rs`

### Configuration and records

- [Config loader](https://github.com/thusinh1969/brighto_router/blob/main/src/config/mod.rs): `src/config/mod.rs`
- **PostgreSQL**
- [Usage ledger](https://github.com/thusinh1969/brighto_router/blob/main/src/ledger/mod.rs): `src/ledger/mod.rs`
- [Metrics](https://github.com/thusinh1969/brighto_router/blob/main/src/metrics.rs): `src/metrics.rs`

### Other components

- **API client**
- **Model providers**

## Connections

- API client → HTTP handlers: sends requests (evidence: `README.md`)
- HTTP handlers → Key authentication: authenticates with (evidence: `src/handlers.rs`)
- HTTP handlers → Budgets and limits: checks limits (evidence: `src/handlers.rs`)
- HTTP handlers → Route selection: selects route (evidence: `src/handlers.rs`)
- HTTP handlers → Backend proxy: forwards through (evidence: `src/handlers.rs`)
- Backend proxy → Model providers: proxies requests (evidence: `src/proxy/mod.rs`)
- HTTP handlers → Anthropic bridge: translates opted-in traffic (evidence: `src/handlers.rs`)
- Backend proxy → DeepSeek compatibility: applies compatibility shim (evidence: `src/proxy/mod.rs`)
- API client → API endpoint families: uses supported APIs (evidence: `README.md`)
- Admin API and portal → Config loader: manages configuration (evidence: `src/admin/mod.rs`)
- Admin API and portal → PostgreSQL: reads and writes admin data
- Config loader → PostgreSQL: loads configuration (evidence: `src/config/mod.rs`)
- Backend proxy → Usage ledger: reports usage (evidence: `src/proxy/mod.rs`)
- Usage ledger → PostgreSQL: writes usage records (evidence: `src/ledger/mod.rs`)
- Backend proxy → Metrics: updates metrics (evidence: `src/proxy/mod.rs`)
- Router process → HTTP handlers: serves API
