# guhcostan/tilework architecture

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

- Interactive diagram: https://gitdiagram.com/guhcostan/tilework
- Repository: https://github.com/guhcostan/tilework

## Overview

Tilework is a self-hosted browser virtual office. A visitor joins through the web client, enters a shared map, moves and interacts with people and objects; the server maintains office state and sends updates, while proximity conversations and spotlight broadcasts use LiveKit. Administration, map editing, chat and persistent whiteboards extend that loop. The map separates client experience, realtime world, administration/storage and media. Evidence is limited to the supplied excerpts, source index and README; several backend connections are documented at product level rather than shown in sampled call sites.

Main entry points: [`web/src/session.ts`](https://github.com/guhcostan/tilework/blob/main/web/src/session.ts) (Office session), [`server/internal/httpapi/server.go`](https://github.com/guhcostan/tilework/blob/main/server/internal/httpapi/server.go) (HTTP and WebSocket API), [`web/src/game/WorldView.ts`](https://github.com/guhcostan/tilework/blob/main/web/src/game/WorldView.ts) (World renderer), [`web/src/ui/App.tsx`](https://github.com/guhcostan/tilework/blob/main/web/src/ui/App.tsx) (App and join)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser office"]
  node_app["App and join<br/>[App.tsx]"]
  node_session["Office session<br/>[session.ts]"]
  node_clientstate["Client state<br/>[store.ts]"]
  node_socket["Realtime socket<br/>[socket.ts]"]
  node_protocol["Wire protocol<br/>[protocol.ts]"]
  node_worldview["World renderer<br/>[WorldView.ts]"]
  node_mapmodel["Map model<br/>[mapModel.ts]"]
  node_avatar["Avatar art<br/>[avatars.ts]"]
  node_characterart["Character sprites<br/>[characters.ts]"]
  node_petart["Pet sprites<br/>[pets.ts]"]
  node_petfollow["Pet following<br/>[petFollow.ts]"]
  node_joinui["Join and profile<br/>[JoinScreen.tsx]"]
  node_officeui["Office interface<br/>[OfficeScreen.tsx]"]
  node_editor["Map editor<br/>[MapEditor.tsx]"]
end

subgraph group_world["Realtime world"]
  node_server["HTTP and WebSocket API<br/>[server.go]"]
  node_worldengine["World engine<br/>[world.go]"]
  node_features["World features<br/>[features.go]"]
  node_gamemap["Map model and defaults<br/>[map.go]"]
end

subgraph group_admin["Administration and state"]
  node_adminapi["Admin endpoints<br/>[admin.go]"]
  node_adminstore["Admin records<br/>[admin.go]"]
  node_store[("Persistent office state<br/>[store.go]")]
  node_boards["Shared whiteboards<br/>[board.go]"]
end

subgraph group_media["Live media"]
  node_livekit["LiveKit integration<br/>[livekit.go]"]
  node_mediareconcile["Media reconciliation<br/>[reconcile.go]"]
  node_mediamanager["Browser media<br/>[MediaManager.ts]"]
end

node_visitor(("Office visitor"))
node_livekitservice["LiveKit SFU"]

node_visitor -->|"joins office"| node_app
node_app -->|"routes to join"| node_joinui
node_app -->|"routes to office"| node_officeui
node_officeui -.->|"starts session"| node_session
node_joinui -->|"reads profile state"| node_clientstate
node_session -->|"sends and receives"| node_socket
node_session -->|"creates view"| node_worldview
node_session -->|"updates state"| node_clientstate
node_socket -->|"encodes messages"| node_protocol
node_worldview -->|"renders avatars"| node_avatar
node_avatar -->|"builds frames"| node_characterart
node_worldview -->|"uses map data"| node_mapmodel
node_worldview -->|"updates companions"| node_petfollow
node_petfollow -.->|"uses pet frames"| node_petart
node_editor -->|"submits edits"| node_session
node_editor -->|"uses map messages"| node_protocol
node_socket -.->|"exchanges realtime data"| node_server
node_server -.->|"dispatches world events"| node_worldengine
node_worldengine -.->|"handles world features"| node_features
node_worldengine -.->|"uses office map"| node_gamemap
node_adminapi -.->|"manages admin records"| node_adminstore
node_server -.->|"persists office data"| node_store
node_features -.->|"supports shared boards"| node_boards
node_server -.->|"serves admin actions"| node_adminapi
node_session -->|"controls calls"| node_mediamanager
node_mediamanager -->|"joins media room"| node_livekitservice
node_server -.->|"issues scoped access"| node_livekit
node_livekit -.->|"configures rooms"| node_livekitservice
node_mediareconcile -.->|"reconciles media"| node_livekit

click node_app "https://github.com/guhcostan/tilework/blob/main/web/src/ui/App.tsx"
click node_session "https://github.com/guhcostan/tilework/blob/main/web/src/session.ts"
click node_clientstate "https://github.com/guhcostan/tilework/blob/main/web/src/store.ts"
click node_socket "https://github.com/guhcostan/tilework/blob/main/web/src/net/socket.ts"
click node_protocol "https://github.com/guhcostan/tilework/blob/main/web/src/net/protocol.ts"
click node_worldview "https://github.com/guhcostan/tilework/blob/main/web/src/game/WorldView.ts"
click node_mapmodel "https://github.com/guhcostan/tilework/blob/main/web/src/game/mapModel.ts"
click node_avatar "https://github.com/guhcostan/tilework/blob/main/web/src/game/avatars.ts"
click node_characterart "https://github.com/guhcostan/tilework/blob/main/web/src/game/art/characters.ts"
click node_petart "https://github.com/guhcostan/tilework/blob/main/web/src/game/art/pets.ts"
click node_petfollow "https://github.com/guhcostan/tilework/blob/main/web/src/game/petFollow.ts"
click node_joinui "https://github.com/guhcostan/tilework/blob/main/web/src/ui/JoinScreen.tsx"
click node_officeui "https://github.com/guhcostan/tilework/blob/main/web/src/ui/OfficeScreen.tsx"
click node_editor "https://github.com/guhcostan/tilework/blob/main/web/src/ui/MapEditor.tsx"
click node_server "https://github.com/guhcostan/tilework/blob/main/server/internal/httpapi/server.go"
click node_worldengine "https://github.com/guhcostan/tilework/blob/main/server/internal/world/world.go"
click node_features "https://github.com/guhcostan/tilework/blob/main/server/internal/world/features.go"
click node_gamemap "https://github.com/guhcostan/tilework/blob/main/server/internal/gamemap/map.go"
click node_adminapi "https://github.com/guhcostan/tilework/blob/main/server/internal/httpapi/admin.go"
click node_adminstore "https://github.com/guhcostan/tilework/blob/main/server/internal/store/admin.go"
click node_store "https://github.com/guhcostan/tilework/blob/main/server/internal/store/store.go"
click node_boards "https://github.com/guhcostan/tilework/blob/main/server/internal/world/board.go"
click node_livekit "https://github.com/guhcostan/tilework/blob/main/server/internal/media/livekit.go"
click node_mediareconcile "https://github.com/guhcostan/tilework/blob/main/server/internal/media/reconcile.go"
click node_mediamanager "https://github.com/guhcostan/tilework/blob/main/web/src/media/MediaManager.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_app,node_session,node_clientstate,node_socket,node_protocol,node_worldview,node_mapmodel,node_avatar,node_characterart,node_petart,node_petfollow,node_joinui,node_officeui,node_editor toneBlue
class node_server,node_worldengine,node_features,node_gamemap toneAmber
class node_adminapi,node_adminstore,node_store,node_boards toneMint
class node_livekit,node_mediareconcile,node_mediamanager toneRose
class node_visitor,node_livekitservice toneIndigo
```

## Components

### Browser office

- [App and join](https://github.com/guhcostan/tilework/blob/main/web/src/ui/App.tsx): `web/src/ui/App.tsx`
- [Office session](https://github.com/guhcostan/tilework/blob/main/web/src/session.ts): `web/src/session.ts`
- [Client state](https://github.com/guhcostan/tilework/blob/main/web/src/store.ts): `web/src/store.ts`
- [Realtime socket](https://github.com/guhcostan/tilework/blob/main/web/src/net/socket.ts): `web/src/net/socket.ts`
- [Wire protocol](https://github.com/guhcostan/tilework/blob/main/web/src/net/protocol.ts): `web/src/net/protocol.ts`
- [World renderer](https://github.com/guhcostan/tilework/blob/main/web/src/game/WorldView.ts): `web/src/game/WorldView.ts`
- [Map model](https://github.com/guhcostan/tilework/blob/main/web/src/game/mapModel.ts): `web/src/game/mapModel.ts`
- [Avatar art](https://github.com/guhcostan/tilework/blob/main/web/src/game/avatars.ts): `web/src/game/avatars.ts`
- [Character sprites](https://github.com/guhcostan/tilework/blob/main/web/src/game/art/characters.ts): `web/src/game/art/characters.ts`
- [Pet sprites](https://github.com/guhcostan/tilework/blob/main/web/src/game/art/pets.ts): `web/src/game/art/pets.ts`
- [Pet following](https://github.com/guhcostan/tilework/blob/main/web/src/game/petFollow.ts): `web/src/game/petFollow.ts`
- [Join and profile](https://github.com/guhcostan/tilework/blob/main/web/src/ui/JoinScreen.tsx): `web/src/ui/JoinScreen.tsx`
- [Office interface](https://github.com/guhcostan/tilework/blob/main/web/src/ui/OfficeScreen.tsx): `web/src/ui/OfficeScreen.tsx`
- [Map editor](https://github.com/guhcostan/tilework/blob/main/web/src/ui/MapEditor.tsx): `web/src/ui/MapEditor.tsx`

### Realtime world

- [HTTP and WebSocket API](https://github.com/guhcostan/tilework/blob/main/server/internal/httpapi/server.go): `server/internal/httpapi/server.go`
- [World engine](https://github.com/guhcostan/tilework/blob/main/server/internal/world/world.go): `server/internal/world/world.go`
- [World features](https://github.com/guhcostan/tilework/blob/main/server/internal/world/features.go): `server/internal/world/features.go`
- [Map model and defaults](https://github.com/guhcostan/tilework/blob/main/server/internal/gamemap/map.go): `server/internal/gamemap/map.go`

### Administration and state

- [Admin endpoints](https://github.com/guhcostan/tilework/blob/main/server/internal/httpapi/admin.go): `server/internal/httpapi/admin.go`
- [Admin records](https://github.com/guhcostan/tilework/blob/main/server/internal/store/admin.go): `server/internal/store/admin.go`
- [Persistent office state](https://github.com/guhcostan/tilework/blob/main/server/internal/store/store.go): `server/internal/store/store.go`
- [Shared whiteboards](https://github.com/guhcostan/tilework/blob/main/server/internal/world/board.go): `server/internal/world/board.go`

### Live media

- [LiveKit integration](https://github.com/guhcostan/tilework/blob/main/server/internal/media/livekit.go): `server/internal/media/livekit.go`
- [Media reconciliation](https://github.com/guhcostan/tilework/blob/main/server/internal/media/reconcile.go): `server/internal/media/reconcile.go`
- [Browser media](https://github.com/guhcostan/tilework/blob/main/web/src/media/MediaManager.ts): `web/src/media/MediaManager.ts`

### Other components

- **Office visitor**
- **LiveKit SFU**

## Connections

- Office visitor → App and join: joins office (evidence: `README.md`)
- App and join → Join and profile: routes to join (evidence: `web/src/ui/App.tsx`)
- App and join → Office interface: routes to office (evidence: `web/src/ui/App.tsx`)
- Office interface → Office session: starts session
- Join and profile → Client state: reads profile state (evidence: `web/src/ui/JoinScreen.tsx`)
- Office session → Realtime socket: sends and receives (evidence: `web/src/session.ts`)
- Office session → World renderer: creates view (evidence: `web/src/session.ts`)
- Office session → Client state: updates state (evidence: `web/src/session.ts`)
- Realtime socket → Wire protocol: encodes messages (evidence: `web/src/net/socket.ts`)
- World renderer → Avatar art: renders avatars (evidence: `web/src/game/WorldView.ts`)
- Avatar art → Character sprites: builds frames (evidence: `web/src/game/avatars.ts`)
- World renderer → Map model: uses map data (evidence: `web/src/game/WorldView.ts`)
- World renderer → Pet following: updates companions (evidence: `web/src/game/WorldView.ts`)
- Pet following → Pet sprites: uses pet frames
- Map editor → Office session: submits edits (evidence: `web/src/ui/MapEditor.tsx`)
- Map editor → Wire protocol: uses map messages (evidence: `web/src/ui/MapEditor.tsx`)
- Realtime socket → HTTP and WebSocket API: exchanges realtime data
- HTTP and WebSocket API → World engine: dispatches world events
- World engine → World features: handles world features
- World engine → Map model and defaults: uses office map
- Admin endpoints → Admin records: manages admin records
- HTTP and WebSocket API → Persistent office state: persists office data
- World features → Shared whiteboards: supports shared boards
- HTTP and WebSocket API → Admin endpoints: serves admin actions
- Office session → Browser media: controls calls (evidence: `web/src/session.ts`)
- Browser media → LiveKit SFU: joins media room (evidence: `README.md`)
- HTTP and WebSocket API → LiveKit integration: issues scoped access
- LiveKit integration → LiveKit SFU: configures rooms
- Media reconciliation → LiveKit integration: reconciles media
