# yujunzhixue/qwen2api architecture

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

- Interactive diagram: https://gitdiagram.com/yujunzhixue/qwen2api
- Repository: https://github.com/yujunzhixue/qwen2api

## Overview

qwen2API is a self-hosted gateway that exposes Qwen Web capabilities through OpenAI-, Anthropic-, and Gemini-compatible APIs, alongside an administrative React WebUI. The primary flow is an API client sending a protocol request to the Go backend, which adapts it for the Qwen account pool and upstream; the UI separately supports account/key management, runtime settings, and chat, image, and video tests. The README documents the high-level gateway flow and capabilities; where backend implementation details were not sampled, the graph avoids asserting internal call order.

Main entry points: [`frontend/src/App.tsx`](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/App.tsx) (Admin WebUI), [`backend/api`](https://github.com/yujunzhixue/qwen2api/tree/main/backend/api) (Compatible APIs), [`frontend/src/pages/SettingsPage.tsx`](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/SettingsPage.tsx) (Runtime Settings), [`backend/context_pipeline.go`](https://github.com/yujunzhixue/qwen2api/blob/main/backend/context_pipeline.go) (Context Pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["API Gateway"]
  node_http_api["Compatible APIs"]
  node_protocol_adapter["Protocol Adapters"]
  node_context_pipeline["Context Pipeline"]
  node_toolcall["Tool-call Handling"]
end

subgraph group_runtime["Qwen Runtime"]
  node_account_pool["Account Pool"]
  node_qwen_client["Qwen Client<br/>[qwen_client.go]"]
  node_upstream["Qwen Web"]
  node_upstream_exec["Upstream Execution"]
  node_runtime_stream["Stream Runtime"]
end

subgraph group_admin["Admin Console"]
  node_webui["Admin WebUI<br/>[App.tsx]"]
  node_admin_layout["Navigation Layout<br/>[AdminLayout.tsx]"]
  node_accounts_page["Account Management<br/>[AccountsPage.tsx]"]
  node_tokens_page["API Keys<br/>[TokensPage.tsx]"]
  node_settings_page["Runtime Settings<br/>[SettingsPage.tsx]"]
  node_dashboard["Status Dashboard<br/>[Dashboard.tsx]"]
  node_chat_test["Chat Testing<br/>[TestPage.tsx]"]
  node_image_test["Image Testing<br/>[ImagePage.tsx]"]
  node_video_test["Video Testing<br/>[VideoPage.tsx]"]
  node_model_catalog["Model Catalog<br/>[models.ts]"]
  node_api_auth["Admin Auth<br/>[auth.ts]"]
end

subgraph group_state["State and Operations"]
  node_json_store[("JSON Data Stores<br/>[database.go]")]
  node_ops_probes["Health Probes<br/>[probes.go]"]
end

node_api_clients(("API Clients"))

node_api_clients -->|"send requests"| node_http_api
node_http_api -->|"dispatches protocols"| node_protocol_adapter
node_protocol_adapter -->|"passes context"| node_context_pipeline
node_context_pipeline -->|"processes tool calls"| node_toolcall
node_context_pipeline -->|"uses pool"| node_account_pool
node_account_pool -->|"selects account"| node_upstream
node_account_pool -->|"persists accounts"| node_json_store
node_qwen_client -.->|"uses upstream"| node_upstream_exec
node_upstream_exec -.->|"sends requests"| node_upstream
node_http_api -.->|"streams responses"| node_runtime_stream
node_webui -->|"routes through"| node_admin_layout
node_webui -->|"routes to"| node_dashboard
node_webui -->|"routes to"| node_accounts_page
node_webui -->|"routes to"| node_tokens_page
node_webui -->|"routes to"| node_settings_page
node_webui -->|"routes to"| node_chat_test
node_webui -->|"routes to"| node_image_test
node_webui -->|"routes to"| node_video_test
node_accounts_page -->|"gets credentials"| node_api_auth
node_accounts_page -->|"fetches accounts"| node_http_api
node_settings_page -->|"gets credentials"| node_api_auth
node_settings_page -->|"fetches settings"| node_http_api
node_chat_test -->|"calls chat API"| node_http_api
node_image_test -->|"loads models"| node_model_catalog
node_video_test -->|"loads models"| node_model_catalog
node_settings_page -->|"loads models"| node_model_catalog
node_api_clients -->|"checks readiness"| node_ops_probes

click node_http_api "https://github.com/yujunzhixue/qwen2api/tree/main/backend/api"
click node_protocol_adapter "https://github.com/yujunzhixue/qwen2api/tree/main/backend/adapter"
click node_context_pipeline "https://github.com/yujunzhixue/qwen2api/blob/main/backend/context_pipeline.go"
click node_toolcall "https://github.com/yujunzhixue/qwen2api/tree/main/backend/toolcall"
click node_account_pool "https://github.com/yujunzhixue/qwen2api/tree/main/backend/core/account_pool"
click node_qwen_client "https://github.com/yujunzhixue/qwen2api/blob/main/backend/services/qwen_client.go"
click node_upstream_exec "https://github.com/yujunzhixue/qwen2api/tree/main/backend/upstream"
click node_runtime_stream "https://github.com/yujunzhixue/qwen2api/tree/main/backend/runtime"
click node_webui "https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/App.tsx"
click node_admin_layout "https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/layouts/AdminLayout.tsx"
click node_accounts_page "https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/AccountsPage.tsx"
click node_tokens_page "https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/TokensPage.tsx"
click node_settings_page "https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/SettingsPage.tsx"
click node_dashboard "https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/Dashboard.tsx"
click node_chat_test "https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/TestPage.tsx"
click node_image_test "https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/ImagePage.tsx"
click node_video_test "https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/VideoPage.tsx"
click node_model_catalog "https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/lib/models.ts"
click node_api_auth "https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/lib/auth.ts"
click node_json_store "https://github.com/yujunzhixue/qwen2api/blob/main/backend/core/database.go"
click node_ops_probes "https://github.com/yujunzhixue/qwen2api/blob/main/backend/api/probes.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_http_api,node_protocol_adapter,node_context_pipeline,node_toolcall,node_api_clients toneBlue
class node_account_pool,node_qwen_client,node_upstream,node_upstream_exec,node_runtime_stream toneAmber
class node_webui,node_admin_layout,node_accounts_page,node_tokens_page,node_settings_page,node_dashboard,node_chat_test,node_image_test,node_video_test,node_model_catalog,node_api_auth toneMint
class node_json_store,node_ops_probes toneRose
```

## Components

### API Gateway

- [Compatible APIs](https://github.com/yujunzhixue/qwen2api/tree/main/backend/api): `backend/api`
- [Protocol Adapters](https://github.com/yujunzhixue/qwen2api/tree/main/backend/adapter): `backend/adapter`
- [Context Pipeline](https://github.com/yujunzhixue/qwen2api/blob/main/backend/context_pipeline.go): `backend/context_pipeline.go`
- [Tool-call Handling](https://github.com/yujunzhixue/qwen2api/tree/main/backend/toolcall): `backend/toolcall`

### Qwen Runtime

- [Account Pool](https://github.com/yujunzhixue/qwen2api/tree/main/backend/core/account_pool): `backend/core/account_pool`
- [Qwen Client](https://github.com/yujunzhixue/qwen2api/blob/main/backend/services/qwen_client.go): `backend/services/qwen_client.go`
- **Qwen Web**
- [Upstream Execution](https://github.com/yujunzhixue/qwen2api/tree/main/backend/upstream): `backend/upstream`
- [Stream Runtime](https://github.com/yujunzhixue/qwen2api/tree/main/backend/runtime): `backend/runtime`

### Admin Console

- [Admin WebUI](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Navigation Layout](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/layouts/AdminLayout.tsx): `frontend/src/layouts/AdminLayout.tsx`
- [Account Management](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/AccountsPage.tsx): `frontend/src/pages/AccountsPage.tsx`
- [API Keys](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/TokensPage.tsx): `frontend/src/pages/TokensPage.tsx`
- [Runtime Settings](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/SettingsPage.tsx): `frontend/src/pages/SettingsPage.tsx`
- [Status Dashboard](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/Dashboard.tsx): `frontend/src/pages/Dashboard.tsx`
- [Chat Testing](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/TestPage.tsx): `frontend/src/pages/TestPage.tsx`
- [Image Testing](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/ImagePage.tsx): `frontend/src/pages/ImagePage.tsx`
- [Video Testing](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/pages/VideoPage.tsx): `frontend/src/pages/VideoPage.tsx`
- [Model Catalog](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/lib/models.ts): `frontend/src/lib/models.ts`
- [Admin Auth](https://github.com/yujunzhixue/qwen2api/blob/main/frontend/src/lib/auth.ts): `frontend/src/lib/auth.ts`

### State and Operations

- [JSON Data Stores](https://github.com/yujunzhixue/qwen2api/blob/main/backend/core/database.go): `backend/core/database.go`
- [Health Probes](https://github.com/yujunzhixue/qwen2api/blob/main/backend/api/probes.go): `backend/api/probes.go`

### Other components

- **API Clients**

## Connections

- API Clients → Compatible APIs: send requests (evidence: `README.md`)
- Compatible APIs → Protocol Adapters: dispatches protocols (evidence: `README.md`)
- Protocol Adapters → Context Pipeline: passes context (evidence: `README.md`)
- Context Pipeline → Tool-call Handling: processes tool calls (evidence: `README.md`)
- Context Pipeline → Account Pool: uses pool (evidence: `README.md`)
- Account Pool → Qwen Web: selects account (evidence: `README.md`)
- Account Pool → JSON Data Stores: persists accounts (evidence: `README.md`)
- Qwen Client → Upstream Execution: uses upstream
- Upstream Execution → Qwen Web: sends requests
- Compatible APIs → Stream Runtime: streams responses
- Admin WebUI → Navigation Layout: routes through (evidence: `frontend/src/App.tsx`)
- Admin WebUI → Status Dashboard: routes to (evidence: `frontend/src/App.tsx`)
- Admin WebUI → Account Management: routes to (evidence: `frontend/src/App.tsx`)
- Admin WebUI → API Keys: routes to (evidence: `frontend/src/App.tsx`)
- Admin WebUI → Runtime Settings: routes to (evidence: `frontend/src/App.tsx`)
- Admin WebUI → Chat Testing: routes to (evidence: `frontend/src/App.tsx`)
- Admin WebUI → Image Testing: routes to (evidence: `frontend/src/App.tsx`)
- Admin WebUI → Video Testing: routes to (evidence: `frontend/src/App.tsx`)
- Account Management → Admin Auth: gets credentials (evidence: `frontend/src/pages/AccountsPage.tsx`)
- Account Management → Compatible APIs: fetches accounts (evidence: `frontend/src/pages/AccountsPage.tsx`)
- Runtime Settings → Admin Auth: gets credentials (evidence: `frontend/src/pages/SettingsPage.tsx`)
- Runtime Settings → Compatible APIs: fetches settings (evidence: `frontend/src/pages/SettingsPage.tsx`)
- Chat Testing → Compatible APIs: calls chat API (evidence: `frontend/src/pages/TestPage.tsx`)
- Image Testing → Model Catalog: loads models (evidence: `frontend/src/pages/ImagePage.tsx`)
- Video Testing → Model Catalog: loads models (evidence: `frontend/src/pages/VideoPage.tsx`)
- Runtime Settings → Model Catalog: loads models (evidence: `frontend/src/pages/SettingsPage.tsx`)
- API Clients → Health Probes: checks readiness (evidence: `README.md`)
