# chatgptnextweb/chatgpt-next-web architecture

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

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

## Overview

##### High-Level Components (Main Layer)

a) Client-Side Components:
- Web Application (Next.js)
- Desktop Application (Tauri)
- PWA Support
- Service Worker

b) Server-Side Components:
- API Routes (Next.js API)
- Model Providers Integration
- Cloud Storage Services
- Authentication System

##### Core Architectural Patterns

**[Client Layer]**

- Web Interface (Next.js)
- Components
- Store (State Management)
- Utils

- Desktop Client (Tauri)
- Native Shell
- Web View

**[API Layer]**

- Route Handlers
- Model Providers
- Authentication
- Configuration

**[External Services]**

- AI Models
- OpenAI
- Azure
- Google
- Other Providers

- Storage
- WebDAV
- UpStash
- Local Storage

##### Key Components to Highlight

a) Frontend Architecture:
- Components (/app/components)
- Store Management (/app/store)
- API Clients (/app/client)
- Utilities (/app/utils)
- Localization (/app/locales)

b) API Integration:
- Multiple Model Providers (/app/api/[provider])
- Authentication Handlers
- Configuration Management
- Storage Services

c) Cross-Platform Support:
- Web Application (Next.js)
- Desktop Client (Tauri)
- PWA Capabilities

##### Data Flow Patterns

Following interactions:
- Client-Server Communication
- State Management Flow
- Authentication Flow
- Model Provider Integration
- Storage Synchronization

##### Special Features

- Real-time Chat Support
- Plugin System
- Artifacts Management
- Multi-language Support
- Theme System (Dark/Light Mode)
- Prompt Templates
- Voice Integration

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        WebApp["Web Application (Next.js)"]
        Desktop["Desktop Application (Tauri)"]:::desktop
        PWA["Progressive Web App"]
        SW["Service Worker"]:::sw

        Components["UI Components"]:::components
        Store["State Management"]:::store
        APIClients["API Clients"]:::apiclients
        Utils["Utility Functions"]:::utils
        Locales["Localization System"]:::locales
        Config["Configuration"]:::config
        
        WebApp --> Components
        WebApp --> Store
        WebApp --> APIClients
        WebApp --> Utils
        WebApp --> Locales
        WebApp --> Config
        
        Desktop --> WebApp
    end

    subgraph "API Layer"
        Routes["Route Handlers"]
        Auth["Authentication System"]:::auth
        ModelProviders["Model Providers Integration"]:::providers
        StorageHandlers["Storage Handlers"]
        
        Routes --> Auth
        Routes --> ModelProviders
        Routes --> StorageHandlers
    end

    subgraph Features
        RealTime["Real-time Chat"]:::realtime
        Voice["Voice Integration"]:::voice
        Plugins["Plugin System"]:::plugins
        Templates["Prompt Templates"]:::templates
        Theme["Theme System"]:::theme
        
        Components --> RealTime
        Components --> Voice
        Components --> Plugins
        Components --> Templates
        Components --> Theme
    end

    subgraph "External Services"
        AI["AI Models"]
        Storage["Storage Services"]
        
        subgraph "AI Providers"
            OpenAI["OpenAI"]
            Azure["Azure"]
            Google["Google"]
        end
        
        subgraph "Storage Providers"
            WebDAV["WebDAV"]:::webdav
            UpStash["UpStash"]:::upstash
            LocalStorage["Local Storage"]
        end
        
        AI --> OpenAI
        AI --> Azure
        AI --> Google
        
        Storage --> WebDAV
        Storage --> UpStash
        Storage --> LocalStorage
    end

    WebApp --> Routes
    Routes --> AI
    Routes --> Storage

    %% Component Mappings
    click Desktop "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/src-tauri"
    click Components "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/components"
    click Store "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/store"
    click APIClients "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/client"
    click ModelProviders "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/api/[provider]"
    click StorageHandlers "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/utils/cloud"
    click Auth "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/blob/main/app/api/auth.ts"
    click Locales "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/locales"
    click RealTime "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/components/realtime-chat"
    click Voice "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/components/voice-print"
    click Plugins "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/blob/main/app/components/plugin.tsx"
    click Templates "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/masks"
    click Config "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/config"
    click Utils "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/utils"
    click WebDAV "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/api/webdav"
    click UpStash "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/tree/main/app/api/upstash"
    click SW "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/blob/main/public/serviceWorker.js"
    click Theme "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/blob/main/app/styles/globals.scss"

    classDef desktop fill:#b8d4ff,stroke:#2d6bff
    classDef components fill:#a8e6cf,stroke:#3d8b61
    classDef store fill:#ffd3b6,stroke:#ff8b3d
    classDef apiclients fill:#ffaaa5,stroke:#ff5c5c
    classDef utils fill:#dcedc1,stroke:#a5c663
    classDef locales fill:#c7ceea,stroke:#6b7db3
    classDef providers fill:#ff8b94,stroke:#e63946
    classDef auth fill:#ff6b6b,stroke:#c92a2a
    classDef realtime fill:#a8e6cf,stroke:#3d8b61
    classDef voice fill:#ffd3b6,stroke:#ff8b3d
    classDef plugins fill:#ffaaa5,stroke:#ff5c5c
    classDef templates fill:#dcedc1,stroke:#a5c663
    classDef theme fill:#c7ceea,stroke:#6b7db3
    classDef webdav fill:#ff8b94,stroke:#e63946
    classDef upstash fill:#ff6b6b,stroke:#c92a2a
    classDef sw fill:#a8e6cf,stroke:#3d8b61

    %% Legend
    subgraph Legend
        L1["Client Components"]:::components
        L2["State Management"]:::store
        L3["API Integration"]:::apiclients
        L4["Security"]:::auth
        L5["External Services"]:::webdav
    end
```
