# bioshazard/just-pi architecture

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

- Interactive diagram: https://gitdiagram.com/bioshazard/just-pi
- Repository: https://github.com/bioshazard/just-pi

## Overview

#### Purpose and entry points
just-pi is a browser-native coding sandbox: users configure an OpenRouter key/model, prompt a Pi-based coding agent, run shell commands, and persist a workspace entirely in browser storage. Vite boots the React application from `index.html` through `src/main.tsx`, with `src/App.tsx` composing the IDE experience.

#### UI shell and interaction surfaces
The React shell provides setup, prompting, review, and file-workspace modes, including responsive mobile navigation. `src/App.tsx` owns top-level state and integration; `src/AssistantCommandBar.tsx` accepts either prompts or `!`-prefixed shell commands; `src/AssistantReviewPane.tsx` renders command and agent activity for review.

#### Agent-session boundary
`src/agent-session.ts` is the browser-side Pi agent runtime boundary. It assembles the agent loop, model/provider access, system context, tool surface, and streamed session events. `src/agent-session-ui.ts` adapts those events/state for the React layer, separating agent execution concerns from presentation.

#### Workspace persistence and tool consistency
`src/opfs.ts` implements the Origin Private File System workspace abstraction. Agent tools and interactive shell operations must act through this shared filesystem layer so edits persist across refreshes and both execution paths observe the same files. If present in that workspace, `AGENTS.md` contributes additional instructions to the agent prompt.

#### Command execution and attachments
`src/shell.ts` integrates just-bash with the OPFS-backed workspace, enabling `!` command-bar requests to execute against the same file state used by the agent. `src/assistant-attachments.ts` handles attachment/context preparation for assistant requests, forming the boundary between UI-provided artifacts and agent inputs.

#### Runtime, external service, and deployment
The client runs fully in a modern browser with OPFS support; no server runtime is indicated. OpenRouter is the external model API, with user-supplied BYOK credentials read from browser `localStorage`, not embedded in the build. React and Vite provide the UI/build runtime (`src/main.tsx`, `vite.config.ts`), while GitHub Pages deployment is automated by `.github/workflows/deploy-pages.yml`.

