# riazmohamed/teechez architecture

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

- Interactive diagram: https://gitdiagram.com/riazmohamed/teechez
- Repository: https://github.com/riazmohamed/teechez

## Overview

Teechez is a live AI diagram canvas: users describe or revise a diagram in chat, the server streams model events and graph-tool results, and the client applies edits to a persistent graph rendered on the canvas. The graph layer validates and reduces patches and computes layouts; the UI also supports document management, attachments, research tools, and direct canvas edits. Edges reflect excerpts, source-index references, or README statements; unsampled implementation details and external service wiring are not inferred.

Main entry points: [`src/app/api/chat/route.ts`](https://github.com/riazmohamed/teechez/blob/main/src/app/api/chat/route.ts) (Chat API), [`src/components/Chat.tsx`](https://github.com/riazmohamed/teechez/blob/main/src/components/Chat.tsx) (Chat panel), [`src/lib/graph/store.ts`](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/store.ts) (Graph store), [`src/components/AppShell.tsx`](https://github.com/riazmohamed/teechez/blob/main/src/components/AppShell.tsx) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Canvas and Chat UI"]
  node_shell["App shell<br/>[AppShell.tsx]"]
  node_chat["Chat panel<br/>[Chat.tsx]"]
  node_canvas["Diagram canvas<br/>[Canvas.tsx]"]
  node_documents["Document menu<br/>[DocumentMenu.tsx]"]
end

subgraph group_graph["Diagram Graph"]
  node_graphstore[("Graph store<br/>[store.ts]")]
  node_patchqueue["Patch queue<br/>[patch-queue.ts]"]
  node_patchapply["Patch conversion<br/>[apply.ts]"]
  node_reducer["Graph reducer<br/>[reduce.ts]"]
  node_validator["Patch validation<br/>[validate.ts]"]
  node_tools["Graph tools<br/>[tools.ts]"]
  node_types["Graph model<br/>[types.ts]"]
end

subgraph group_server["Chat and Research"]
  node_client["Stream client<br/>[client.ts]"]
  node_route["Chat API<br/>[route.ts]"]
  node_attachments["Attachments<br/>[attachments.ts]"]
  node_fileextract["File extraction<br/>[file-extract.ts]"]
  node_auth["Shared auth<br/>[gg-auth.ts]"]
  node_research["Research tools<br/>[index.ts]"]
  node_websearch["Web search<br/>[web-search.ts]"]
  node_webfetch["Web fetch<br/>[web-fetch.ts]"]
end

subgraph group_layout["Layout Engine"]
  node_layoutuse["Layout hook<br/>[use-layout.ts]"]
  node_autolayout["Auto layout<br/>[auto-layout.ts]"]
  node_sequencelayout["Sequence layout<br/>[sequence-layout.ts]"]
  node_elklayout["ELK layout<br/>[elk-layout.ts]"]
  node_measurement["Graph measurement<br/>[measure.ts]"]
end

node_user(("Diagram author"))
node_externalweb(("Web sources"))

node_user -->|"uses"| node_shell
node_shell -->|"renders"| node_chat
node_shell -->|"renders"| node_canvas
node_shell -->|"renders"| node_documents
node_chat -->|"streams through"| node_client
node_client -->|"POSTs to"| node_route
node_chat -->|"queues edits"| node_patchqueue
node_chat -->|"reads and updates"| node_graphstore
node_chat -->|"encodes files"| node_attachments
node_canvas -->|"reads graph"| node_graphstore
node_documents -->|"manages documents"| node_graphstore
node_route -->|"loads credentials"| node_auth
node_route -->|"extracts text"| node_fileextract
node_route -->|"handles attachments"| node_attachments
node_route -->|"offers tools"| node_tools
node_route -->|"converts tool calls"| node_patchapply
node_route -->|"validates patches"| node_validator
node_route -->|"reduces patches"| node_reducer
node_route -->|"executes research"| node_research
node_research -->|"dispatches search"| node_websearch
node_research -->|"dispatches fetch"| node_webfetch
node_websearch -.->|"queries"| node_externalweb
node_webfetch -.->|"fetches pages"| node_externalweb
node_graphstore -->|"applies edits"| node_reducer
node_graphstore -->|"checks graph"| node_validator
node_patchapply -->|"maps tool calls"| node_tools
node_reducer -->|"uses model"| node_types
node_validator -->|"checks model"| node_types
node_canvas -->|"requests layout"| node_layoutuse
node_layoutuse -->|"computes layout"| node_autolayout
node_autolayout -->|"delegates sequence"| node_sequencelayout
node_autolayout -->|"uses engine"| node_elklayout
node_autolayout -->|"sizes nodes"| node_measurement
node_canvas -->|"measures labels"| node_measurement

click node_shell "https://github.com/riazmohamed/teechez/blob/main/src/components/AppShell.tsx"
click node_chat "https://github.com/riazmohamed/teechez/blob/main/src/components/Chat.tsx"
click node_canvas "https://github.com/riazmohamed/teechez/blob/main/src/components/Canvas.tsx"
click node_documents "https://github.com/riazmohamed/teechez/blob/main/src/components/DocumentMenu.tsx"
click node_graphstore "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/store.ts"
click node_patchqueue "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/patch-queue.ts"
click node_patchapply "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/apply.ts"
click node_reducer "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/reduce.ts"
click node_validator "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/validate.ts"
click node_tools "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/tools.ts"
click node_types "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/types.ts"
click node_client "https://github.com/riazmohamed/teechez/blob/main/src/lib/chat/client.ts"
click node_route "https://github.com/riazmohamed/teechez/blob/main/src/app/api/chat/route.ts"
click node_attachments "https://github.com/riazmohamed/teechez/blob/main/src/lib/chat/attachments.ts"
click node_fileextract "https://github.com/riazmohamed/teechez/blob/main/src/lib/chat/file-extract.ts"
click node_auth "https://github.com/riazmohamed/teechez/blob/main/src/server/gg-auth.ts"
click node_research "https://github.com/riazmohamed/teechez/blob/main/src/lib/research/index.ts"
click node_websearch "https://github.com/riazmohamed/teechez/blob/main/src/lib/research/web-search.ts"
click node_webfetch "https://github.com/riazmohamed/teechez/blob/main/src/lib/research/web-fetch.ts"
click node_layoutuse "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/use-layout.ts"
click node_autolayout "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/auto-layout.ts"
click node_sequencelayout "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/sequence-layout.ts"
click node_elklayout "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/elk-layout.ts"
click node_measurement "https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/measure.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_shell,node_chat,node_canvas,node_documents toneBlue
class node_graphstore,node_patchqueue,node_patchapply,node_reducer,node_validator,node_tools,node_types toneAmber
class node_client,node_route,node_attachments,node_fileextract,node_auth,node_research,node_websearch,node_webfetch toneMint
class node_layoutuse,node_autolayout,node_sequencelayout,node_elklayout,node_measurement toneRose
class node_user,node_externalweb toneIndigo
```

## Components

### Canvas and Chat UI

- [App shell](https://github.com/riazmohamed/teechez/blob/main/src/components/AppShell.tsx): `src/components/AppShell.tsx`
- [Chat panel](https://github.com/riazmohamed/teechez/blob/main/src/components/Chat.tsx): `src/components/Chat.tsx`
- [Diagram canvas](https://github.com/riazmohamed/teechez/blob/main/src/components/Canvas.tsx): `src/components/Canvas.tsx`
- [Document menu](https://github.com/riazmohamed/teechez/blob/main/src/components/DocumentMenu.tsx): `src/components/DocumentMenu.tsx`

### Diagram Graph

- [Graph store](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/store.ts): `src/lib/graph/store.ts`
- [Patch queue](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/patch-queue.ts): `src/lib/graph/patch-queue.ts`
- [Patch conversion](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/apply.ts): `src/lib/graph/apply.ts`
- [Graph reducer](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/reduce.ts): `src/lib/graph/reduce.ts`
- [Patch validation](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/validate.ts): `src/lib/graph/validate.ts`
- [Graph tools](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/tools.ts): `src/lib/graph/tools.ts`
- [Graph model](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/types.ts): `src/lib/graph/types.ts`

### Chat and Research

- [Stream client](https://github.com/riazmohamed/teechez/blob/main/src/lib/chat/client.ts): `src/lib/chat/client.ts`
- [Chat API](https://github.com/riazmohamed/teechez/blob/main/src/app/api/chat/route.ts): `src/app/api/chat/route.ts`
- [Attachments](https://github.com/riazmohamed/teechez/blob/main/src/lib/chat/attachments.ts): `src/lib/chat/attachments.ts`
- [File extraction](https://github.com/riazmohamed/teechez/blob/main/src/lib/chat/file-extract.ts): `src/lib/chat/file-extract.ts`
- [Shared auth](https://github.com/riazmohamed/teechez/blob/main/src/server/gg-auth.ts): `src/server/gg-auth.ts`
- [Research tools](https://github.com/riazmohamed/teechez/blob/main/src/lib/research/index.ts): `src/lib/research/index.ts`
- [Web search](https://github.com/riazmohamed/teechez/blob/main/src/lib/research/web-search.ts): `src/lib/research/web-search.ts`
- [Web fetch](https://github.com/riazmohamed/teechez/blob/main/src/lib/research/web-fetch.ts): `src/lib/research/web-fetch.ts`

### Layout Engine

- [Layout hook](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/use-layout.ts): `src/lib/graph/use-layout.ts`
- [Auto layout](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/auto-layout.ts): `src/lib/graph/auto-layout.ts`
- [Sequence layout](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/sequence-layout.ts): `src/lib/graph/sequence-layout.ts`
- [ELK layout](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/elk-layout.ts): `src/lib/graph/elk-layout.ts`
- [Graph measurement](https://github.com/riazmohamed/teechez/blob/main/src/lib/graph/measure.ts): `src/lib/graph/measure.ts`

### Other components

- **Diagram author**
- **Web sources**

## Connections

- Diagram author → App shell: uses (evidence: `README.md`)
- App shell → Chat panel: renders (evidence: `src/components/AppShell.tsx`)
- App shell → Diagram canvas: renders (evidence: `src/components/AppShell.tsx`)
- App shell → Document menu: renders (evidence: `src/components/AppShell.tsx`)
- Chat panel → Stream client: streams through (evidence: `src/components/Chat.tsx`)
- Stream client → Chat API: POSTs to (evidence: `src/lib/chat/client.ts`)
- Chat panel → Patch queue: queues edits (evidence: `src/components/Chat.tsx`)
- Chat panel → Graph store: reads and updates (evidence: `src/components/Chat.tsx`)
- Chat panel → Attachments: encodes files (evidence: `src/components/Chat.tsx`)
- Diagram canvas → Graph store: reads graph (evidence: `src/components/Canvas.tsx`)
- Document menu → Graph store: manages documents (evidence: `src/components/DocumentMenu.tsx`)
- Chat API → Shared auth: loads credentials (evidence: `src/app/api/chat/route.ts`)
- Chat API → File extraction: extracts text (evidence: `src/app/api/chat/route.ts`)
- Chat API → Attachments: handles attachments (evidence: `src/app/api/chat/route.ts`)
- Chat API → Graph tools: offers tools (evidence: `src/app/api/chat/route.ts`)
- Chat API → Patch conversion: converts tool calls (evidence: `src/app/api/chat/route.ts`)
- Chat API → Patch validation: validates patches (evidence: `src/app/api/chat/route.ts`)
- Chat API → Graph reducer: reduces patches (evidence: `src/app/api/chat/route.ts`)
- Chat API → Research tools: executes research (evidence: `src/app/api/chat/route.ts`)
- Research tools → Web search: dispatches search (evidence: `src/lib/research/index.ts`)
- Research tools → Web fetch: dispatches fetch (evidence: `src/lib/research/index.ts`)
- Web search → Web sources: queries
- Web fetch → Web sources: fetches pages
- Graph store → Graph reducer: applies edits (evidence: `src/lib/graph/store.ts`)
- Graph store → Patch validation: checks graph (evidence: `src/lib/graph/store.ts`)
- Patch conversion → Graph tools: maps tool calls (evidence: `src/lib/graph/apply.ts`)
- Graph reducer → Graph model: uses model (evidence: `src/lib/graph/reduce.ts`)
- Patch validation → Graph model: checks model (evidence: `src/lib/graph/validate.ts`)
- Diagram canvas → Layout hook: requests layout (evidence: `src/components/Canvas.tsx`)
- Layout hook → Auto layout: computes layout (evidence: `src/lib/graph/use-layout.ts`)
- Auto layout → Sequence layout: delegates sequence (evidence: `src/lib/graph/auto-layout.ts`)
- Auto layout → ELK layout: uses engine (evidence: `src/lib/graph/auto-layout.ts`)
- Auto layout → Graph measurement: sizes nodes (evidence: `src/lib/graph/auto-layout.ts`)
- Diagram canvas → Graph measurement: measures labels (evidence: `src/components/Canvas.tsx`)
