# zqbxdev/webchat2api architecture

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

- Interactive diagram: https://gitdiagram.com/zqbxdev/webchat2api
- Repository: https://github.com/zqbxdev/webchat2api

## Overview

webchat2api is a self-hosted proxy that exposes GPT/ChatGPT Web, Grok/xAI Web, and Gemini Web capabilities through OpenAI-style and Gemini-native APIs, alongside a management UI. The main request path is client → FastAPI routing → protocol adaptation → provider execution using managed accounts → upstream response. Separate product branches cover account administration, image tasks and storage, configuration/backup, and the browser-based management pages. Edges reflect the supplied excerpts, SOURCE INDEX references, or README; unsampled subsystem internals and some runtime wiring are not asserted.

Main entry points: [`api/app.py`](https://github.com/zqbxdev/webchat2api/blob/main/api/app.py) (FastAPI app), [`services/providers/registry.py`](https://github.com/zqbxdev/webchat2api/blob/main/services/providers/registry.py) (Provider registry), [`web/src/lib/api.ts`](https://github.com/zqbxdev/webchat2api/blob/main/web/src/lib/api.ts) (Web API client), [`api/ai.py`](https://github.com/zqbxdev/webchat2api/blob/main/api/ai.py) (AI routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and protocols"]
  node_app["FastAPI app<br/>[app.py]"]
  node_ai_routes["AI routes<br/>[ai.py]"]
  node_gemini_routes["Gemini routes<br/>[gemini.py]"]
  node_chat_protocol["Chat protocol"]
  node_other_protocols["API protocols"]
end

subgraph group_providers["Provider runtime"]
  node_registry["Provider registry<br/>[registry.py]"]
  node_gpt_runtime["GPT runtime"]
  node_grok_runtime["Grok runtime<br/>[client.py]"]
  node_gemini_runtime["Gemini runtime<br/>[client.py]"]
  node_network["Network profiles<br/>[profiles.py]"]
end

subgraph group_management["Accounts and settings"]
  node_account_routes["Account routes<br/>[accounts.py]"]
  node_system_routes["System routes<br/>[system.py]"]
  node_account_service["Account pool<br/>[account_service.py]"]
  node_auth_service["API-key auth<br/>[auth_service.py]"]
  node_storage[("Storage backends")]
  node_config["Configuration<br/>[config.py]"]
  node_backup["Cloud backups<br/>[backup_service.py]"]
end

subgraph group_images["Image workflows"]
  node_image_routes["Image task routes<br/>[image_tasks.py]"]
  node_image_tasks["Image task service"]
  node_image_storage["Image storage"]
end

subgraph group_web["Management interface"]
  node_web_pages["Admin pages"]
  node_web_api["Web API client<br/>[api.ts]"]
  node_web_chat["Chat and images<br/>[page.tsx]"]
  node_web_accounts["Account manager<br/>[page.tsx]"]
  node_web_settings["Settings UI<br/>[page.tsx]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_ai_routes
node_app -->|"mounts routes"| node_gemini_routes
node_app -->|"mounts routes"| node_account_routes
node_app -->|"mounts routes"| node_image_routes
node_app -->|"mounts routes"| node_system_routes
node_ai_routes -->|"dispatches chat"| node_chat_protocol
node_ai_routes -->|"dispatches formats"| node_other_protocols
node_chat_protocol -->|"resolves providers"| node_registry
node_registry -->|"registers models"| node_gpt_runtime
node_registry -->|"registers models"| node_grok_runtime
node_registry -->|"registers models"| node_gemini_runtime
node_grok_runtime -->|"uses profiles"| node_network
node_gemini_runtime -->|"creates sessions"| node_network
node_account_routes -->|"manages accounts"| node_account_service
node_account_routes -->|"uses authentication"| node_auth_service
node_account_service -->|"loads and saves"| node_storage
node_account_service -->|"uses provider rules"| node_registry
node_auth_service -->|"persists keys"| node_storage
node_config -->|"selects backend"| node_storage
node_app -->|"starts service"| node_backup
node_backup -->|"includes image data"| node_image_storage
node_image_routes -->|"handles tasks"| node_image_tasks
node_web_pages -.->|"uses API client"| node_web_api
node_web_chat -.->|"requests services"| node_web_api
node_web_accounts -.->|"requests services"| node_web_api
node_web_settings -.->|"requests services"| node_web_api
node_web_api -.->|"calls management API"| node_app

click node_app "https://github.com/zqbxdev/webchat2api/blob/main/api/app.py"
click node_ai_routes "https://github.com/zqbxdev/webchat2api/blob/main/api/ai.py"
click node_gemini_routes "https://github.com/zqbxdev/webchat2api/blob/main/api/gemini.py"
click node_chat_protocol "https://github.com/zqbxdev/webchat2api/blob/main/services/protocol/openai_v1_chat_complete.py"
click node_other_protocols "https://github.com/zqbxdev/webchat2api/tree/main/services/protocol"
click node_account_routes "https://github.com/zqbxdev/webchat2api/blob/main/api/accounts.py"
click node_system_routes "https://github.com/zqbxdev/webchat2api/blob/main/api/system.py"
click node_account_service "https://github.com/zqbxdev/webchat2api/blob/main/services/account_service.py"
click node_auth_service "https://github.com/zqbxdev/webchat2api/blob/main/services/auth_service.py"
click node_storage "https://github.com/zqbxdev/webchat2api/tree/main/services/storage"
click node_config "https://github.com/zqbxdev/webchat2api/blob/main/services/config.py"
click node_backup "https://github.com/zqbxdev/webchat2api/blob/main/services/backup_service.py"
click node_registry "https://github.com/zqbxdev/webchat2api/blob/main/services/providers/registry.py"
click node_gpt_runtime "https://github.com/zqbxdev/webchat2api/tree/main/services/providers/gpt"
click node_grok_runtime "https://github.com/zqbxdev/webchat2api/blob/main/services/providers/grok/client.py"
click node_gemini_runtime "https://github.com/zqbxdev/webchat2api/blob/main/services/providers/gemini/client.py"
click node_network "https://github.com/zqbxdev/webchat2api/blob/main/services/network/profiles.py"
click node_image_routes "https://github.com/zqbxdev/webchat2api/blob/main/api/image_tasks.py"
click node_image_tasks "https://github.com/zqbxdev/webchat2api/blob/main/services/image_task_service.py"
click node_image_storage "https://github.com/zqbxdev/webchat2api/blob/main/services/image_storage_service.py"
click node_web_pages "https://github.com/zqbxdev/webchat2api/tree/main/web/src/app"
click node_web_api "https://github.com/zqbxdev/webchat2api/blob/main/web/src/lib/api.ts"
click node_web_chat "https://github.com/zqbxdev/webchat2api/blob/main/web/src/app/image/page.tsx"
click node_web_accounts "https://github.com/zqbxdev/webchat2api/blob/main/web/src/app/accounts/page.tsx"
click node_web_settings "https://github.com/zqbxdev/webchat2api/blob/main/web/src/app/settings/page.tsx"

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_app,node_ai_routes,node_gemini_routes,node_chat_protocol,node_other_protocols,node_client toneBlue
class node_registry,node_gpt_runtime,node_grok_runtime,node_gemini_runtime,node_network toneAmber
class node_account_routes,node_system_routes,node_account_service,node_auth_service,node_storage,node_config,node_backup toneMint
class node_image_routes,node_image_tasks,node_image_storage toneRose
class node_web_pages,node_web_api,node_web_chat,node_web_accounts,node_web_settings toneIndigo
```

## Components

### API and protocols

- [FastAPI app](https://github.com/zqbxdev/webchat2api/blob/main/api/app.py): `api/app.py`
- [AI routes](https://github.com/zqbxdev/webchat2api/blob/main/api/ai.py): `api/ai.py`
- [Gemini routes](https://github.com/zqbxdev/webchat2api/blob/main/api/gemini.py): `api/gemini.py`
- [Chat protocol](https://github.com/zqbxdev/webchat2api/blob/main/services/protocol/openai_v1_chat_complete.py): `services/protocol/openai_v1_chat_complete.py`
- [API protocols](https://github.com/zqbxdev/webchat2api/tree/main/services/protocol): `services/protocol`

### Provider runtime

- [Provider registry](https://github.com/zqbxdev/webchat2api/blob/main/services/providers/registry.py): `services/providers/registry.py`
- [GPT runtime](https://github.com/zqbxdev/webchat2api/tree/main/services/providers/gpt): `services/providers/gpt`
- [Grok runtime](https://github.com/zqbxdev/webchat2api/blob/main/services/providers/grok/client.py): `services/providers/grok/client.py`
- [Gemini runtime](https://github.com/zqbxdev/webchat2api/blob/main/services/providers/gemini/client.py): `services/providers/gemini/client.py`
- [Network profiles](https://github.com/zqbxdev/webchat2api/blob/main/services/network/profiles.py): `services/network/profiles.py`

### Accounts and settings

- [Account routes](https://github.com/zqbxdev/webchat2api/blob/main/api/accounts.py): `api/accounts.py`
- [System routes](https://github.com/zqbxdev/webchat2api/blob/main/api/system.py): `api/system.py`
- [Account pool](https://github.com/zqbxdev/webchat2api/blob/main/services/account_service.py): `services/account_service.py`
- [API-key auth](https://github.com/zqbxdev/webchat2api/blob/main/services/auth_service.py): `services/auth_service.py`
- [Storage backends](https://github.com/zqbxdev/webchat2api/tree/main/services/storage): `services/storage`
- [Configuration](https://github.com/zqbxdev/webchat2api/blob/main/services/config.py): `services/config.py`
- [Cloud backups](https://github.com/zqbxdev/webchat2api/blob/main/services/backup_service.py): `services/backup_service.py`

### Image workflows

- [Image task routes](https://github.com/zqbxdev/webchat2api/blob/main/api/image_tasks.py): `api/image_tasks.py`
- [Image task service](https://github.com/zqbxdev/webchat2api/blob/main/services/image_task_service.py): `services/image_task_service.py`
- [Image storage](https://github.com/zqbxdev/webchat2api/blob/main/services/image_storage_service.py): `services/image_storage_service.py`

### Management interface

- [Admin pages](https://github.com/zqbxdev/webchat2api/tree/main/web/src/app): `web/src/app`
- [Web API client](https://github.com/zqbxdev/webchat2api/blob/main/web/src/lib/api.ts): `web/src/lib/api.ts`
- [Chat and images](https://github.com/zqbxdev/webchat2api/blob/main/web/src/app/image/page.tsx): `web/src/app/image/page.tsx`
- [Account manager](https://github.com/zqbxdev/webchat2api/blob/main/web/src/app/accounts/page.tsx): `web/src/app/accounts/page.tsx`
- [Settings UI](https://github.com/zqbxdev/webchat2api/blob/main/web/src/app/settings/page.tsx): `web/src/app/settings/page.tsx`

### Other components

- **API client**

## Connections

- API client → FastAPI app: sends requests
- FastAPI app → AI routes: mounts routes (evidence: `api/app.py`)
- FastAPI app → Gemini routes: mounts routes (evidence: `api/app.py`)
- FastAPI app → Account routes: mounts routes (evidence: `api/app.py`)
- FastAPI app → Image task routes: mounts routes (evidence: `api/app.py`)
- FastAPI app → System routes: mounts routes (evidence: `api/app.py`)
- AI routes → Chat protocol: dispatches chat (evidence: `api/ai.py`)
- AI routes → API protocols: dispatches formats (evidence: `api/ai.py`)
- Chat protocol → Provider registry: resolves providers (evidence: `services/protocol/openai_v1_chat_complete.py`)
- Provider registry → GPT runtime: registers models (evidence: `services/providers/registry.py`)
- Provider registry → Grok runtime: registers models (evidence: `services/providers/registry.py`)
- Provider registry → Gemini runtime: registers models (evidence: `services/providers/registry.py`)
- Grok runtime → Network profiles: uses profiles (evidence: `services/providers/grok/client.py`)
- Gemini runtime → Network profiles: creates sessions (evidence: `services/providers/gemini/client.py`)
- Account routes → Account pool: manages accounts (evidence: `api/accounts.py`)
- Account routes → API-key auth: uses authentication (evidence: `api/accounts.py`)
- Account pool → Storage backends: loads and saves (evidence: `services/account_service.py`)
- Account pool → Provider registry: uses provider rules (evidence: `services/account_service.py`)
- API-key auth → Storage backends: persists keys (evidence: `services/auth_service.py`)
- Configuration → Storage backends: selects backend (evidence: `services/config.py`)
- FastAPI app → Cloud backups: starts service (evidence: `api/app.py`)
- Cloud backups → Image storage: includes image data (evidence: `services/backup_service.py`)
- Image task routes → Image task service: handles tasks (evidence: `api/image_tasks.py`)
- Admin pages → Web API client: uses API client
- Chat and images → Web API client: requests services
- Account manager → Web API client: requests services
- Settings UI → Web API client: requests services
- Web API client → FastAPI app: calls management API
