# w17ant/claude-office architecture

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

- Interactive diagram: https://gitdiagram.com/w17ant/claude-office
- Repository: https://github.com/w17ant/claude-office

## Overview

1. **What this repo is**
   Claude Office is a local, single-user “digital office” app: a React scene renderer plus a local event/chat backend that visualizes Claude Code agents as pixel-art coworkers in real time.

2. **Top-level runtime split**
   There are three main runtime pieces:
   - **Frontend**: Vite + React + TypeScript in `src/`
   - **Local server**: Express + WebSocket in `server/`
   - **Automation layer**: shell/Python scripts and Claude Code hooks in `hooks/` and `scripts/`
   Electron exists as an optional wrapper, not the primary runtime.

3. **Frontend responsibilities**
   `src/App.tsx` orchestrates the office scene: agent lifecycle, room state, chat panel, effects, and mode selection. Supporting modules break the scene into boundaries like agent state (`agentManager.ts`), events, interactions, rooms, daylight, sounds, theme, and shared types. UI rendering is composed from specialized components such as `Character`, `FurnitureRenderer`, `SpeechBubble`, `EffectBubble`, and `SlackChat`.

4. **Real-time agent event pipeline**
   Claude Code hooks are the source of truth for agent activity. `hooks/agent-tracker.sh` captures hook events like spawn/tool use/completion and forwards them to the local server. The server broadcasts those events over WebSocket, and the React app consumes them through `useAgentSocket.ts` to animate agents entering, moving, typing, taking breaks, and leaving.

5. **Server boundary and security**
   `server/index.js` is the local control plane: it exposes HTTP endpoints plus a WS channel, and it binds to `127.0.0.1` only. The event ingestion path requires a bearer token generated at startup, which keeps external processes from injecting office events. This is a localhost-only architecture designed for one operator’s machine.

6. **Chat subsystem**
   The office chat is separate from the visual event stream. `server/chat-db.js` provides SQLite-backed persistence for chat history, which survives restarts. The UI’s Slack-like panel (`SlackChat.tsx`) displays the conversation, slash commands, typing/read-state UI, and role-based replies.

7. **AI reply generation**
   `scripts/chat-ai-watcher.sh` and related helper scripts form the asynchronous reply loop. They watch for new chat activity, gather context (branch, recent messages, active agents), call the Claude CLI (`claude -p`), and write replies back through the local chat path. This keeps token usage and message generation outside the browser app.

8. **Simulation, video, and helper modes**
   The main app supports multiple operational modes via query params: live office, scripted simulation, recording/video mode, and a placement-helper mode for furniture positioning. That means the frontend can run against real hook events or against fabricated scripted data, which is important when drawing the architecture as a set of interchangeable event sources.

9. **Asset and rendering pipeline**
   Static art lives under `public/sprites/` and `public/rooms/`, while generated assets are produced by scripts like `generate-sprites.mjs`, `generate-office-bg.mjs`, `generate-walks.mjs`, and `extract-boss-sprite.py`. The frontend is therefore mostly a renderer over prebuilt sprite sheets and room layouts rather than a canvas game engine.

10. **Office customization and state**
   `office.config.example.json` defines configurable identity data such as the boss character name, sprite, color, and emoji. The README also describes persistent UI toggles like the Dunder Mifflin mode, which is stored client-side in `localStorage`. So some state is durable in SQLite, some is durable in browser storage, and some is ephemeral in the live event stream.

11. **Desktop packaging**
   `electron/main.cjs` is a thin optional desktop shell around the same web app. It does not appear to introduce a separate backend; instead it packages the local office experience into a desktop application when needed.

12. **Operational scripts and lifecycle**
   `scripts/start-office.sh` and `scripts/stop-office.sh` are the main lifecycle controls, likely starting the server, frontend, and chat watcher together. The repo is therefore organized around a local orchestration model: hooks inject events, the server brokers state, the watcher generates chat, and the browser/Electron client renders the office.

