# zetaphor/pi-webui architecture

> Architecture diagram of the GitHub repository zetaphor/pi-webui, 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/zetaphor/pi-webui
- Repository: https://github.com/zetaphor/pi-webui

## Overview

Pi Web UI provides browser access to a Pi coding-agent session. The main workflow runs from user input in the Lit client, through the WebSocket server and typed protocol, to the agent session; responses and session state stream back to the browser. The server also supports session history and model selection, including LiteLLM model discovery. The excerpts show key handlers and calls, while some feature details come from the README; links based only on that documentation are identified as such by their evidence path.

Main entry points: [`server/index.ts`](https://github.com/zetaphor/pi-webui/blob/main/server/index.ts) (WebSocket server), [`client/main.ts`](https://github.com/zetaphor/pi-webui/blob/main/client/main.ts) (Pi Web UI), [`shared/protocol.ts`](https://github.com/zetaphor/pi-webui/blob/main/shared/protocol.ts) (WebSocket protocol)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser interface"]
  node_client["Pi Web UI<br/>[main.ts]"]
  node_ui_components["Pi UI components"]
end

subgraph group_transport["Realtime transport"]
  node_protocol["WebSocket protocol<br/>[protocol.ts]"]
  node_server["WebSocket server<br/>[index.ts]"]
end

subgraph group_runtime["Agent and models"]
  node_agent["Pi agent session<br/>[index.ts]"]
  node_sessions[("Session history<br/>[index.ts]")]
  node_model_catalog["Model catalog<br/>[index.ts]"]
end

node_user(("User"))
node_litellm["LiteLLM service"]
node_system_tools["System tools"]

node_user -->|"uses"| node_client
node_client -->|"renders with"| node_ui_components
node_client -->|"uses types"| node_protocol
node_server -->|"uses types"| node_protocol
node_client -->|"sends WebSocket messages"| node_server
node_server -->|"streams events and state"| node_client
node_server -->|"creates and controls"| node_agent
node_server -->|"lists and loads"| node_sessions
node_server -->|"fetches and merges"| node_model_catalog
node_model_catalog -->|"fetches models"| node_litellm
node_agent -->|"uses tools"| node_system_tools

click node_client "https://github.com/zetaphor/pi-webui/blob/main/client/main.ts"
click node_protocol "https://github.com/zetaphor/pi-webui/blob/main/shared/protocol.ts"
click node_server "https://github.com/zetaphor/pi-webui/blob/main/server/index.ts"
click node_agent "https://github.com/zetaphor/pi-webui/blob/main/server/index.ts"
click node_sessions "https://github.com/zetaphor/pi-webui/blob/main/server/index.ts"
click node_model_catalog "https://github.com/zetaphor/pi-webui/blob/main/server/index.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_client,node_ui_components,node_user toneBlue
class node_protocol,node_server toneAmber
class node_agent,node_sessions,node_model_catalog toneMint
class node_litellm,node_system_tools toneIndigo
```

## Components

### Browser interface

- [Pi Web UI](https://github.com/zetaphor/pi-webui/blob/main/client/main.ts): `client/main.ts`
- **Pi UI components**

### Realtime transport

- [WebSocket protocol](https://github.com/zetaphor/pi-webui/blob/main/shared/protocol.ts): `shared/protocol.ts`
- [WebSocket server](https://github.com/zetaphor/pi-webui/blob/main/server/index.ts): `server/index.ts`

### Agent and models

- [Pi agent session](https://github.com/zetaphor/pi-webui/blob/main/server/index.ts): `server/index.ts`
- [Session history](https://github.com/zetaphor/pi-webui/blob/main/server/index.ts): `server/index.ts`
- [Model catalog](https://github.com/zetaphor/pi-webui/blob/main/server/index.ts): `server/index.ts`

### Other components

- **User**
- **LiteLLM service**
- **System tools**

## Connections

- User → Pi Web UI: uses (evidence: `README.md`)
- Pi Web UI → Pi UI components: renders with (evidence: `client/main.ts`)
- Pi Web UI → WebSocket protocol: uses types (evidence: `client/main.ts`)
- WebSocket server → WebSocket protocol: uses types (evidence: `server/index.ts`)
- Pi Web UI → WebSocket server: sends WebSocket messages (evidence: `README.md`)
- WebSocket server → Pi Web UI: streams events and state (evidence: `README.md`)
- WebSocket server → Pi agent session: creates and controls (evidence: `server/index.ts`)
- WebSocket server → Session history: lists and loads (evidence: `server/index.ts`)
- WebSocket server → Model catalog: fetches and merges (evidence: `server/index.ts`)
- Model catalog → LiteLLM service: fetches models (evidence: `server/index.ts`)
- Pi agent session → System tools: uses tools (evidence: `README.md`)
