# sng2c/ai-turk architecture

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

- Interactive diagram: https://gitdiagram.com/sng2c/ai-turk
- Repository: https://github.com/sng2c/ai-turk

## Overview

AI Turk is a web interface for an LLM coding agent: users enter a command or choose a generated button, and the agent returns a streamed response and updated button grid. The server manages conversation sessions and backend processes, with pi or Claude Code as configurable engines; scheduling and persistent conversation state extend that workflow. The UI also supports conversation management, optional account login, push notifications, and workspace instructions. Edges follow the excerpts, SOURCE INDEX references, or README; unsampled route and storage details are not inferred.

Main entry points: [`src/App.tsx`](https://github.com/sng2c/ai-turk/blob/main/src/App.tsx) (Chat UI), [`session-core.ts`](https://github.com/sng2c/ai-turk/blob/main/session-core.ts) (Session core), [`server.ts`](https://github.com/sng2c/ai-turk/blob/main/server.ts) (HTTP server), [`backend.ts`](https://github.com/sng2c/ai-turk/blob/main/backend.ts) (Agent backends)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web interface"]
  node_webapp["Chat UI<br/>[App.tsx]"]
  node_conversation["Conversation drawer"]
  node_turk["Response parsing<br/>[turk.tsx]"]
  node_schema["Response schema<br/>[response-schema.ts]"]
  node_browserstore[("Browser storage<br/>[storage.ts]")]
  node_serviceworker["Push worker<br/>[sw.js]"]
end

subgraph group_server["Server runtime"]
  node_http["HTTP server<br/>[server.ts]"]
end

subgraph group_session["Agent sessions"]
  node_core["Session core<br/>[session-core.ts]"]
  node_backend["Agent backends<br/>[backend.ts]"]
  node_scheduler["Task scheduler<br/>[scheduler.ts]"]
  node_instructions["Agent instructions"]
  node_agentsmd["Instruction content<br/>[agents-md.ts]"]
end

subgraph group_identity["Identity and admin"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_useradmin["Account CLI<br/>[user-cli.ts]"]
end

node_user(("User"))
node_pi["pi CLI"]
node_claude["Claude Code CLI"]
node_anthropic["Anthropic-compatible API"]

node_user -->|"enters commands"| node_webapp
node_webapp -->|"parses responses"| node_turk
node_turk -->|"validates output"| node_schema
node_webapp -->|"loads drafts"| node_browserstore
node_webapp -->|"opens drawer"| node_conversation
node_conversation -->|"requests conversations"| node_http
node_webapp -.->|"streams agent interaction"| node_http
node_http -->|"creates session core"| node_core
node_http -->|"delegates authentication"| node_auth
node_useradmin -->|"manages accounts"| node_auth
node_core -->|"starts backend"| node_backend
node_core -->|"manages schedules"| node_scheduler
node_core -->|"loads instructions"| node_instructions
node_instructions -->|"uses shared content"| node_agentsmd
node_backend -.->|"launches when selected"| node_pi
node_backend -.->|"launches when selected"| node_claude
node_claude -.->|"sends API requests"| node_anthropic
node_webapp -->|"registers for push"| node_serviceworker

click node_webapp "https://github.com/sng2c/ai-turk/blob/main/src/App.tsx"
click node_conversation "https://github.com/sng2c/ai-turk/blob/main/src/components/ConversationDrawer.tsx"
click node_turk "https://github.com/sng2c/ai-turk/blob/main/src/lib/turk.tsx"
click node_schema "https://github.com/sng2c/ai-turk/blob/main/src/lib/response-schema.ts"
click node_browserstore "https://github.com/sng2c/ai-turk/blob/main/src/lib/storage.ts"
click node_serviceworker "https://github.com/sng2c/ai-turk/blob/main/public/sw.js"
click node_http "https://github.com/sng2c/ai-turk/blob/main/server.ts"
click node_auth "https://github.com/sng2c/ai-turk/blob/main/auth.ts"
click node_useradmin "https://github.com/sng2c/ai-turk/blob/main/user-cli.ts"
click node_core "https://github.com/sng2c/ai-turk/blob/main/session-core.ts"
click node_backend "https://github.com/sng2c/ai-turk/blob/main/backend.ts"
click node_scheduler "https://github.com/sng2c/ai-turk/blob/main/scheduler.ts"
click node_instructions "https://github.com/sng2c/ai-turk/blob/main/src/lib/agents-md-server.ts"
click node_agentsmd "https://github.com/sng2c/ai-turk/blob/main/src/lib/agents-md.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_webapp,node_conversation,node_turk,node_schema,node_browserstore,node_serviceworker,node_user toneBlue
class node_http toneAmber
class node_core,node_backend,node_scheduler,node_instructions,node_agentsmd,node_anthropic toneMint
class node_auth,node_useradmin toneRose
class node_pi,node_claude toneIndigo
```

## Components

### Web interface

- [Chat UI](https://github.com/sng2c/ai-turk/blob/main/src/App.tsx): `src/App.tsx`
- [Conversation drawer](https://github.com/sng2c/ai-turk/blob/main/src/components/ConversationDrawer.tsx): `src/components/ConversationDrawer.tsx`
- [Response parsing](https://github.com/sng2c/ai-turk/blob/main/src/lib/turk.tsx): `src/lib/turk.tsx`
- [Response schema](https://github.com/sng2c/ai-turk/blob/main/src/lib/response-schema.ts): `src/lib/response-schema.ts`
- [Browser storage](https://github.com/sng2c/ai-turk/blob/main/src/lib/storage.ts): `src/lib/storage.ts`
- [Push worker](https://github.com/sng2c/ai-turk/blob/main/public/sw.js): `public/sw.js`

### Server runtime

- [HTTP server](https://github.com/sng2c/ai-turk/blob/main/server.ts): `server.ts`

### Agent sessions

- [Session core](https://github.com/sng2c/ai-turk/blob/main/session-core.ts): `session-core.ts`
- [Agent backends](https://github.com/sng2c/ai-turk/blob/main/backend.ts): `backend.ts`
- [Task scheduler](https://github.com/sng2c/ai-turk/blob/main/scheduler.ts): `scheduler.ts`
- [Agent instructions](https://github.com/sng2c/ai-turk/blob/main/src/lib/agents-md-server.ts): `src/lib/agents-md-server.ts`
- [Instruction content](https://github.com/sng2c/ai-turk/blob/main/src/lib/agents-md.ts): `src/lib/agents-md.ts`

### Identity and admin

- [Authentication](https://github.com/sng2c/ai-turk/blob/main/auth.ts): `auth.ts`
- [Account CLI](https://github.com/sng2c/ai-turk/blob/main/user-cli.ts): `user-cli.ts`

### Other components

- **User**
- **pi CLI**
- **Claude Code CLI**
- **Anthropic-compatible API**

## Connections

- User → Chat UI: enters commands
- Chat UI → Response parsing: parses responses (evidence: `src/App.tsx`)
- Response parsing → Response schema: validates output (evidence: `src/lib/turk.tsx`)
- Chat UI → Browser storage: loads drafts (evidence: `src/App.tsx`)
- Chat UI → Conversation drawer: opens drawer (evidence: `src/App.tsx`)
- Conversation drawer → HTTP server: requests conversations (evidence: `src/components/ConversationDrawer.tsx`)
- Chat UI → HTTP server: streams agent interaction
- HTTP server → Session core: creates session core (evidence: `server.ts`)
- HTTP server → Authentication: delegates authentication (evidence: `server.ts`)
- Account CLI → Authentication: manages accounts (evidence: `user-cli.ts`)
- Session core → Agent backends: starts backend (evidence: `session-core.ts`)
- Session core → Task scheduler: manages schedules (evidence: `session-core.ts`)
- Session core → Agent instructions: loads instructions (evidence: `session-core.ts`)
- Agent instructions → Instruction content: uses shared content (evidence: `src/lib/agents-md-server.ts`)
- Agent backends → pi CLI: launches when selected
- Agent backends → Claude Code CLI: launches when selected
- Claude Code CLI → Anthropic-compatible API: sends API requests
- Chat UI → Push worker: registers for push
