# yangyuhou/qwen2api architecture

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

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

## Overview

qwen2API is a self-hosted gateway that exposes Qwen Web capabilities through OpenAI-, Anthropic-, and Gemini-compatible APIs, alongside an administration and testing WebUI. The principal request path is client → Go HTTP/API layer → protocol and context processing → account pool → Qwen upstream; the README documents this high-level flow. The WebUI separately manages accounts, keys, settings, and chat/image/video tests. Several backend subsystems are represented by their exact directories because their individual source was not sampled; detailed internal calls beyond documented relationships are therefore omitted.

Main entry points: [`backend/main.go`](https://github.com/yangyuhou/qwen2api/blob/main/backend/main.go) (HTTP router), [`backend/adapter/standard_request.go`](https://github.com/yangyuhou/qwen2api/blob/main/backend/adapter/standard_request.go) (Protocol adapter), [`backend/context_pipeline.go`](https://github.com/yangyuhou/qwen2api/blob/main/backend/context_pipeline.go) (Context pipeline), [`backend/core/account_pool/pool_core.go`](https://github.com/yangyuhou/qwen2api/blob/main/backend/core/account_pool/pool_core.go) (Account pool)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Clients"]
  node_api_clients(("API clients"))
end

subgraph group_web["Admin WebUI"]
  node_webui["Admin console<br/>[App.tsx]"]
  node_account_ui["Account management<br/>[AccountsPage.tsx]"]
  node_dashboard_ui["Dashboard<br/>[Dashboard.tsx]"]
  node_token_ui["API keys<br/>[TokensPage.tsx]"]
  node_settings_ui["Runtime settings<br/>[SettingsPage.tsx]"]
  node_chat_test_ui["Chat testing<br/>[TestPage.tsx]"]
  node_image_ui["Image testing<br/>[ImagePage.tsx]"]
  node_video_ui["Video testing<br/>[VideoPage.tsx]"]
end

subgraph group_gateway["Go Gateway"]
  node_router["HTTP router<br/>[main.go]"]
  node_protocol_apis["Protocol APIs"]
  node_admin_api["Admin API<br/>[admin.go]"]
end

subgraph group_processing["Request Processing"]
  node_adapter["Protocol adapter"]
  node_context["Context pipeline"]
  node_toolcalls["Tool-call parsing<br/>[parser.go]"]
  node_execution["Stream execution<br/>[execution.go]"]
end

subgraph group_upstream["Accounts And Upstream"]
  node_account_pool["Account pool<br/>[pool_core.go]"]
  node_qwen_upstream(("Qwen Web"))
  node_qwen_executor["Qwen executor<br/>[qwen_executor.go]"]
  node_payload["Payload builder<br/>[payload_builder.go]"]
  node_data_store[("JSON data stores<br/>[database.go]")]
end

node_api_clients -->|"send requests"| node_router
node_webui -->|"calls admin APIs"| node_router
node_router -->|"dispatches to"| node_adapter
node_adapter -->|"processes through"| node_context
node_context -->|"uses"| node_account_pool
node_account_pool -->|"forwards requests"| node_qwen_upstream
node_account_pool -->|"uses account data"| node_data_store
node_router -.->|"routes protocol requests"| node_protocol_apis
node_router -.->|"routes management requests"| node_admin_api
node_protocol_apis -.->|"adapts protocols"| node_adapter
node_account_ui -.->|"manages accounts"| node_router
node_dashboard_ui -.->|"reads status"| node_router
node_token_ui -.->|"manages keys"| node_router
node_settings_ui -.->|"updates settings"| node_router
node_chat_test_ui -->|"tests chat"| node_router
node_image_ui -.->|"tests images"| node_router
node_video_ui -.->|"tests videos"| node_router
node_adapter -.->|"handles tool calls"| node_toolcalls
node_context -.->|"passes request"| node_execution
node_execution -.->|"builds upstream payload"| node_payload
node_payload -.->|"provides payload"| node_qwen_executor
node_qwen_executor -.->|"executes request"| node_qwen_upstream

click node_webui "https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/App.tsx"
click node_account_ui "https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/AccountsPage.tsx"
click node_dashboard_ui "https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/Dashboard.tsx"
click node_token_ui "https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/TokensPage.tsx"
click node_settings_ui "https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/SettingsPage.tsx"
click node_chat_test_ui "https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/TestPage.tsx"
click node_image_ui "https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/ImagePage.tsx"
click node_video_ui "https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/VideoPage.tsx"
click node_router "https://github.com/yangyuhou/qwen2api/blob/main/backend/main.go"
click node_protocol_apis "https://github.com/yangyuhou/qwen2api/tree/main/backend/api"
click node_admin_api "https://github.com/yangyuhou/qwen2api/blob/main/backend/api/admin.go"
click node_adapter "https://github.com/yangyuhou/qwen2api/blob/main/backend/adapter/standard_request.go"
click node_context "https://github.com/yangyuhou/qwen2api/blob/main/backend/context_pipeline.go"
click node_toolcalls "https://github.com/yangyuhou/qwen2api/blob/main/backend/toolcall/parser.go"
click node_execution "https://github.com/yangyuhou/qwen2api/blob/main/backend/runtime/execution.go"
click node_account_pool "https://github.com/yangyuhou/qwen2api/blob/main/backend/core/account_pool/pool_core.go"
click node_qwen_executor "https://github.com/yangyuhou/qwen2api/blob/main/backend/upstream/qwen_executor.go"
click node_payload "https://github.com/yangyuhou/qwen2api/blob/main/backend/upstream/payload_builder.go"
click node_data_store "https://github.com/yangyuhou/qwen2api/blob/main/backend/core/database.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_api_clients toneBlue
class node_webui,node_account_ui,node_dashboard_ui,node_token_ui,node_settings_ui,node_chat_test_ui,node_image_ui,node_video_ui toneAmber
class node_router,node_protocol_apis,node_admin_api toneMint
class node_adapter,node_context,node_toolcalls,node_execution toneRose
class node_account_pool,node_qwen_upstream,node_qwen_executor,node_payload,node_data_store toneIndigo
```

## Components

### Clients

- **API clients**

### Admin WebUI

- [Admin console](https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Account management](https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/AccountsPage.tsx): `frontend/src/pages/AccountsPage.tsx`
- [Dashboard](https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/Dashboard.tsx): `frontend/src/pages/Dashboard.tsx`
- [API keys](https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/TokensPage.tsx): `frontend/src/pages/TokensPage.tsx`
- [Runtime settings](https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/SettingsPage.tsx): `frontend/src/pages/SettingsPage.tsx`
- [Chat testing](https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/TestPage.tsx): `frontend/src/pages/TestPage.tsx`
- [Image testing](https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/ImagePage.tsx): `frontend/src/pages/ImagePage.tsx`
- [Video testing](https://github.com/yangyuhou/qwen2api/blob/main/frontend/src/pages/VideoPage.tsx): `frontend/src/pages/VideoPage.tsx`

### Go Gateway

- [HTTP router](https://github.com/yangyuhou/qwen2api/blob/main/backend/main.go): `backend/main.go`
- [Protocol APIs](https://github.com/yangyuhou/qwen2api/tree/main/backend/api): `backend/api`
- [Admin API](https://github.com/yangyuhou/qwen2api/blob/main/backend/api/admin.go): `backend/api/admin.go`

### Request Processing

- [Protocol adapter](https://github.com/yangyuhou/qwen2api/blob/main/backend/adapter/standard_request.go): `backend/adapter/standard_request.go`
- [Context pipeline](https://github.com/yangyuhou/qwen2api/blob/main/backend/context_pipeline.go): `backend/context_pipeline.go`
- [Tool-call parsing](https://github.com/yangyuhou/qwen2api/blob/main/backend/toolcall/parser.go): `backend/toolcall/parser.go`
- [Stream execution](https://github.com/yangyuhou/qwen2api/blob/main/backend/runtime/execution.go): `backend/runtime/execution.go`

### Accounts And Upstream

- [Account pool](https://github.com/yangyuhou/qwen2api/blob/main/backend/core/account_pool/pool_core.go): `backend/core/account_pool/pool_core.go`
- **Qwen Web**
- [Qwen executor](https://github.com/yangyuhou/qwen2api/blob/main/backend/upstream/qwen_executor.go): `backend/upstream/qwen_executor.go`
- [Payload builder](https://github.com/yangyuhou/qwen2api/blob/main/backend/upstream/payload_builder.go): `backend/upstream/payload_builder.go`
- [JSON data stores](https://github.com/yangyuhou/qwen2api/blob/main/backend/core/database.go): `backend/core/database.go`

## Connections

- API clients → HTTP router: send requests (evidence: `README.md`)
- Admin console → HTTP router: calls admin APIs (evidence: `README.md`)
- HTTP router → Protocol adapter: dispatches to (evidence: `README.md`)
- Protocol adapter → Context pipeline: processes through (evidence: `README.md`)
- Context pipeline → Account pool: uses (evidence: `README.md`)
- Account pool → Qwen Web: forwards requests (evidence: `README.md`)
- Account pool → JSON data stores: uses account data (evidence: `README.md`)
- HTTP router → Protocol APIs: routes protocol requests
- HTTP router → Admin API: routes management requests
- Protocol APIs → Protocol adapter: adapts protocols
- Account management → HTTP router: manages accounts
- Dashboard → HTTP router: reads status
- API keys → HTTP router: manages keys
- Runtime settings → HTTP router: updates settings
- Chat testing → HTTP router: tests chat (evidence: `frontend/src/pages/TestPage.tsx`)
- Image testing → HTTP router: tests images
- Video testing → HTTP router: tests videos
- Protocol adapter → Tool-call parsing: handles tool calls
- Context pipeline → Stream execution: passes request
- Stream execution → Payload builder: builds upstream payload
- Payload builder → Qwen executor: provides payload
- Qwen executor → Qwen Web: executes request
