# chuanqisun/iter architecture

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

- Interactive diagram: https://gitdiagram.com/chuanqisun/iter
- Repository: https://github.com/chuanqisun/iter

## Overview

Iter is a browser-based Gen AI chat frontend for rapid prompt iteration. The main workflow is user input (including attachments or dictation), chat-tree orchestration to a selected provider, streamed response rendering, and Markdown preview with editable runnable artifacts. Settings manage provider connections and model parameters; storage supports saving and restoring chat history. The graph uses README and SOURCE INDEX relationships where available; unsampled implementation details are represented only when documented, and optional external integrations are marked dashed.

Main entry points: [`src/chat-tree/chat-tree.tsx`](https://github.com/chuanqisun/iter/blob/master/src/chat-tree/chat-tree.tsx) (Chat interface), [`src/workers/preview-worker.ts`](https://github.com/chuanqisun/iter/blob/master/src/workers/preview-worker.ts) (Markdown renderer), [`src/storage/auto-save-service.ts`](https://github.com/chuanqisun/iter/blob/master/src/storage/auto-save-service.ts) (Auto-save history), [`src/storage/restore-service.ts`](https://github.com/chuanqisun/iter/blob/master/src/storage/restore-service.ts) (History restore)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chat["Chat workflow"]
  node_chatapp["Chat interface<br/>[chat-tree.tsx]"]
  node_chatstate["Chat tree state<br/>[tree-store.ts]"]
end

subgraph group_models["Models and settings"]
  node_providerbase["Provider interface<br/>[base.ts]"]
  node_providerfactory["Provider selection<br/>[factory.ts]"]
  node_adapters["Provider adapters"]
  node_settings["Connection settings"]
  node_paramsync["Model parameters"]
end

subgraph group_content["Rendering and artifacts"]
  node_preview["Streaming preview"]
  node_workerproxy["Preview worker client<br/>[worker-proxy.ts]"]
  node_markdownworker["Markdown renderer<br/>[preview-worker.ts]"]
  node_artifacteditor["Artifact editor"]
  node_directives["Run directives<br/>[directives.ts]"]
end

subgraph group_state["Persistence and input"]
  node_attachments["Attachments<br/>[attachment.ts]"]
  node_voice["Speech input"]
  node_autosave["Auto-save history"]
  node_restore["History restore<br/>[restore-service.ts]"]
end

node_user(("User"))
node_api{{"Model APIs"}}
node_localstorage[("Browser storage")]

node_user -->|"sends input"| node_chatapp
node_chatapp -->|"updates tree"| node_chatstate
node_chatapp -->|"handles files"| node_attachments
node_chatapp -->|"uses dictation"| node_voice
node_chatapp -->|"requests chat"| node_providerbase
node_chatapp -->|"renders responses"| node_preview
node_chatapp -->|"saves history"| node_autosave
node_chatapp -->|"restores history"| node_restore
node_providerbase -.->|"selects adapter"| node_providerfactory
node_providerfactory -->|"creates provider"| node_adapters
node_adapters -->|"sends requests"| node_api
node_settings -->|"uses providers"| node_providerfactory
node_settings -.->|"syncs parameters"| node_paramsync
node_preview -->|"renders markdown"| node_workerproxy
node_workerproxy -->|"dispatches render"| node_markdownworker
node_markdownworker -.->|"emits artifact markup"| node_artifacteditor
node_markdownworker -.->|"supports runnable blocks"| node_directives
node_autosave -->|"reads tree"| node_chatstate
node_restore -->|"restores tree"| node_chatstate
node_autosave -.->|"stores history"| node_localstorage
node_restore -.->|"loads history"| node_localstorage

click node_chatapp "https://github.com/chuanqisun/iter/blob/master/src/chat-tree/chat-tree.tsx"
click node_chatstate "https://github.com/chuanqisun/iter/blob/master/src/chat-tree/tree-store.ts"
click node_attachments "https://github.com/chuanqisun/iter/blob/master/src/chat-tree/attachment.ts"
click node_voice "https://github.com/chuanqisun/iter/blob/master/src/voice/speech-recognition.ts"
click node_providerbase "https://github.com/chuanqisun/iter/blob/master/src/providers/base.ts"
click node_providerfactory "https://github.com/chuanqisun/iter/blob/master/src/providers/factory.ts"
click node_adapters "https://github.com/chuanqisun/iter/tree/master/src/providers"
click node_settings "https://github.com/chuanqisun/iter/blob/master/src/settings/settings-element.ts"
click node_paramsync "https://github.com/chuanqisun/iter/blob/master/src/settings/use-model-parameter-sync.ts"
click node_preview "https://github.com/chuanqisun/iter/blob/master/src/chat-tree/streaming-preview.tsx"
click node_workerproxy "https://github.com/chuanqisun/iter/blob/master/src/workers/worker-proxy.ts"
click node_markdownworker "https://github.com/chuanqisun/iter/blob/master/src/workers/preview-worker.ts"
click node_artifacteditor "https://github.com/chuanqisun/iter/blob/master/src/artifact/artifact-editor-element.ts"
click node_directives "https://github.com/chuanqisun/iter/blob/master/src/artifact/lib/directives.ts"
click node_autosave "https://github.com/chuanqisun/iter/blob/master/src/storage/auto-save-service.ts"
click node_restore "https://github.com/chuanqisun/iter/blob/master/src/storage/restore-service.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_chatapp,node_chatstate,node_user toneBlue
class node_providerbase,node_providerfactory,node_adapters,node_settings,node_paramsync,node_localstorage toneAmber
class node_preview,node_workerproxy,node_markdownworker,node_artifacteditor,node_directives,node_api toneMint
class node_attachments,node_voice,node_autosave,node_restore toneRose
```

## Components

### Chat workflow

- [Chat interface](https://github.com/chuanqisun/iter/blob/master/src/chat-tree/chat-tree.tsx): `src/chat-tree/chat-tree.tsx`
- [Chat tree state](https://github.com/chuanqisun/iter/blob/master/src/chat-tree/tree-store.ts): `src/chat-tree/tree-store.ts`

### Models and settings

- [Provider interface](https://github.com/chuanqisun/iter/blob/master/src/providers/base.ts): `src/providers/base.ts`
- [Provider selection](https://github.com/chuanqisun/iter/blob/master/src/providers/factory.ts): `src/providers/factory.ts`
- [Provider adapters](https://github.com/chuanqisun/iter/tree/master/src/providers): `src/providers`
- [Connection settings](https://github.com/chuanqisun/iter/blob/master/src/settings/settings-element.ts): `src/settings/settings-element.ts`
- [Model parameters](https://github.com/chuanqisun/iter/blob/master/src/settings/use-model-parameter-sync.ts): `src/settings/use-model-parameter-sync.ts`

### Rendering and artifacts

- [Streaming preview](https://github.com/chuanqisun/iter/blob/master/src/chat-tree/streaming-preview.tsx): `src/chat-tree/streaming-preview.tsx`
- [Preview worker client](https://github.com/chuanqisun/iter/blob/master/src/workers/worker-proxy.ts): `src/workers/worker-proxy.ts`
- [Markdown renderer](https://github.com/chuanqisun/iter/blob/master/src/workers/preview-worker.ts): `src/workers/preview-worker.ts`
- [Artifact editor](https://github.com/chuanqisun/iter/blob/master/src/artifact/artifact-editor-element.ts): `src/artifact/artifact-editor-element.ts`
- [Run directives](https://github.com/chuanqisun/iter/blob/master/src/artifact/lib/directives.ts): `src/artifact/lib/directives.ts`

### Persistence and input

- [Attachments](https://github.com/chuanqisun/iter/blob/master/src/chat-tree/attachment.ts): `src/chat-tree/attachment.ts`
- [Speech input](https://github.com/chuanqisun/iter/blob/master/src/voice/speech-recognition.ts): `src/voice/speech-recognition.ts`
- [Auto-save history](https://github.com/chuanqisun/iter/blob/master/src/storage/auto-save-service.ts): `src/storage/auto-save-service.ts`
- [History restore](https://github.com/chuanqisun/iter/blob/master/src/storage/restore-service.ts): `src/storage/restore-service.ts`

### Other components

- **User**
- **Model APIs**
- **Browser storage**

## Connections

- User → Chat interface: sends input
- Chat interface → Chat tree state: updates tree (evidence: `src/chat-tree/chat-tree.tsx`)
- Chat interface → Attachments: handles files (evidence: `src/chat-tree/chat-tree.tsx`)
- Chat interface → Speech input: uses dictation (evidence: `src/chat-tree/chat-tree.tsx`)
- Chat interface → Provider interface: requests chat (evidence: `src/chat-tree/chat-tree.tsx`)
- Chat interface → Streaming preview: renders responses (evidence: `src/chat-tree/chat-tree.tsx`)
- Chat interface → Auto-save history: saves history (evidence: `src/chat-tree/chat-tree.tsx`)
- Chat interface → History restore: restores history (evidence: `src/chat-tree/chat-tree.tsx`)
- Provider interface → Provider selection: selects adapter
- Provider selection → Provider adapters: creates provider
- Provider adapters → Model APIs: sends requests
- Connection settings → Provider selection: uses providers (evidence: `src/settings/settings-element.ts`)
- Connection settings → Model parameters: syncs parameters
- Streaming preview → Preview worker client: renders markdown (evidence: `src/chat-tree/streaming-preview.tsx`)
- Preview worker client → Markdown renderer: dispatches render (evidence: `src/workers/worker-proxy.ts`)
- Markdown renderer → Artifact editor: emits artifact markup
- Markdown renderer → Run directives: supports runnable blocks
- Auto-save history → Chat tree state: reads tree (evidence: `src/storage/auto-save-service.ts`)
- History restore → Chat tree state: restores tree (evidence: `src/storage/restore-service.ts`)
- Auto-save history → Browser storage: stores history
- History restore → Browser storage: loads history
