# qabot-zh/chatgpt-next-web architecture

> Architecture diagram of the GitHub repository qabot-zh/chatgpt-next-web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/qabot-zh/chatgpt-next-web
- Repository: https://github.com/qabot-zh/chatgpt-next-web

## Overview

##### Project type and purpose
- This is a full-stack hybrid web & desktop chat application (NextraChat).
- Purpose: Provide a customizable ChatGPT-like UI with multiple AI providers, cloud backup, file upload, i18n, and optional desktop packaging via Tauri.

##### File structure
- Top level:
- config files (Dockerfile, tsconfig.json, next.config.mjs, GitHub workflows)
- app/ – Next.js “app” directory containing:
– api/ – serverless route handlers for anthropic, openai, google, upstash (key-value), webdav
– client/ – client-side adapters, controller logic, platform drivers
– components/ – UI React components (chat, sidebar, settings, etc.)
– config/, constant.ts, utils.ts, utils/ – build, client, server config and utility functions
– store/ – Zustand or Redux-style state management slices
– locales/, masks/ – internationalization and prompt templates
– layout.tsx, page.tsx – root layout and pages
- public/ – static assets (prompts.json, service worker)
- scripts/ – automation for deployments and prompt fetching
- src-tauri/ – Rust back end for the Tauri desktop app
- docs/ – user manual and deployment guides
- Patterns:
- Next.js App Router for SSR/SSG and serverless API
- Client-side state management via store/
- Modular “platform” pattern for AI providers
- Tauri bridge for desktop packaging

##### README insights
- Core features: model selector, chat history search, OCR, translation, cloud backup
- Supported AI channels: OpenAI, Anthropic, Google, Upstash (for KV backup), WebDAV (for file backup)
- Extensive environment variable configuration for provider keys, UI customization, and feature toggles
- Multiple deployment targets: Docker, Vercel, Cloudflare Pages, Tauri desktop

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Web Layer
    subgraph "Web Layer"
        direction TB
        subgraph "Frontend" 
            direction TB
            UI["Client UI"]:::frontend
            State["State Store"]:::frontend
        end
        subgraph "Next.js Server/API" 
            direction TB
            API["API Controller"]:::server
            subgraph "API Routes" 
                direction TB
                AnthropicAPI["Anthropic Route"]:::server
                OpenAIAPI["OpenAI Route"]:::server
                GoogleAPI["Google Route"]:::server
                UpstashAPI["Upstash Route"]:::server
                WebDAVAPI["WebDAV Route"]:::server
                AuthAPI["Auth Route"]:::server
                CommonAPI["Common Route"]:::server
                ConfigAPI["Config Route"]:::server
                ArtifactsAPI["Artifacts Route"]:::server
            end
        end
    end

    %% External AI Providers
    subgraph "External AI Providers"
        direction TB
        Anthropic["Anthropic API"]:::external
        OpenAI["OpenAI API"]:::external
        Google["Google API"]:::external
    end

    %% Cloud Backup Services
    subgraph "Cloud Backup Services"
        direction TB
        Upstash["Upstash KV"]:::external
        WebDAVService["WebDAV Server"]:::external
    end

    %% Desktop Layer
    subgraph "Desktop Layer"
        direction TB
        Bridge["Tauri Frontend Bridge"]:::frontend
        Backend["Rust Backend"]:::server
        FS["Local Filesystem"]:::external
    end

    %% Deployment Pipeline
    subgraph "Deployment Pipeline"
        direction TB
        GH["GitHub Actions"]:::deployment
        DockerImg["Docker Image"]:::deployment
        Cloud["Vercel/Cloudflare"]:::deployment
        TauriBundle["Tauri Bundler"]:::deployment
    end

    %% Flows
    User["User"]:::frontend -->|"interacts with"| UI
    UI -->|"reads/writes"| State
    UI -->|"calls"| API
    API -->|"routes to"| AnthropicAPI
    API -->|"routes to"| OpenAIAPI
    API -->|"routes to"| GoogleAPI
    API -->|"routes to"| UpstashAPI
    API -->|"routes to"| WebDAVAPI

    AnthropicAPI -->|"calls"| Anthropic
    OpenAIAPI -->|"calls"| OpenAI
    GoogleAPI -->|"calls"| Google

    UI -->|"backup via"| UpstashAPI
    UI -->|"backup via"| WebDAVAPI
    UpstashAPI -->|"stores in"| Upstash
    WebDAVAPI -->|"stores in"| WebDAVService

    %% Desktop interactions
    UI -->|"desktop call"| Bridge
    Bridge -->|"invokes"| Backend
    Backend -->|"reads/writes"| FS
    Bridge -->|"returns data"| UI

    %% Deployment flows
    GH --> DockerImg
    DockerImg --> Cloud
    GH --> TauriBundle

    %% Click events
    click UI "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/layout.tsx"
    click UI "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/page.tsx"
    click UI "https://github.com/qabot-zh/chatgpt-next-web/tree/main/app/components/"
    click State "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/store/index.ts"
    click State "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/store/chat.ts"
    click State "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/store/provider.ts"
    click API "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/client/controller.ts"
    click API "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/client/api.ts"
    click AnthropicAPI "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/api/anthropic/[...path]/route.ts"
    click OpenAIAPI "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/api/openai/[...path]/route.ts"
    click GoogleAPI "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/api/google/[...path]/route.ts"
    click UpstashAPI "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/api/upstash/[action]/[...key]/route.ts"
    click WebDAVAPI "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/api/webdav/[...path]/route.ts"
    click AuthAPI "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/api/auth.ts"
    click CommonAPI "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/api/common.ts"
    click ConfigAPI "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/api/config/route.ts"
    click ArtifactsAPI "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/api/artifacts/route.ts"
    click API "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/client/platforms/anthropic.ts"
    click API "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/client/platforms/openai.ts"
    click API "https://github.com/qabot-zh/chatgpt-next-web/blob/main/app/client/platforms/google.ts"
    click Bridge "https://github.com/qabot-zh/chatgpt-next-web/blob/main/src-tauri/src/main.rs"
    click Backend "https://github.com/qabot-zh/chatgpt-next-web/blob/main/src-tauri/Cargo.toml"
    click Backend "https://github.com/qabot-zh/chatgpt-next-web/blob/main/src-tauri/tauri.conf.json"
    click Backend "https://github.com/qabot-zh/chatgpt-next-web/blob/main/src-tauri/build.rs"
    click GH "https://github.com/qabot-zh/chatgpt-next-web/blob/main/scripts/fetch-prompts.mjs"
    click GH "https://github.com/qabot-zh/chatgpt-next-web/blob/main/scripts/setup.sh"
    click DockerImg "https://github.com/qabot-zh/chatgpt-next-web/tree/main/Dockerfile"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#006064
    classDef server fill:#E8F5E9,stroke:#1B5E20,color:#1B5E20
    classDef external fill:#FFF3E0,stroke:#E65100,color:#E65100
    classDef deployment fill:#EEEEEE,stroke:#616161,color:#616161
```
