# victor-gabriel-barbosa/chatgpu architecture

> Architecture diagram of the GitHub repository victor-gabriel-barbosa/chatgpu, 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/victor-gabriel-barbosa/chatgpu
- Repository: https://github.com/victor-gabriel-barbosa/chatgpu

## Overview

ChatGPU is a browser-only conversational LLM: users select or download a model, send prompts through the React chat, and receive streamed local inference without a chat backend. The main control path runs from the page through session orchestration to local inference, while chat history persists in IndexedDB. The README documents model caching, WebGPU/WASM inference, streaming and generation controls; sampled source confirms the main UI, session, worker and storage relationships. Some inference details rely on README documentation because not all implementation files were sampled.

Main entry points: [`app/page.tsx`](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/app/page.tsx) (Chat page), [`hooks/use-session.ts`](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/hooks/use-session.ts) (Session orchestration), [`hooks/use-engine.ts`](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/hooks/use-engine.ts) (Engine lifecycle), [`lib/worker.ts`](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/lib/worker.ts) (Inference worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chat["Chat experience"]
  node_page["Chat page<br/>[page.tsx]"]
  node_session["Session orchestration<br/>[use-session.ts]"]
  node_filetext["File extraction<br/>[fileToText.ts]"]
end

subgraph group_inference["Local inference"]
  node_stream["Reply streaming"]
  node_engine["Engine lifecycle<br/>[use-engine.ts]"]
  node_worker["Inference worker<br/>[worker.ts]"]
  node_webllm["WebLLM runtime"]
  node_gpu["WebGPU / WASM"]
  node_modelui["Model manager"]
  node_modelcache["Model cache<br/>[use-model-cache.ts]"]
end

subgraph group_persistence["Browser data"]
  node_db[("Chat database<br/>[database.ts]")]
end

subgraph group_presentation["UI components"]
  node_sidebar["Conversation sidebar<br/>[app-sidebar.tsx]"]
  node_message["Message renderer<br/>[chat-message.tsx]"]
  node_code["Code renderer<br/>[code-block.tsx]"]
  node_settings["Chat settings<br/>[settings-modal.tsx]"]
end

node_user(("User"))

node_user -->|"sends prompts"| node_page
node_page -->|"manages chat"| node_session
node_page -->|"selects model"| node_engine
node_page -->|"renders messages"| node_message
node_page -->|"renders navigation"| node_sidebar
node_page -->|"opens manager"| node_modelui
node_page -->|"opens settings"| node_settings
node_session -->|"reads and writes"| node_db
node_session -->|"extracts attachments"| node_filetext
node_session -->|"starts generation"| node_stream
node_engine -->|"creates worker"| node_worker
node_worker -->|"runs model"| node_webllm
node_webllm -->|"infers locally"| node_gpu
node_modelui -->|"manages downloads"| node_modelcache
node_message -->|"renders code"| node_code

click node_page "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/app/page.tsx"
click node_session "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/hooks/use-session.ts"
click node_stream "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/lib/stream-assistant-reply.ts"
click node_engine "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/hooks/use-engine.ts"
click node_worker "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/lib/worker.ts"
click node_modelui "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/components/model-manager-modal.tsx"
click node_modelcache "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/hooks/use-model-cache.ts"
click node_db "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/db/database.ts"
click node_filetext "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/lib/fileToText.ts"
click node_sidebar "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/components/app-sidebar.tsx"
click node_message "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/components/chat-message.tsx"
click node_code "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/components/code-block.tsx"
click node_settings "https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/components/settings-modal.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_page,node_session,node_filetext,node_user toneBlue
class node_stream,node_engine,node_worker,node_webllm,node_gpu,node_modelui,node_modelcache toneAmber
class node_db toneMint
class node_sidebar,node_message,node_code,node_settings toneRose
```

## Components

### Chat experience

- [Chat page](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/app/page.tsx): `app/page.tsx`
- [Session orchestration](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/hooks/use-session.ts): `hooks/use-session.ts`
- [File extraction](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/lib/fileToText.ts): `lib/fileToText.ts`

### Local inference

- [Reply streaming](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/lib/stream-assistant-reply.ts): `lib/stream-assistant-reply.ts`
- [Engine lifecycle](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/hooks/use-engine.ts): `hooks/use-engine.ts`
- [Inference worker](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/lib/worker.ts): `lib/worker.ts`
- **WebLLM runtime**
- **WebGPU / WASM**
- [Model manager](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/components/model-manager-modal.tsx): `components/model-manager-modal.tsx`
- [Model cache](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/hooks/use-model-cache.ts): `hooks/use-model-cache.ts`

### Browser data

- [Chat database](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/db/database.ts): `db/database.ts`

### UI components

- [Conversation sidebar](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/components/app-sidebar.tsx): `components/app-sidebar.tsx`
- [Message renderer](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/components/chat-message.tsx): `components/chat-message.tsx`
- [Code renderer](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/components/code-block.tsx): `components/code-block.tsx`
- [Chat settings](https://github.com/victor-gabriel-barbosa/chatgpu/blob/main/components/settings-modal.tsx): `components/settings-modal.tsx`

### Other components

- **User**

## Connections

- User → Chat page: sends prompts
- Chat page → Session orchestration: manages chat (evidence: `app/page.tsx`)
- Chat page → Engine lifecycle: selects model (evidence: `app/page.tsx`)
- Chat page → Message renderer: renders messages (evidence: `app/page.tsx`)
- Chat page → Conversation sidebar: renders navigation (evidence: `app/page.tsx`)
- Chat page → Model manager: opens manager (evidence: `app/page.tsx`)
- Chat page → Chat settings: opens settings (evidence: `app/page.tsx`)
- Session orchestration → Chat database: reads and writes (evidence: `hooks/use-session.ts`)
- Session orchestration → File extraction: extracts attachments (evidence: `hooks/use-session.ts`)
- Session orchestration → Reply streaming: starts generation (evidence: `hooks/use-session.ts`)
- Engine lifecycle → Inference worker: creates worker (evidence: `hooks/use-engine.ts`)
- Inference worker → WebLLM runtime: runs model
- WebLLM runtime → WebGPU / WASM: infers locally
- Model manager → Model cache: manages downloads (evidence: `components/model-manager-modal.tsx`)
- Message renderer → Code renderer: renders code (evidence: `components/chat-message.tsx`)