Main entry points: [`src/App.tsx`](https://github.com/w17ant/claude-office/blob/main/src/App.tsx) (Office App), [`server/index.js`](https://github.com/w17ant/claude-office/blob/main/server/index.js) (Local Server), [`src/components/Character.tsx`](https://github.com/w17ant/claude-office/blob/main/src/components/Character.tsx) (Scene UI), [`scripts/start-office.sh`](https://github.com/w17ant/claude-office/blob/main/scripts/start-office.sh) (Lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_app["Office App<br/>React orchestrator<br/>[App.tsx]"]
  node_agent_manager["Agent State<br/>state manager<br/>[agentManager.ts]"]
  node_events["Event Model<br/>event schema<br/>[events.ts]"]
  node_interactions["Interactions<br/>interaction logic<br/>[interactions.ts]"]
  node_rooms["Rooms<br/>layout data<br/>[rooms.ts]"]
  node_theme["Theme<br/>visual config<br/>[theme.ts]"]
  node_daylight["Daylight<br/>scene effect<br/>[daylight.ts]"]
  node_ui_shell["Scene UI<br/>component set<br/>[Character.tsx]"]
  node_chat_ui["Chat Panel<br/>UI component<br/>[SlackChat.tsx]"]
  node_socket_hook["Agent Socket<br/>ws client hook<br/>[useAgentSocket.ts]"]
end

subgraph group_backend["Local server"]
  node_server_main[("Local Server<br/>express/ws control plane<br/>[index.js]")]
  node_chat_db[("Chat DB<br/>sqlite persistence<br/>[chat-db.js]")]
end

subgraph group_automation["Automation"]
  node_agent_hook["Agent Tracker<br/>claude hook script<br/>[agent-tracker.sh]"]
  node_chat_watch["Chat Watcher<br/>reply loop<br/>[chat-ai-watcher.sh]"]
  node_chat_scripts["Chat Tools<br/>bridge scripts<br/>[chat-bridge.sh]"]
  node_lifecycle["Lifecycle<br/>startup scripts<br/>[start-office.sh]"]
end

subgraph group_assets["Assets"]
  node_sprites["Sprites<br/>art assets"]
  node_rooms_assets["Room Art<br/>background assets"]
  node_asset_gen["Asset Gen<br/>generation scripts"]
end

subgraph group_desktop["Desktop shell"]
  node_electron_shell["Electron Shell<br/>optional wrapper<br/>[main.cjs]"]
end

node_app -->|"owns state"| node_agent_manager
node_app -->|"uses schema"| node_events
node_app -->|"drives rules"| node_interactions
node_app -->|"loads layouts"| node_rooms
node_app -->|"applies theme"| node_theme
node_app -->|"renders lighting"| node_daylight
node_app -->|"composes UI"| node_ui_shell
node_app -->|"shows chat"| node_chat_ui
node_socket_hook -->|"ws updates"| node_server_main
node_agent_hook -->|"ingests events"| node_server_main
node_server_main -->|"broadcasts"| node_socket_hook
node_server_main -->|"persists chat"| node_chat_db
node_chat_ui -->|"reads history"| node_chat_db
node_chat_watch -->|"orchestrates"| node_chat_scripts
node_chat_scripts -->|"writes replies"| node_server_main
node_lifecycle -->|"starts server"| node_server_main
node_lifecycle -->|"starts watcher"| node_chat_watch
node_asset_gen -->|"builds art"| node_sprites
node_asset_gen -->|"builds rooms"| node_rooms_assets
node_ui_shell -->|"renders sprites"| node_sprites
node_ui_shell -->|"uses backdrops"| node_rooms_assets
node_electron_shell -->|"wraps UI"| node_app

click node_app "https://github.com/w17ant/claude-office/blob/main/src/App.tsx"
click node_agent_manager "https://github.com/w17ant/claude-office/blob/main/src/agentManager.ts"
click node_events "https://github.com/w17ant/claude-office/blob/main/src/events.ts"
click node_interactions "https://github.com/w17ant/claude-office/blob/main/src/interactions.ts"
click node_rooms "https://github.com/w17ant/claude-office/blob/main/src/rooms.ts"
click node_theme "https://github.com/w17ant/claude-office/blob/main/src/theme.ts"
click node_daylight "https://github.com/w17ant/claude-office/blob/main/src/daylight.ts"
click node_ui_shell "https://github.com/w17ant/claude-office/blob/main/src/components/Character.tsx"
click node_chat_ui "https://github.com/w17ant/claude-office/blob/main/src/components/SlackChat.tsx"
click node_socket_hook "https://github.com/w17ant/claude-office/blob/main/src/hooks/useAgentSocket.ts"
click node_server_main "https://github.com/w17ant/claude-office/blob/main/server/index.js"
click node_chat_db "https://github.com/w17ant/claude-office/blob/main/server/chat-db.js"
click node_agent_hook "https://github.com/w17ant/claude-office/blob/main/hooks/agent-tracker.sh"
click node_chat_watch "https://github.com/w17ant/claude-office/blob/main/scripts/chat-ai-watcher.sh"
click node_chat_scripts "https://github.com/w17ant/claude-office/blob/main/scripts/chat-bridge.sh"
click node_lifecycle "https://github.com/w17ant/claude-office/blob/main/scripts/start-office.sh"
click node_sprites "https://github.com/w17ant/claude-office/tree/main/public/sprites"
click node_rooms_assets "https://github.com/w17ant/claude-office/tree/main/public/rooms"
click node_asset_gen "https://github.com/w17ant/claude-office/blob/main/scripts/generate-sprites.mjs"
click node_electron_shell "https://github.com/w17ant/claude-office/blob/main/electron/main.cjs"

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_app,node_agent_manager,node_events,node_interactions,node_rooms,node_theme,node_daylight,node_ui_shell,node_chat_ui,node_socket_hook toneBlue
class node_server_main,node_chat_db toneAmber
class node_agent_hook,node_chat_watch,node_chat_scripts,node_lifecycle toneMint
class node_sprites,node_rooms_assets,node_asset_gen toneRose
class node_electron_shell toneIndigo
```

## Components

### Frontend

React/Vite office renderer and UI state

- [Office App](https://github.com/w17ant/claude-office/blob/main/src/App.tsx): React orchestrator · Main scene coordinator for office modes, agent lifecycle, room state, effects, and chat. · `src/App.tsx`
- [Agent State](https://github.com/w17ant/claude-office/blob/main/src/agentManager.ts): state manager · Tracks agents, lifecycle, positions, and office-facing state transitions. · `src/agentManager.ts`
- [Event Model](https://github.com/w17ant/claude-office/blob/main/src/events.ts): event schema · Shared event definitions for the office and agent activity pipeline. · `src/events.ts`
- [Interactions](https://github.com/w17ant/claude-office/blob/main/src/interactions.ts): interaction logic · Rules for agent movement, room interactions, and office behaviors. · `src/interactions.ts`
- [Rooms](https://github.com/w17ant/claude-office/blob/main/src/rooms.ts): layout data · Room definitions and spatial boundaries used by the renderer. · `src/rooms.ts`
- [Theme](https://github.com/w17ant/claude-office/blob/main/src/theme.ts): visual config · Shared theming and presentation settings for the office scene. · `src/theme.ts`
- [Daylight](https://github.com/w17ant/claude-office/blob/main/src/daylight.ts): scene effect · Light and time-of-day treatment for the rendered office. · `src/daylight.ts`
- [Scene UI](https://github.com/w17ant/claude-office/blob/main/src/components/Character.tsx): component set · Character, furniture, speech, and effect components that render the office. · `src/components/Character.tsx`
- [Chat Panel](https://github.com/w17ant/claude-office/blob/main/src/components/SlackChat.tsx): UI component · Slack-like office chat view with commands, presence, and replies. · `src/components/SlackChat.tsx`
- [Agent Socket](https://github.com/w17ant/claude-office/blob/main/src/hooks/useAgentSocket.ts): ws client hook · Consumes live agent updates from the local server and drives animation state. · `src/hooks/useAgentSocket.ts`

### Local server

Local HTTP, WebSocket, and chat persistence

- [Local Server](https://github.com/w17ant/claude-office/blob/main/server/index.js): express/ws control plane · Local HTTP and WebSocket server bound to localhost for office events and chat. · `server/index.js`
- [Chat DB](https://github.com/w17ant/claude-office/blob/main/server/chat-db.js): sqlite persistence · SQLite-backed storage for chat history across restarts. · `server/chat-db.js`

### Automation

Hooks and scripts that feed the office

- [Agent Tracker](https://github.com/w17ant/claude-office/blob/main/hooks/agent-tracker.sh): claude hook script · Captures Claude Code hook events and forwards agent lifecycle updates. · `hooks/agent-tracker.sh`
- [Chat Watcher](https://github.com/w17ant/claude-office/blob/main/scripts/chat-ai-watcher.sh): reply loop · Monitors chat activity and triggers asynchronous AI reply generation. · `scripts/chat-ai-watcher.sh`
- [Chat Tools](https://github.com/w17ant/claude-office/blob/main/scripts/chat-bridge.sh): bridge scripts · Helpers that gather context, poll, post, and reply through the local chat path. · `scripts/chat-bridge.sh`
- [Lifecycle](https://github.com/w17ant/claude-office/blob/main/scripts/start-office.sh): startup scripts · Starts and stops the office stack as a local single-user experience. · `scripts/start-office.sh`

### Assets

Static and generated art for the scene

- [Sprites](https://github.com/w17ant/claude-office/tree/main/public/sprites): art assets · Prebuilt character, furniture, effect, and office sprite sheets. · `public/sprites`
- [Room Art](https://github.com/w17ant/claude-office/tree/main/public/rooms): background assets · Static room backdrops and scene art used by the renderer. · `public/rooms`
- [Asset Gen](https://github.com/w17ant/claude-office/blob/main/scripts/generate-sprites.mjs): generation scripts · Scripts that build sprites, backgrounds, walks, and extracted character art. · `scripts/generate-sprites.mjs`

### Desktop shell

Optional Electron wrapper

- [Electron Shell](https://github.com/w17ant/claude-office/blob/main/electron/main.cjs): optional wrapper · Thin desktop packaging layer around the same local web app. · `electron/main.cjs`

## Connections

- Office App → Agent State: owns state · The app coordinates agent lifecycle and room state through the manager.
- Office App → Event Model: uses schema · Scene logic consumes shared event definitions.
- Office App → Interactions: drives rules · Interaction rules shape movement and office behavior.
- Office App → Rooms: loads layouts · The app renders room structure from shared layout data.
- Office App → Theme: applies theme · Presentation settings feed the scene renderer.
- Office App → Daylight: renders lighting · Time-of-day effects are layered into the office scene.
- Office App → Scene UI: composes UI · The main scene is assembled from specialized render components.
- Office App → Chat Panel: shows chat · The office app embeds the Slack-like chat panel.
- Agent Socket → Local Server: ws updates · The client listens to live agent broadcasts from the local server.
- Agent Tracker → Local Server: ingests events · Claude hook output is forwarded into the server event pipeline.
- Local Server → Agent Socket: broadcasts · Live office events are pushed to connected browser clients.
- Local Server → Chat DB: persists chat · Chat history is stored in SQLite for recovery after restarts.
- Chat Panel → Chat DB: reads history · The chat panel reflects persisted conversation state.
- Chat Watcher → Chat Tools: orchestrates · The watcher uses helper scripts to collect context and post replies.
- Chat Tools → Local Server: writes replies · Reply scripts send messages through the local chat path.
- Lifecycle → Local Server: starts server · Startup scripts bring up the local control plane.
- Lifecycle → Chat Watcher: starts watcher · The office lifecycle includes the asynchronous reply loop.
- Asset Gen → Sprites: builds art · Generated sprite sheets populate the renderer asset set.
- Asset Gen → Room Art: builds rooms · Background and room art are generated by helper scripts.
- Scene UI → Sprites: renders sprites · Scene components draw characters, furniture, and effects from sprite assets.
- Scene UI → Room Art: uses backdrops · Furniture and scene rendering rely on room art.
- Electron Shell → Office App: wraps UI · Electron packages the same front-end application as a desktop shell.
