# fuzhengwei/one-api architecture

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

- Interactive diagram: https://gitdiagram.com/fuzhengwei/one-api
- Repository: https://github.com/fuzhengwei/one-api

## Overview

One API presents a standard OpenAI-compatible interface over multiple model providers, with account, token, channel, billing and operational management. The main request path is an API client through HTTP routing and relay handling, provider-specific translation, then a normalized response; administrative users also manage access and routing through the dashboard. The README documents streaming, images, retries, load balancing, OAuth, redemption and configuration capabilities. Some relay and controller wiring is unsampled, so those relationships are marked unverified rather than asserted as source-confirmed.

Main entry points: [`router/relay.go`](https://github.com/fuzhengwei/one-api/blob/main/router/relay.go) (HTTP routes), [`model/user.go`](https://github.com/fuzhengwei/one-api/blob/main/model/user.go) (Domain models), [`web/default/src/helpers/api.js`](https://github.com/fuzhengwei/one-api/blob/main/web/default/src/helpers/api.js) (Dashboard API client), [`web/default/src/App.js`](https://github.com/fuzhengwei/one-api/blob/main/web/default/src/App.js) (Dashboard application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["HTTP entry"]
  node_server["Server bootstrap<br/>[main.go]"]
  node_routes["HTTP routes<br/>[relay.go]"]
end

subgraph group_relay["Model relay"]
  node_relay_controller["Relay handlers<br/>[text.go]"]
  node_relay_helpers["Relay validation<br/>[validation.go]"]
  node_adaptor_registry["Provider dispatch<br/>[adaptor.go]"]
  node_provider_adaptors["Provider adaptors<br/>[main.go]"]
  node_relay_models["Common API models<br/>[general.go]"]
end

subgraph group_management["Accounts and operations"]
  node_users["User management<br/>[user.go]"]
  node_auth["Authentication<br/>[github.go]"]
  node_tokens["Token management<br/>[token.go]"]
  node_channels["Channel management<br/>[channel.go]"]
  node_redemptions["Redemption codes<br/>[redemption.go]"]
  node_operations["Logs and settings<br/>[log.go]"]
end

subgraph group_persistence["State and billing"]
  node_billing["Usage billing<br/>[billing.go]"]
  node_models["Domain models<br/>[user.go]"]
  node_database[("SQL storage<br/>[main.go]")]
  node_cache["Channel cache<br/>[cache.go]"]
end

subgraph group_dashboard["Web dashboard"]
  node_web_app["Dashboard application<br/>[App.js]"]
  node_web_api["Dashboard API client<br/>[api.js]"]
  node_admin_user["Account screens<br/>[EditUser.js]"]
  node_admin_channels["Channel screens<br/>[EditChannel.js]"]
  node_admin_tokens["Token screens<br/>[EditToken.js]"]
  node_admin_redemptions["Redemption screens<br/>[EditRedemption.js]"]
  node_admin_logs["Logs and settings UI<br/>[index.js]"]
end

node_client(("API client"))
node_providers{{"Model providers"}}

node_client -.->|"sends API request"| node_routes
node_server -->|"registers routes"| node_routes
node_routes -.->|"dispatches relay"| node_relay_controller
node_relay_controller -.->|"validates request"| node_relay_helpers
node_relay_controller -.->|"selects provider"| node_adaptor_registry
node_adaptor_registry -.->|"dispatches adaptor"| node_provider_adaptors
node_provider_adaptors -.->|"calls provider"| node_providers
node_provider_adaptors -->|"translates payload"| node_relay_models
node_relay_controller -.->|"records usage"| node_billing
node_relay_controller -.->|"returns response"| node_client
node_routes -.->|"routes administration"| node_users
node_routes -.->|"routes sign-in"| node_auth
node_routes -.->|"routes token actions"| node_tokens
node_routes -.->|"routes channel actions"| node_channels
node_routes -.->|"routes redemption actions"| node_redemptions
node_routes -.->|"routes operations"| node_operations
node_users -.->|"updates user data"| node_models
node_tokens -.->|"updates token data"| node_models
node_channels -.->|"updates channel data"| node_models
node_redemptions -.->|"updates redemption data"| node_models
node_billing -.->|"uses domain data"| node_models
node_models -.->|"persists records"| node_database
node_server -->|"initializes storage"| node_database
node_server -->|"initializes cache"| node_cache
node_web_app -->|"routes to"| node_admin_user
node_web_app -->|"routes to"| node_admin_channels
node_web_app -->|"routes to"| node_admin_tokens
node_web_app -->|"routes to"| node_admin_redemptions
node_web_app -->|"routes to"| node_admin_logs
node_admin_user -.->|"requests data"| node_web_api
node_admin_channels -.->|"requests data"| node_web_api
node_admin_tokens -.->|"requests data"| node_web_api
node_admin_redemptions -.->|"requests data"| node_web_api
node_admin_logs -.->|"requests data"| node_web_api
node_web_api -.->|"calls management API"| node_routes

click node_server "https://github.com/fuzhengwei/one-api/blob/main/main.go"
click node_routes "https://github.com/fuzhengwei/one-api/blob/main/router/relay.go"
click node_relay_controller "https://github.com/fuzhengwei/one-api/blob/main/relay/controller/text.go"
click node_relay_helpers "https://github.com/fuzhengwei/one-api/blob/main/relay/controller/validator/validation.go"
click node_adaptor_registry "https://github.com/fuzhengwei/one-api/blob/main/relay/adaptor.go"
click node_provider_adaptors "https://github.com/fuzhengwei/one-api/blob/main/relay/adaptor/openai/main.go"
click node_relay_models "https://github.com/fuzhengwei/one-api/blob/main/relay/model/general.go"
click node_billing "https://github.com/fuzhengwei/one-api/blob/main/relay/billing/billing.go"
click node_users "https://github.com/fuzhengwei/one-api/blob/main/controller/user.go"
click node_auth "https://github.com/fuzhengwei/one-api/blob/main/controller/auth/github.go"
click node_tokens "https://github.com/fuzhengwei/one-api/blob/main/controller/token.go"
click node_channels "https://github.com/fuzhengwei/one-api/blob/main/controller/channel.go"
click node_redemptions "https://github.com/fuzhengwei/one-api/blob/main/controller/redemption.go"
click node_operations "https://github.com/fuzhengwei/one-api/blob/main/controller/log.go"
click node_models "https://github.com/fuzhengwei/one-api/blob/main/model/user.go"
click node_database "https://github.com/fuzhengwei/one-api/blob/main/model/main.go"
click node_cache "https://github.com/fuzhengwei/one-api/blob/main/model/cache.go"
click node_web_app "https://github.com/fuzhengwei/one-api/blob/main/web/default/src/App.js"
click node_web_api "https://github.com/fuzhengwei/one-api/blob/main/web/default/src/helpers/api.js"
click node_admin_user "https://github.com/fuzhengwei/one-api/blob/main/web/default/src/pages/User/EditUser.js"
click node_admin_channels "https://github.com/fuzhengwei/one-api/blob/main/web/default/src/pages/Channel/EditChannel.js"
click node_admin_tokens "https://github.com/fuzhengwei/one-api/blob/main/web/default/src/pages/Token/EditToken.js"
click node_admin_redemptions "https://github.com/fuzhengwei/one-api/blob/main/web/default/src/pages/Redemption/EditRedemption.js"
click node_admin_logs "https://github.com/fuzhengwei/one-api/blob/main/web/default/src/pages/Log/index.js"

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_server,node_routes,node_client toneBlue
class node_relay_controller,node_relay_helpers,node_adaptor_registry,node_provider_adaptors,node_relay_models toneAmber
class node_users,node_auth,node_tokens,node_channels,node_redemptions,node_operations toneMint
class node_billing,node_models,node_database,node_cache toneRose
class node_web_app,node_web_api,node_admin_user,node_admin_channels,node_admin_tokens,node_admin_redemptions,node_admin_logs,node_providers toneIndigo
```

## Components

### HTTP entry

- [Server bootstrap](https://github.com/fuzhengwei/one-api/blob/main/main.go): `main.go`
- [HTTP routes](https://github.com/fuzhengwei/one-api/blob/main/router/relay.go): `router/relay.go`

### Model relay

- [Relay handlers](https://github.com/fuzhengwei/one-api/blob/main/relay/controller/text.go): `relay/controller/text.go`
- [Relay validation](https://github.com/fuzhengwei/one-api/blob/main/relay/controller/validator/validation.go): `relay/controller/validator/validation.go`
- [Provider dispatch](https://github.com/fuzhengwei/one-api/blob/main/relay/adaptor.go): `relay/adaptor.go`
- [Provider adaptors](https://github.com/fuzhengwei/one-api/blob/main/relay/adaptor/openai/main.go): `relay/adaptor/openai/main.go`
- [Common API models](https://github.com/fuzhengwei/one-api/blob/main/relay/model/general.go): `relay/model/general.go`

### Accounts and operations

- [User management](https://github.com/fuzhengwei/one-api/blob/main/controller/user.go): `controller/user.go`
- [Authentication](https://github.com/fuzhengwei/one-api/blob/main/controller/auth/github.go): `controller/auth/github.go`
- [Token management](https://github.com/fuzhengwei/one-api/blob/main/controller/token.go): `controller/token.go`
- [Channel management](https://github.com/fuzhengwei/one-api/blob/main/controller/channel.go): `controller/channel.go`
- [Redemption codes](https://github.com/fuzhengwei/one-api/blob/main/controller/redemption.go): `controller/redemption.go`
- [Logs and settings](https://github.com/fuzhengwei/one-api/blob/main/controller/log.go): `controller/log.go`

### State and billing

- [Usage billing](https://github.com/fuzhengwei/one-api/blob/main/relay/billing/billing.go): `relay/billing/billing.go`
- [Domain models](https://github.com/fuzhengwei/one-api/blob/main/model/user.go): `model/user.go`
- [SQL storage](https://github.com/fuzhengwei/one-api/blob/main/model/main.go): `model/main.go`
- [Channel cache](https://github.com/fuzhengwei/one-api/blob/main/model/cache.go): `model/cache.go`

### Web dashboard

- [Dashboard application](https://github.com/fuzhengwei/one-api/blob/main/web/default/src/App.js): `web/default/src/App.js`
- [Dashboard API client](https://github.com/fuzhengwei/one-api/blob/main/web/default/src/helpers/api.js): `web/default/src/helpers/api.js`
- [Account screens](https://github.com/fuzhengwei/one-api/blob/main/web/default/src/pages/User/EditUser.js): `web/default/src/pages/User/EditUser.js`
- [Channel screens](https://github.com/fuzhengwei/one-api/blob/main/web/default/src/pages/Channel/EditChannel.js): `web/default/src/pages/Channel/EditChannel.js`
- [Token screens](https://github.com/fuzhengwei/one-api/blob/main/web/default/src/pages/Token/EditToken.js): `web/default/src/pages/Token/EditToken.js`
- [Redemption screens](https://github.com/fuzhengwei/one-api/blob/main/web/default/src/pages/Redemption/EditRedemption.js): `web/default/src/pages/Redemption/EditRedemption.js`
- [Logs and settings UI](https://github.com/fuzhengwei/one-api/blob/main/web/default/src/pages/Log/index.js): `web/default/src/pages/Log/index.js`

### Other components

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

## Connections

- API client → HTTP routes: sends API request (evidence: `README.md`)
- Server bootstrap → HTTP routes: registers routes (evidence: `main.go`)
- HTTP routes → Relay handlers: dispatches relay
- Relay handlers → Relay validation: validates request
- Relay handlers → Provider dispatch: selects provider
- Provider dispatch → Provider adaptors: dispatches adaptor
- Provider adaptors → Model providers: calls provider (evidence: `README.md`)
- Provider adaptors → Common API models: translates payload
- Relay handlers → Usage billing: records usage (evidence: `README.md`)
- Relay handlers → API client: returns response (evidence: `README.md`)
- HTTP routes → User management: routes administration (evidence: `README.md`)
- HTTP routes → Authentication: routes sign-in (evidence: `README.md`)
- HTTP routes → Token management: routes token actions (evidence: `README.md`)
- HTTP routes → Channel management: routes channel actions (evidence: `README.md`)
- HTTP routes → Redemption codes: routes redemption actions (evidence: `README.md`)
- HTTP routes → Logs and settings: routes operations (evidence: `README.md`)
- User management → Domain models: updates user data
- Token management → Domain models: updates token data
- Channel management → Domain models: updates channel data
- Redemption codes → Domain models: updates redemption data
- Usage billing → Domain models: uses domain data (evidence: `README.md`)
- Domain models → SQL storage: persists records (evidence: `model/main.go`)
- Server bootstrap → SQL storage: initializes storage (evidence: `main.go`)
- Server bootstrap → Channel cache: initializes cache (evidence: `main.go`)
- Dashboard application → Account screens: routes to (evidence: `web/default/src/App.js`)
- Dashboard application → Channel screens: routes to (evidence: `web/default/src/App.js`)
- Dashboard application → Token screens: routes to (evidence: `web/default/src/App.js`)
- Dashboard application → Redemption screens: routes to (evidence: `web/default/src/App.js`)
- Dashboard application → Logs and settings UI: routes to (evidence: `web/default/src/App.js`)
- Account screens → Dashboard API client: requests data
- Channel screens → Dashboard API client: requests data
- Token screens → Dashboard API client: requests data
- Redemption screens → Dashboard API client: requests data
- Logs and settings UI → Dashboard API client: requests data
- Dashboard API client → HTTP routes: calls management API (evidence: `README.md`)