Main entry points: [`src/agent-session.ts`](https://github.com/bioshazard/just-pi/blob/master/src/agent-session.ts) (Pi agent session), [`src/App.tsx`](https://github.com/bioshazard/just-pi/blob/master/src/App.tsx) (IDE shell), [`src/AssistantCommandBar.tsx`](https://github.com/bioshazard/just-pi/blob/master/src/AssistantCommandBar.tsx) (Assistant command bar), [`index.html`](https://github.com/bioshazard/just-pi/blob/master/index.html) (HTML entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["React IDE"]
  node_main["React bootstrap<br/>UI entry<br/>[main.tsx]"]
  node_app["IDE shell<br/>React integration<br/>[App.tsx]"]
  node_commandbar["Assistant command bar<br/>prompt &amp; shell input"]
  node_review["Review pane<br/>activity UI"]
end

subgraph group_agent["Agent &amp; execution"]
  node_agentui["Agent UI adapter<br/>event/state adapter"]
  node_attachments["Attachment preparation<br/>agent input boundary"]
  node_session["Pi agent session<br/>agent runtime boundary<br/>[agent-session.ts]"]
  node_shell["Interactive shell<br/>just-bash integration<br/>[shell.ts]"]
end

subgraph group_storage["Browser persistence"]
  node_opfs[("OPFS workspace<br/>filesystem abstraction<br/>[opfs.ts]")]
  node_credentials[("BYOK credentials<br/>localStorage")]
end

subgraph group_delivery["Build &amp; delivery"]
  node_index["HTML entry<br/>entry document<br/>[index.html]"]
  node_vite["Vite build<br/>build tooling<br/>[vite.config.ts]"]
  node_pages["GitHub Pages deploy<br/>deployment workflow<br/>[deploy-pages.yml]"]
end

node_browser{{"Modern browser<br/>runtime"}}
node_openrouter{{"OpenRouter<br/>external model API"}}

node_browser -->|"loads"| node_index
node_index -->|"boots"| node_main
node_main -->|"renders"| node_app
node_app -->|"hosts"| node_commandbar
node_app -->|"hosts"| node_review
node_app -->|"binds"| node_agentui
node_commandbar -->|"prompt context"| node_attachments
node_attachments -->|"agent inputs"| node_session
node_commandbar -->|"! commands"| node_shell
node_agentui -->|"adapts events"| node_session
node_session -->|"streams activity"| node_review
node_session -->|"agent tools use"| node_opfs
node_shell -->|"reads and writes"| node_opfs
node_session -->|"reads key/model"| node_credentials
node_session -->|"model requests"| node_openrouter
node_vite -->|"builds"| node_index
node_pages -->|"deploys build"| node_vite
node_browser -->|"persists workspace"| node_opfs
node_browser -->|"stores settings"| node_credentials

click node_index "https://github.com/bioshazard/just-pi/blob/master/index.html"
click node_main "https://github.com/bioshazard/just-pi/blob/master/src/main.tsx"
click node_app "https://github.com/bioshazard/just-pi/blob/master/src/App.tsx"
click node_commandbar "https://github.com/bioshazard/just-pi/blob/master/src/AssistantCommandBar.tsx"
click node_review "https://github.com/bioshazard/just-pi/blob/master/src/AssistantReviewPane.tsx"
click node_agentui "https://github.com/bioshazard/just-pi/blob/master/src/agent-session-ui.ts"
click node_attachments "https://github.com/bioshazard/just-pi/blob/master/src/assistant-attachments.ts"
click node_session "https://github.com/bioshazard/just-pi/blob/master/src/agent-session.ts"
click node_shell "https://github.com/bioshazard/just-pi/blob/master/src/shell.ts"
click node_opfs "https://github.com/bioshazard/just-pi/blob/master/src/opfs.ts"
click node_vite "https://github.com/bioshazard/just-pi/blob/master/vite.config.ts"
click node_pages "https://github.com/bioshazard/just-pi/blob/master/.github/workflows/deploy-pages.yml"

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_main,node_app,node_commandbar,node_review toneBlue
class node_agentui,node_attachments,node_session,node_shell toneAmber
class node_opfs,node_credentials toneMint
class node_index,node_vite,node_pages toneRose
class node_browser,node_openrouter toneNeutral
```

## Components

### React IDE

- [React bootstrap](https://github.com/bioshazard/just-pi/blob/master/src/main.tsx): UI entry · `src/main.tsx`
- [IDE shell](https://github.com/bioshazard/just-pi/blob/master/src/App.tsx): React integration · Owns top-level modes, state, and integrations. · `src/App.tsx`
- [Assistant command bar](https://github.com/bioshazard/just-pi/blob/master/src/AssistantCommandBar.tsx): prompt & shell input · Routes prompts and !-prefixed commands. · `src/AssistantCommandBar.tsx`
- [Review pane](https://github.com/bioshazard/just-pi/blob/master/src/AssistantReviewPane.tsx): activity UI · Shows command and agent activity. · `src/AssistantReviewPane.tsx`

### Agent & execution

- [Agent UI adapter](https://github.com/bioshazard/just-pi/blob/master/src/agent-session-ui.ts): event/state adapter · Separates agent execution state from React presentation. · `src/agent-session-ui.ts`
- [Attachment preparation](https://github.com/bioshazard/just-pi/blob/master/src/assistant-attachments.ts): agent input boundary · Prepares UI artifacts and context for requests. · `src/assistant-attachments.ts`
- [Pi agent session](https://github.com/bioshazard/just-pi/blob/master/src/agent-session.ts): agent runtime boundary · Builds the agent loop, tools, context, provider access, and streamed events. · `src/agent-session.ts`
- [Interactive shell](https://github.com/bioshazard/just-pi/blob/master/src/shell.ts): just-bash integration · Executes command-bar shell requests against the workspace. · `src/shell.ts`

### Browser persistence

- [OPFS workspace](https://github.com/bioshazard/just-pi/blob/master/src/opfs.ts): filesystem abstraction · Shared persistent files; AGENTS.md can extend agent instructions. · `src/opfs.ts`
- **BYOK credentials**: localStorage · Stores user-supplied OpenRouter key and model.

### Build & delivery

- [HTML entry](https://github.com/bioshazard/just-pi/blob/master/index.html): entry document · `index.html`
- [Vite build](https://github.com/bioshazard/just-pi/blob/master/vite.config.ts): build tooling · `vite.config.ts`
- [GitHub Pages deploy](https://github.com/bioshazard/just-pi/blob/master/.github/workflows/deploy-pages.yml): deployment workflow · `.github/workflows/deploy-pages.yml`

### Other components

- **Modern browser**: runtime · Hosts the entire sandbox with OPFS support.
- **OpenRouter**: external model API

## Connections

- Modern browser → HTML entry: loads
- HTML entry → React bootstrap: boots
- React bootstrap → IDE shell: renders
- IDE shell → Assistant command bar: hosts
- IDE shell → Review pane: hosts
- IDE shell → Agent UI adapter: binds
- Assistant command bar → Attachment preparation: prompt context
- Attachment preparation → Pi agent session: agent inputs
- Assistant command bar → Interactive shell: ! commands
- Agent UI adapter → Pi agent session: adapts events
- Pi agent session → Review pane: streams activity
- Pi agent session → OPFS workspace: agent tools use
- Interactive shell → OPFS workspace: reads and writes
- Pi agent session → BYOK credentials: reads key/model
- Pi agent session → OpenRouter: model requests
- Vite build → HTML entry: builds
- GitHub Pages deploy → Vite build: deploys build
- Modern browser → OPFS workspace: persists workspace
- Modern browser → BYOK credentials: stores settings
