# chatgptnextweb/nextchat architecture

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

- Interactive diagram: https://gitdiagram.com/chatgptnextweb/nextchat
- Repository: https://github.com/chatgptnextweb/nextchat

## Overview

NextChat is a browser-first AI assistant for chatting with multiple hosted or self-hosted model providers. Its main workflow is conversation UI → chat state and prompt preparation → provider-specific client → API route and provider handler → model service, with responses streamed back into the conversation. The README also documents prompt templates, plugins/MCP, realtime chat, artifacts, image generation, and local browser storage. Some feature paths and their wiring are unsampled; those branches are included where documented, without asserting unverified calls.

Main entry points: [`app/store/chat.ts`](https://github.com/chatgptnextweb/nextchat/blob/main/app/store/chat.ts) (Chat state), [`app/client/api.ts`](https://github.com/chatgptnextweb/nextchat/blob/main/app/client/api.ts) (Client API), [`app/store/sync.ts`](https://github.com/chatgptnextweb/nextchat/blob/main/app/store/sync.ts) (Cloud sync), [`app/components/home.tsx`](https://github.com/chatgptnextweb/nextchat/blob/main/app/components/home.tsx) (Application home)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Chat experience"]
  node_home["Application home<br/>[home.tsx]"]
  node_chatui["Chat interface<br/>[chat.tsx]"]
end

subgraph group_conversation["Conversation state"]
  node_chatstore["Chat state<br/>[chat.ts]"]
  node_maskstore["Prompt templates<br/>[mask.ts]"]
end

subgraph group_models["Model access"]
  node_clientapi["Client API<br/>[api.ts]"]
  node_platforms["Provider clients"]
  node_router["Provider router<br/>[route.ts]"]
  node_providerhandlers["Provider handlers"]
end

subgraph group_capabilities["Assistant capabilities"]
  node_pluginstore["Plugin state<br/>[plugin.ts]"]
  node_mcpactions["MCP actions<br/>[actions.ts]"]
  node_realtime["Realtime chat<br/>[realtime-chat.tsx]"]
  node_artifacts["Artifacts<br/>[artifacts.tsx]"]
  node_imagegen["Image generation<br/>[sd.tsx]"]
end

subgraph group_persistence["Persistence and config"]
  node_modelconfig["Model configuration<br/>[server.ts]"]
  node_modelcatalog["Model catalog<br/>[model.ts]"]
  node_browserstorage[("Browser storage")]
  node_sync["Cloud sync<br/>[sync.ts]"]
  node_upstash["Upstash endpoint<br/>[route.ts]"]
  node_webdav["WebDAV endpoint<br/>[route.ts]"]
end

node_user(("User"))
node_modelservice{{"Model services"}}

node_user -->|"opens"| node_home
node_home -.->|"shows"| node_chatui
node_chatui -.->|"updates"| node_chatstore
node_chatstore -->|"requests"| node_clientapi
node_clientapi -->|"dispatches"| node_platforms
node_platforms -.->|"calls"| node_router
node_router -->|"dispatches"| node_providerhandlers
node_providerhandlers -.->|"forwards"| node_modelservice
node_modelconfig -->|"configures"| node_modelcatalog
node_clientapi -->|"reads"| node_modelconfig
node_chatstore -->|"persists"| node_browserstorage
node_chatstore -->|"uses"| node_maskstore
node_chatstore -->|"invokes"| node_mcpactions
node_user -.->|"uses"| node_realtime
node_user -.->|"views"| node_artifacts
node_user -.->|"creates images"| node_imagegen
node_chatstore -.->|"supports tools"| node_pluginstore
node_sync -.->|"syncs"| node_upstash
node_sync -.->|"syncs"| node_webdav

click node_home "https://github.com/chatgptnextweb/nextchat/blob/main/app/components/home.tsx"
click node_chatui "https://github.com/chatgptnextweb/nextchat/blob/main/app/components/chat.tsx"
click node_chatstore "https://github.com/chatgptnextweb/nextchat/blob/main/app/store/chat.ts"
click node_clientapi "https://github.com/chatgptnextweb/nextchat/blob/main/app/client/api.ts"
click node_platforms "https://github.com/chatgptnextweb/nextchat/tree/main/app/client/platforms"
click node_router "https://github.com/chatgptnextweb/nextchat/blob/main/app/api/%5Bprovider%5D/%5B...path%5D/route.ts"
click node_providerhandlers "https://github.com/chatgptnextweb/nextchat/tree/main/app/api"
click node_modelconfig "https://github.com/chatgptnextweb/nextchat/blob/main/app/config/server.ts"
click node_modelcatalog "https://github.com/chatgptnextweb/nextchat/blob/main/app/utils/model.ts"
click node_browserstorage "https://github.com/chatgptnextweb/nextchat/blob/main/app/utils/indexedDB-storage.ts"
click node_maskstore "https://github.com/chatgptnextweb/nextchat/blob/main/app/store/mask.ts"
click node_pluginstore "https://github.com/chatgptnextweb/nextchat/blob/main/app/store/plugin.ts"
click node_mcpactions "https://github.com/chatgptnextweb/nextchat/blob/main/app/mcp/actions.ts"
click node_realtime "https://github.com/chatgptnextweb/nextchat/blob/main/app/components/realtime-chat/realtime-chat.tsx"
click node_artifacts "https://github.com/chatgptnextweb/nextchat/blob/main/app/components/artifacts.tsx"
click node_imagegen "https://github.com/chatgptnextweb/nextchat/blob/main/app/components/sd/sd.tsx"
click node_sync "https://github.com/chatgptnextweb/nextchat/blob/main/app/store/sync.ts"
click node_upstash "https://github.com/chatgptnextweb/nextchat/blob/main/app/api/upstash/%5Baction%5D/%5B...key%5D/route.ts"
click node_webdav "https://github.com/chatgptnextweb/nextchat/blob/main/app/api/webdav/%5B...path%5D/route.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_home,node_chatui,node_user toneBlue
class node_chatstore,node_maskstore toneAmber
class node_clientapi,node_platforms,node_router,node_providerhandlers toneMint
class node_pluginstore,node_mcpactions,node_realtime,node_artifacts,node_imagegen toneRose
class node_modelconfig,node_modelcatalog,node_browserstorage,node_sync,node_upstash,node_webdav,node_modelservice toneIndigo
```

## Components

### Chat experience

- [Application home](https://github.com/chatgptnextweb/nextchat/blob/main/app/components/home.tsx): `app/components/home.tsx`
- [Chat interface](https://github.com/chatgptnextweb/nextchat/blob/main/app/components/chat.tsx): `app/components/chat.tsx`

### Conversation state

- [Chat state](https://github.com/chatgptnextweb/nextchat/blob/main/app/store/chat.ts): `app/store/chat.ts`
- [Prompt templates](https://github.com/chatgptnextweb/nextchat/blob/main/app/store/mask.ts): `app/store/mask.ts`

### Model access

- [Client API](https://github.com/chatgptnextweb/nextchat/blob/main/app/client/api.ts): `app/client/api.ts`
- [Provider clients](https://github.com/chatgptnextweb/nextchat/tree/main/app/client/platforms): `app/client/platforms`
- [Provider router](https://github.com/chatgptnextweb/nextchat/blob/main/app/api/%5Bprovider%5D/%5B...path%5D/route.ts): `app/api/[provider]/[...path]/route.ts`
- [Provider handlers](https://github.com/chatgptnextweb/nextchat/tree/main/app/api): `app/api`

### Assistant capabilities

- [Plugin state](https://github.com/chatgptnextweb/nextchat/blob/main/app/store/plugin.ts): `app/store/plugin.ts`
- [MCP actions](https://github.com/chatgptnextweb/nextchat/blob/main/app/mcp/actions.ts): `app/mcp/actions.ts`
- [Realtime chat](https://github.com/chatgptnextweb/nextchat/blob/main/app/components/realtime-chat/realtime-chat.tsx): `app/components/realtime-chat/realtime-chat.tsx`
- [Artifacts](https://github.com/chatgptnextweb/nextchat/blob/main/app/components/artifacts.tsx): `app/components/artifacts.tsx`
- [Image generation](https://github.com/chatgptnextweb/nextchat/blob/main/app/components/sd/sd.tsx): `app/components/sd/sd.tsx`

### Persistence and config

- [Model configuration](https://github.com/chatgptnextweb/nextchat/blob/main/app/config/server.ts): `app/config/server.ts`
- [Model catalog](https://github.com/chatgptnextweb/nextchat/blob/main/app/utils/model.ts): `app/utils/model.ts`
- [Browser storage](https://github.com/chatgptnextweb/nextchat/blob/main/app/utils/indexedDB-storage.ts): `app/utils/indexedDB-storage.ts`
- [Cloud sync](https://github.com/chatgptnextweb/nextchat/blob/main/app/store/sync.ts): `app/store/sync.ts`
- [Upstash endpoint](https://github.com/chatgptnextweb/nextchat/blob/main/app/api/upstash/%5Baction%5D/%5B...key%5D/route.ts): `app/api/upstash/[action]/[...key]/route.ts`
- [WebDAV endpoint](https://github.com/chatgptnextweb/nextchat/blob/main/app/api/webdav/%5B...path%5D/route.ts): `app/api/webdav/[...path]/route.ts`

### Other components

- **User**
- **Model services**

## Connections

- User → Application home: opens
- Application home → Chat interface: shows
- Chat interface → Chat state: updates
- Chat state → Client API: requests (evidence: `app/store/chat.ts`)
- Client API → Provider clients: dispatches (evidence: `app/client/api.ts`)
- Provider clients → Provider router: calls
- Provider router → Provider handlers: dispatches (evidence: `app/api/[provider]/[...path]/route.ts`)
- Provider handlers → Model services: forwards
- Model configuration → Model catalog: configures (evidence: `app/config/server.ts`)
- Client API → Model configuration: reads (evidence: `app/client/api.ts`)
- Chat state → Browser storage: persists (evidence: `app/store/chat.ts`)
- Chat state → Prompt templates: uses (evidence: `app/store/chat.ts`)
- Chat state → MCP actions: invokes (evidence: `app/store/chat.ts`)
- User → Realtime chat: uses
- User → Artifacts: views
- User → Image generation: creates images
- Chat state → Plugin state: supports tools
- Cloud sync → Upstash endpoint: syncs
- Cloud sync → WebDAV endpoint: syncs
