# y13sint/freeqwenapi architecture

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

- Interactive diagram: https://gitdiagram.com/y13sint/freeqwenapi
- Repository: https://github.com/y13sint/freeqwenapi

## Overview

FreeQwenApi is a local OpenAI-compatible proxy that adapts Qwen Chat’s browser-backed service for chat, media generation, model discovery, and file uploads. The main request path is client → Express entry point → API routes → chat adapter → Qwen Chat, with account tokens and browser sessions supporting authenticated requests. Separate API capabilities are preserved as distinct components. The excerpts show only parts of routing and runtime code, so uncertain internal links are omitted; README-documented capabilities are included where implementation details were not shown.

Main entry points: [`src/api/routes.js`](https://github.com/y13sint/freeqwenapi/blob/main/src/api/routes.js) (API routes), [`src/utils/accountSetup.js`](https://github.com/y13sint/freeqwenapi/blob/main/src/utils/accountSetup.js) (Account setup), [`src/api/chat.js`](https://github.com/y13sint/freeqwenapi/blob/main/src/api/chat.js) (Chat completions), [`src/api/tokenManager.js`](https://github.com/y13sint/freeqwenapi/blob/main/src/api/tokenManager.js) (Account tokens)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Proxy API"]
  node_server["HTTP server<br/>[index.js]"]
  node_routes["API routes<br/>[routes.js]"]
end

subgraph group_qwen["Qwen Integration"]
  node_chat["Chat completions<br/>[chat.js]"]
  node_history[("Chat history<br/>[chatHistory.js]")]
  node_models["Model mapping<br/>[modelMapping.js]"]
  node_files["File uploads<br/>[fileUpload.js]"]
  node_images["Image generation<br/>[imageGeneration.js]"]
end

subgraph group_accounts["Accounts &amp; Sessions"]
  node_accountsetup["Account setup<br/>[accountSetup.js]"]
  node_auth["Browser authentication<br/>[auth.js]"]
  node_browser["Browser runtime<br/>[browser.js]"]
  node_session[("Session storage<br/>[session.js]")]
  node_tokens[("Account tokens<br/>[tokenManager.js]")]
end

subgraph group_support["Runtime Support"]
  node_config["Configuration<br/>[config.js]"]
  node_logger["Logging<br/>[index.js]"]
  node_prompt["Interactive prompt<br/>[prompt.js]"]
  node_branding["Watermark branding<br/>[branding.js]"]
end

node_client(("API client"))
node_qwenservice["Qwen Chat"]

node_client -->|"sends requests"| node_server
node_server -->|"mounts API"| node_routes
node_routes -->|"dispatches chat"| node_chat
node_chat -->|"sends chat requests"| node_qwenservice
node_routes -.->|"uses history"| node_history
node_routes -.->|"maps models"| node_models
node_routes -->|"dispatches uploads"| node_files
node_routes -->|"dispatches generation"| node_images
node_routes -->|"requests video tasks"| node_qwenservice
node_client -->|"requests media"| node_routes
node_accountsetup -->|"starts browser"| node_browser
node_accountsetup -->|"extracts token"| node_chat
node_accountsetup -->|"saves accounts"| node_tokens
node_auth -->|"saves session"| node_session
node_browser -->|"starts login"| node_auth
node_browser -->|"stores session"| node_session
node_chat -->|"selects account"| node_tokens
node_chat -->|"checks login"| node_auth
node_routes -->|"updates status"| node_tokens
node_server -.->|"reads settings"| node_config
node_routes -->|"logs requests"| node_logger
node_tokens -->|"logs errors"| node_logger
node_accountsetup -->|"prompts operator"| node_prompt
node_accountsetup -->|"prints watermark"| node_branding

click node_server "https://github.com/y13sint/freeqwenapi/blob/main/index.js"
click node_routes "https://github.com/y13sint/freeqwenapi/blob/main/src/api/routes.js"
click node_chat "https://github.com/y13sint/freeqwenapi/blob/main/src/api/chat.js"
click node_history "https://github.com/y13sint/freeqwenapi/blob/main/src/api/chatHistory.js"
click node_models "https://github.com/y13sint/freeqwenapi/blob/main/src/api/modelMapping.js"
click node_files "https://github.com/y13sint/freeqwenapi/blob/main/src/api/fileUpload.js"
click node_images "https://github.com/y13sint/freeqwenapi/blob/main/src/api/imageGeneration.js"
click node_accountsetup "https://github.com/y13sint/freeqwenapi/blob/main/src/utils/accountSetup.js"
click node_auth "https://github.com/y13sint/freeqwenapi/blob/main/src/browser/auth.js"
click node_browser "https://github.com/y13sint/freeqwenapi/blob/main/src/browser/browser.js"
click node_session "https://github.com/y13sint/freeqwenapi/blob/main/src/browser/session.js"
click node_tokens "https://github.com/y13sint/freeqwenapi/blob/main/src/api/tokenManager.js"
click node_config "https://github.com/y13sint/freeqwenapi/blob/main/src/config.js"
click node_logger "https://github.com/y13sint/freeqwenapi/blob/main/src/logger/index.js"
click node_prompt "https://github.com/y13sint/freeqwenapi/blob/main/src/utils/prompt.js"
click node_branding "https://github.com/y13sint/freeqwenapi/blob/main/src/utils/branding.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_chat,node_history,node_models,node_files,node_images toneAmber
class node_accountsetup,node_auth,node_browser,node_session,node_tokens toneMint
class node_config,node_logger,node_prompt,node_branding toneRose
class node_qwenservice toneIndigo
```

## Components

### Proxy API

- [HTTP server](https://github.com/y13sint/freeqwenapi/blob/main/index.js): `index.js`
- [API routes](https://github.com/y13sint/freeqwenapi/blob/main/src/api/routes.js): `src/api/routes.js`

### Qwen Integration

- [Chat completions](https://github.com/y13sint/freeqwenapi/blob/main/src/api/chat.js): `src/api/chat.js`
- [Chat history](https://github.com/y13sint/freeqwenapi/blob/main/src/api/chatHistory.js): `src/api/chatHistory.js`
- [Model mapping](https://github.com/y13sint/freeqwenapi/blob/main/src/api/modelMapping.js): `src/api/modelMapping.js`
- [File uploads](https://github.com/y13sint/freeqwenapi/blob/main/src/api/fileUpload.js): `src/api/fileUpload.js`
- [Image generation](https://github.com/y13sint/freeqwenapi/blob/main/src/api/imageGeneration.js): `src/api/imageGeneration.js`

### Accounts & Sessions

- [Account setup](https://github.com/y13sint/freeqwenapi/blob/main/src/utils/accountSetup.js): `src/utils/accountSetup.js`
- [Browser authentication](https://github.com/y13sint/freeqwenapi/blob/main/src/browser/auth.js): `src/browser/auth.js`
- [Browser runtime](https://github.com/y13sint/freeqwenapi/blob/main/src/browser/browser.js): `src/browser/browser.js`
- [Session storage](https://github.com/y13sint/freeqwenapi/blob/main/src/browser/session.js): `src/browser/session.js`
- [Account tokens](https://github.com/y13sint/freeqwenapi/blob/main/src/api/tokenManager.js): `src/api/tokenManager.js`

### Runtime Support

- [Configuration](https://github.com/y13sint/freeqwenapi/blob/main/src/config.js): `src/config.js`
- [Logging](https://github.com/y13sint/freeqwenapi/blob/main/src/logger/index.js): `src/logger/index.js`
- [Interactive prompt](https://github.com/y13sint/freeqwenapi/blob/main/src/utils/prompt.js): `src/utils/prompt.js`
- [Watermark branding](https://github.com/y13sint/freeqwenapi/blob/main/src/utils/branding.js): `src/utils/branding.js`

### Other components

- **API client**
- **Qwen Chat**

## Connections

- API client → HTTP server: sends requests (evidence: `README.md`)
- HTTP server → API routes: mounts API (evidence: `index.js`)
- API routes → Chat completions: dispatches chat (evidence: `src/api/routes.js`)
- Chat completions → Qwen Chat: sends chat requests (evidence: `README.md`)
- API routes → Chat history: uses history (evidence: `src/api/routes.js`)
- API routes → Model mapping: maps models (evidence: `src/api/routes.js`)
- API routes → File uploads: dispatches uploads (evidence: `src/api/routes.js`)
- API routes → Image generation: dispatches generation (evidence: `README.md`)
- API routes → Qwen Chat: requests video tasks (evidence: `README.md`)
- API client → API routes: requests media (evidence: `README.md`)
- Account setup → Browser runtime: starts browser (evidence: `src/utils/accountSetup.js`)
- Account setup → Chat completions: extracts token (evidence: `src/utils/accountSetup.js`)
- Account setup → Account tokens: saves accounts (evidence: `src/utils/accountSetup.js`)
- Browser authentication → Session storage: saves session (evidence: `src/browser/auth.js`)
- Browser runtime → Browser authentication: starts login (evidence: `src/browser/browser.js`)
- Browser runtime → Session storage: stores session (evidence: `src/browser/browser.js`)
- Chat completions → Account tokens: selects account (evidence: `src/api/chat.js`)
- Chat completions → Browser authentication: checks login (evidence: `src/api/chat.js`)
- API routes → Account tokens: updates status (evidence: `src/api/routes.js`)
- HTTP server → Configuration: reads settings (evidence: `index.js`)
- API routes → Logging: logs requests (evidence: `src/api/routes.js`)
- Account tokens → Logging: logs errors (evidence: `src/api/tokenManager.js`)
- Account setup → Interactive prompt: prompts operator (evidence: `src/utils/accountSetup.js`)
- Account setup → Watermark branding: prints watermark (evidence: `src/utils/accountSetup.js`)
