# youssefvdel/qwengate architecture

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

- Interactive diagram: https://gitdiagram.com/youssefvdel/qwengate
- Repository: https://github.com/youssefvdel/qwengate

## Overview

Qwen Gate is a local OpenAI-compatible gateway to Qwen, with a web dashboard for account and service management. A client submits a chat request; the gateway authenticates and routes it through account/session management to Qwen, then returns a response or SSE stream, translating tool-call text and filtering output when applicable. The README also documents Anthropic compatibility, file uploads, account rotation, and monitoring. Edges reflect README statements or relationships listed in the SOURCE INDEX; unsampled implementation details are not inferred.

Main entry points: [`src/routes/chat.ts`](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/chat.ts) (Chat endpoint), [`src/routes/anthropic.ts`](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/anthropic.ts) (Anthropic endpoint), [`src/index.tsx`](https://github.com/youssefvdel/qwengate/blob/dev/src/index.tsx) (HTTP server), [`src/services/qwen.ts`](https://github.com/youssefvdel/qwengate/blob/dev/src/services/qwen.ts) (Qwen client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and chat"]
  node_server["HTTP server<br/>[index.tsx]"]
  node_chat["Chat endpoint<br/>[chat.ts]"]
  node_anthropic["Anthropic endpoint<br/>[anthropic.ts]"]
  node_chathelpers["Chat preparation<br/>[chatHelpers.ts]"]
  node_nonstream["Non-stream response"]
  node_stream["SSE response<br/>[chatStreaming.ts]"]
  node_streamhelpers["Stream helpers"]
  node_toolparser["Tool-call parser<br/>[xmlToolParser.ts]"]
end

subgraph group_accounts["Accounts and sessions"]
  node_accountsroute["Account routes<br/>[accounts.ts]"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_accountmanager[("Account manager<br/>[accountManager.ts]")]
  node_profiles["Browser profiles<br/>[browserProfiles.ts]"]
  node_playwright["Browser login<br/>[playwright.ts]"]
  node_sessionpool["Session pool<br/>[sessionPool.ts]"]
end

subgraph group_upstream["Qwen transport"]
  node_qwen["Qwen client<br/>[qwen.ts]"]
  node_fileupload["File uploads<br/>[qwenFileUpload.ts]"]
  node_browserless["Browserless fetch"]
  node_modelrouter["Model health routing<br/>[modelRouter.ts]"]
end

subgraph group_ops["Operations and dashboard"]
  node_dashboard["Dashboard routes<br/>[dashboardRoutes.ts]"]
  node_monitor["Dashboard monitoring<br/>[monitor.ts]"]
  node_network["Network diagnostics<br/>[debugNetwork.ts]"]
  node_logs[("Request logs<br/>[logStore.ts]")]
end

subgraph group_shared["Shared services"]
  node_openaitypes["OpenAI types<br/>[openai.ts]"]
  node_config[("Configuration<br/>[configService.ts]")]
  node_ratelimit["Rate limiting<br/>[rateLimit.ts]"]
  node_authtypes["Account types<br/>[auth.ts]"]
  node_paths["Path utilities<br/>[paths.ts]"]
end

node_client(("API client"))
node_qwenservice(("Qwen service"))

node_client -->|"sends requests"| node_server
node_server -->|"routes chat"| node_chat
node_server -->|"routes API"| node_anthropic
node_server -->|"routes accounts"| node_accountsroute
node_server -->|"registers routes"| node_dashboard
node_server -->|"applies limits"| node_ratelimit
node_chat -->|"prepares request"| node_chathelpers
node_chat -->|"handles response"| node_nonstream
node_chat -->|"handles streaming"| node_stream
node_anthropic -->|"uses chat helpers"| node_chathelpers
node_chat -->|"selects model"| node_modelrouter
node_chat -->|"requests completion"| node_qwen
node_anthropic -->|"requests completion"| node_qwen
node_chat -->|"acquires sessions"| node_sessionpool
node_anthropic -->|"acquires sessions"| node_sessionpool
node_chat -->|"uploads context"| node_fileupload
node_anthropic -->|"uploads context"| node_fileupload
node_nonstream -->|"parses tool calls"| node_toolparser
node_stream -->|"uses helpers"| node_streamhelpers
node_chat -->|"uses API types"| node_openaitypes
node_anthropic -->|"uses API types"| node_openaitypes
node_accountsroute -->|"manages auth"| node_auth
node_auth -->|"loads accounts"| node_accountmanager
node_auth -->|"loads profile tokens"| node_playwright
node_accountmanager -->|"uses account types"| node_authtypes
node_auth -->|"uses profiles"| node_profiles
node_playwright -->|"uses profile helpers"| node_profiles
node_sessionpool -->|"selects accounts"| node_auth
node_sessionpool -->|"gets headers"| node_playwright
node_sessionpool -->|"creates sessions"| node_browserless
node_qwen -->|"gets account token"| node_auth
node_qwen -->|"sends requests"| node_browserless
node_qwen -->|"calls upstream"| node_qwenservice
node_qwen -->|"uses pooled sessions"| node_sessionpool
node_fileupload -->|"uploads files"| node_qwenservice
node_dashboard -->|"routes monitoring"| node_monitor
node_dashboard -->|"reports accounts"| node_accountmanager
node_dashboard -->|"reads and updates"| node_config
node_dashboard -->|"serves logs"| node_logs
node_network -.->|"records diagnostics"| node_logs
node_config -->|"resolves files"| node_paths
node_logs -->|"reads settings"| node_config
node_chat -->|"records requests"| node_logs
node_anthropic -->|"records requests"| node_logs

click node_server "https://github.com/youssefvdel/qwengate/blob/dev/src/index.tsx"
click node_chat "https://github.com/youssefvdel/qwengate/blob/dev/src/routes/chat.ts"
click node_anthropic "https://github.com/youssefvdel/qwengate/blob/dev/src/routes/anthropic.ts"
click node_chathelpers "https://github.com/youssefvdel/qwengate/blob/dev/src/routes/chatHelpers.ts"
click node_nonstream "https://github.com/youssefvdel/qwengate/blob/dev/src/routes/chatNonStreaming.ts"
click node_stream "https://github.com/youssefvdel/qwengate/blob/dev/src/routes/chatStreaming.ts"
click node_streamhelpers "https://github.com/youssefvdel/qwengate/blob/dev/src/routes/chatStreamingHelpers.ts"
click node_toolparser "https://github.com/youssefvdel/qwengate/blob/dev/src/tools/xmlToolParser.ts"
click node_openaitypes "https://github.com/youssefvdel/qwengate/blob/dev/src/types/openai.ts"
click node_accountsroute "https://github.com/youssefvdel/qwengate/blob/dev/src/routes/accounts.ts"
click node_auth "https://github.com/youssefvdel/qwengate/blob/dev/src/services/auth.ts"
click node_accountmanager "https://github.com/youssefvdel/qwengate/blob/dev/src/services/accountManager.ts"
click node_profiles "https://github.com/youssefvdel/qwengate/blob/dev/src/services/browserProfiles.ts"
click node_playwright "https://github.com/youssefvdel/qwengate/blob/dev/src/services/playwright.ts"
click node_sessionpool "https://github.com/youssefvdel/qwengate/blob/dev/src/services/sessionPool.ts"
click node_qwen "https://github.com/youssefvdel/qwengate/blob/dev/src/services/qwen.ts"
click node_fileupload "https://github.com/youssefvdel/qwengate/blob/dev/src/services/qwenFileUpload.ts"
click node_browserless "https://github.com/youssefvdel/qwengate/blob/dev/src/services/browserlessFetch.ts"
click node_modelrouter "https://github.com/youssefvdel/qwengate/blob/dev/src/services/modelRouter.ts"
click node_dashboard "https://github.com/youssefvdel/qwengate/blob/dev/src/routes/dashboard/dashboardRoutes.ts"
click node_monitor "https://github.com/youssefvdel/qwengate/blob/dev/src/routes/dashboard/monitor.ts"
click node_network "https://github.com/youssefvdel/qwengate/blob/dev/src/routes/debugNetwork.ts"
click node_config "https://github.com/youssefvdel/qwengate/blob/dev/src/services/configService.ts"
click node_logs "https://github.com/youssefvdel/qwengate/blob/dev/src/services/logStore.ts"
click node_ratelimit "https://github.com/youssefvdel/qwengate/blob/dev/src/middleware/rateLimit.ts"
click node_authtypes "https://github.com/youssefvdel/qwengate/blob/dev/src/types/auth.ts"
click node_paths "https://github.com/youssefvdel/qwengate/blob/dev/src/utils/paths.ts"

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_chat,node_anthropic,node_chathelpers,node_nonstream,node_stream,node_streamhelpers,node_toolparser,node_client toneBlue
class node_accountsroute,node_auth,node_accountmanager,node_profiles,node_playwright,node_sessionpool toneAmber
class node_qwen,node_fileupload,node_browserless,node_modelrouter toneMint
class node_dashboard,node_monitor,node_network,node_logs toneRose
class node_openaitypes,node_config,node_ratelimit,node_authtypes,node_paths,node_qwenservice toneIndigo
```

## Components

### API and chat

- [HTTP server](https://github.com/youssefvdel/qwengate/blob/dev/src/index.tsx): `src/index.tsx`
- [Chat endpoint](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/chat.ts): `src/routes/chat.ts`
- [Anthropic endpoint](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/anthropic.ts): `src/routes/anthropic.ts`
- [Chat preparation](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/chatHelpers.ts): `src/routes/chatHelpers.ts`
- [Non-stream response](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/chatNonStreaming.ts): `src/routes/chatNonStreaming.ts`
- [SSE response](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/chatStreaming.ts): `src/routes/chatStreaming.ts`
- [Stream helpers](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/chatStreamingHelpers.ts): `src/routes/chatStreamingHelpers.ts`
- [Tool-call parser](https://github.com/youssefvdel/qwengate/blob/dev/src/tools/xmlToolParser.ts): `src/tools/xmlToolParser.ts`

### Accounts and sessions

- [Account routes](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/accounts.ts): `src/routes/accounts.ts`
- [Authentication](https://github.com/youssefvdel/qwengate/blob/dev/src/services/auth.ts): `src/services/auth.ts`
- [Account manager](https://github.com/youssefvdel/qwengate/blob/dev/src/services/accountManager.ts): `src/services/accountManager.ts`
- [Browser profiles](https://github.com/youssefvdel/qwengate/blob/dev/src/services/browserProfiles.ts): `src/services/browserProfiles.ts`
- [Browser login](https://github.com/youssefvdel/qwengate/blob/dev/src/services/playwright.ts): `src/services/playwright.ts`
- [Session pool](https://github.com/youssefvdel/qwengate/blob/dev/src/services/sessionPool.ts): `src/services/sessionPool.ts`

### Qwen transport

- [Qwen client](https://github.com/youssefvdel/qwengate/blob/dev/src/services/qwen.ts): `src/services/qwen.ts`
- [File uploads](https://github.com/youssefvdel/qwengate/blob/dev/src/services/qwenFileUpload.ts): `src/services/qwenFileUpload.ts`
- [Browserless fetch](https://github.com/youssefvdel/qwengate/blob/dev/src/services/browserlessFetch.ts): `src/services/browserlessFetch.ts`
- [Model health routing](https://github.com/youssefvdel/qwengate/blob/dev/src/services/modelRouter.ts): `src/services/modelRouter.ts`

### Operations and dashboard

- [Dashboard routes](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/dashboard/dashboardRoutes.ts): `src/routes/dashboard/dashboardRoutes.ts`
- [Dashboard monitoring](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/dashboard/monitor.ts): `src/routes/dashboard/monitor.ts`
- [Network diagnostics](https://github.com/youssefvdel/qwengate/blob/dev/src/routes/debugNetwork.ts): `src/routes/debugNetwork.ts`
- [Request logs](https://github.com/youssefvdel/qwengate/blob/dev/src/services/logStore.ts): `src/services/logStore.ts`

### Shared services

- [OpenAI types](https://github.com/youssefvdel/qwengate/blob/dev/src/types/openai.ts): `src/types/openai.ts`
- [Configuration](https://github.com/youssefvdel/qwengate/blob/dev/src/services/configService.ts): `src/services/configService.ts`
- [Rate limiting](https://github.com/youssefvdel/qwengate/blob/dev/src/middleware/rateLimit.ts): `src/middleware/rateLimit.ts`
- [Account types](https://github.com/youssefvdel/qwengate/blob/dev/src/types/auth.ts): `src/types/auth.ts`
- [Path utilities](https://github.com/youssefvdel/qwengate/blob/dev/src/utils/paths.ts): `src/utils/paths.ts`

### Other components

- **API client**
- **Qwen service**

## Connections

- API client → HTTP server: sends requests
- HTTP server → Chat endpoint: routes chat (evidence: `src/index.tsx`)
- HTTP server → Anthropic endpoint: routes API (evidence: `src/index.tsx`)
- HTTP server → Account routes: routes accounts (evidence: `src/index.tsx`)
- HTTP server → Dashboard routes: registers routes (evidence: `src/index.tsx`)
- HTTP server → Rate limiting: applies limits (evidence: `src/index.tsx`)
- Chat endpoint → Chat preparation: prepares request (evidence: `src/routes/chat.ts`)
- Chat endpoint → Non-stream response: handles response (evidence: `src/routes/chat.ts`)
- Chat endpoint → SSE response: handles streaming (evidence: `src/routes/chat.ts`)
- Anthropic endpoint → Chat preparation: uses chat helpers (evidence: `src/routes/anthropic.ts`)
- Chat endpoint → Model health routing: selects model (evidence: `src/routes/chat.ts`)
- Chat endpoint → Qwen client: requests completion (evidence: `src/routes/chat.ts`)
- Anthropic endpoint → Qwen client: requests completion (evidence: `src/routes/anthropic.ts`)
- Chat endpoint → Session pool: acquires sessions (evidence: `src/routes/chat.ts`)
- Anthropic endpoint → Session pool: acquires sessions (evidence: `src/routes/anthropic.ts`)
- Chat endpoint → File uploads: uploads context (evidence: `src/routes/chat.ts`)
- Anthropic endpoint → File uploads: uploads context (evidence: `src/routes/anthropic.ts`)
- Non-stream response → Tool-call parser: parses tool calls (evidence: `src/routes/chatNonStreaming.ts`)
- SSE response → Stream helpers: uses helpers (evidence: `src/routes/chatStreaming.ts`)
- Chat endpoint → OpenAI types: uses API types (evidence: `src/routes/chat.ts`)
- Anthropic endpoint → OpenAI types: uses API types (evidence: `src/routes/anthropic.ts`)
- Account routes → Authentication: manages auth (evidence: `src/routes/accounts.ts`)
- Authentication → Account manager: loads accounts (evidence: `src/services/auth.ts`)
- Authentication → Browser login: loads profile tokens (evidence: `src/services/auth.ts`)
- Account manager → Account types: uses account types (evidence: `src/services/accountManager.ts`)
- Authentication → Browser profiles: uses profiles (evidence: `src/services/auth.ts`)
- Browser login → Browser profiles: uses profile helpers (evidence: `src/services/playwright.ts`)
- Session pool → Authentication: selects accounts (evidence: `src/services/sessionPool.ts`)
- Session pool → Browser login: gets headers (evidence: `src/services/sessionPool.ts`)
- Session pool → Browserless fetch: creates sessions (evidence: `src/services/sessionPool.ts`)
- Qwen client → Authentication: gets account token (evidence: `src/services/qwen.ts`)
- Qwen client → Browserless fetch: sends requests (evidence: `src/services/qwen.ts`)
- Qwen client → Qwen service: calls upstream
- Qwen client → Session pool: uses pooled sessions (evidence: `src/routes/chat.ts`)
- File uploads → Qwen service: uploads files
- Dashboard routes → Dashboard monitoring: routes monitoring (evidence: `src/routes/dashboard/dashboardRoutes.ts`)
- Dashboard routes → Account manager: reports accounts (evidence: `src/routes/dashboard/dashboardRoutes.ts`)
- Dashboard routes → Configuration: reads and updates (evidence: `src/routes/dashboard/dashboardRoutes.ts`)
- Dashboard routes → Request logs: serves logs (evidence: `src/routes/dashboard/dashboardRoutes.ts`)
- Network diagnostics → Request logs: records diagnostics
- Configuration → Path utilities: resolves files (evidence: `src/services/configService.ts`)
- Request logs → Configuration: reads settings (evidence: `src/services/logStore.ts`)
- Chat endpoint → Request logs: records requests (evidence: `src/routes/chat.ts`)
- Anthropic endpoint → Request logs: records requests (evidence: `src/routes/anthropic.ts`)
