# broduoliviercontact-web/collab-hub-web-monitor architecture

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

- Interactive diagram: https://gitdiagram.com/broduoliviercontact-web/collab-hub-web-monitor
- Repository: https://github.com/broduoliviercontact-web/collab-hub-web-monitor

## Overview

#### Purpose and entry points
Collab-Hub Web Monitor is a Vite/vanilla-JS application that displays live music metadata from Max/MSP through Collab-Hub, with optional LiveKit direct audio. Public entry points are `index.html` → `src/main.js` and `src/publicPage.js`; the performer route is `control-room.html` → `src/control-room/controlRoomPage.js`. The Max publisher patch is `max/CollabHub_Web_Text_Sender.maxpat`.

#### Public metadata pipeline
The public runtime connects directly from the browser to the Collab-Hub Socket.IO `/hub` namespace. `src/collabHub/socketClient.js` owns connection/auth fallback and subscriptions; `src/collabHub/observeGuard.js` prevents duplicate observation per socket identity; `src/collabHub/messageRouter.js` normalizes delivered controls and separates known content headers from heartbeat/technical headers.

Routed metadata updates `src/state/soundState.js`, is restored/persisted locally through `src/state/persist.js`, then renders through `src/ui/renderSoundInfo.js` and `src/ui/renderConnectionStatus.js`. This is a browser-to-Collab-Hub boundary: Vercel does not proxy the real-time connection.

#### Freshness, stream state, and public UI
`src/state/freshness.js` tracks distinct server connectivity, Max heartbeat activity, and age of displayed content. `src/state/streamStatus.js` holds public audio-stream presence, level, peak, and listener-count data received from Collab-Hub. Public composition is split into additive runtimes under `src/public/`, notably `src/public/publicContentRuntime.js`, `src/public/publicStreamRuntime.js`, and `src/public/publicListenerRuntime.js`.

The public page can remain useful while disconnected because metadata persists only in browser `localStorage`; heartbeat state intentionally does not persist. Untrusted text and links are rendered safely without interpreted HTML.

#### Live audio: listener and performer paths
The public listener is dynamically enabled through `src/livekit/livekitListener.js` and UI modules in `src/listener/`. It obtains a short-lived listener token, joins LiveKit, subscribes to audio, and controls playback/volume via `src/listener/listenerAudioElement.js`.

The performer Control Room reuses a local Web Audio capture and processing engine: `src/audio/audioEngine.js`, `src/audio/audioCapture.js`, and `src/audio/audioGraph.js`. `src/audio/livekitPublisher.js` publishes the captured `MediaStream` to LiveKit. The Control Room coordinates capture, metering, publishing, and lifecycle in `src/control-room/controlRoomRuntime.js` and `src/control-room/controlRoomController.js`. It also publishes non-secret on-air, level, and listener-count presence back to Collab-Hub via `src/control-room/streamPresencePublisher.js`.

#### Serverless security boundary
Vercel API functions are the only server-side trust boundary. `api/livekit/token.js` issues role-scoped LiveKit tokens using server-only LiveKit credentials and performer authorization. Control Room login/session endpoints are `api/control-room/login.js`, `api/control-room/session.js`, and `api/control-room/logout.js`; signing and cookie logic reside in `src/server/controlRoomSession.js` and HTTP helpers in `src/server/http.js`.

Browser bundles must never receive LiveKit API secrets, performer password, or control-room session secret. The Control Room gate loads before the LiveKit runtime through `src/control-room/controlRoomGatePage.js`.

#### Diagnostics and operations
A gated, dynamically loaded diagnostics surface is implemented by `src/diagnostic/debugGate.js` and `src/diagnostic/diagnosticPanel.js`. It consumes runtime health, bounded event history, and sanitized exports from `src/diagnostic/systemHealth.js`, `src/diagnostic/boundedEventLog.js`, and `src/diagnostic/diagnosticSanitizer.js`. Diagnostic output redacts secrets and listener identities.

Deployment is static Vite output configured by `vercel.json`; GitHub Actions CI is defined in `.github/workflows/ci.yml`. External services are Collab-Hub (`server.collab-hub.io`), LiveKit Cloud, and Vercel serverless/static hosting.

Main entry points: [`src/publicPage.js`](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/publicPage.js) (Public page composition), [`src/collabHub/messageRouter.js`](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/collabHub/messageRouter.js) (Metadata router), [`src/collabHub/socketClient.js`](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/collabHub/socketClient.js) (Collab-Hub socket client), [`api/livekit/token.js`](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/api/livekit/token.js) (LiveKit token API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public browser"]
  node_public_entry["Public page entry<br/>Vite entry<br/>[main.js]"]
  node_public_page["Public page composition<br/>page runtime<br/>[publicPage.js]"]
  node_socket_client["Collab-Hub socket client<br/>Socket.IO client<br/>[socketClient.js]"]
  node_observation_guard["Observation guard<br/>subscription guard<br/>[observeGuard.js]"]
  node_message_router["Metadata router<br/>message normalization<br/>[messageRouter.js]"]
  node_sound_state[("Sound state and persistence<br/>browser state<br/>[soundState.js]")]
  node_freshness["Freshness state<br/>runtime health state<br/>[freshness.js]"]
  node_stream_state["Stream status<br/>audio presence state<br/>[streamStatus.js]"]
  node_public_ui["Public UI runtimes<br/>rendering runtime"]
  node_listener["LiveKit listener<br/>audio subscriber<br/>[livekitListener.js]"]
  node_diagnostics["Gated diagnostics<br/>diagnostic surface<br/>[debugGate.js]"]
end

subgraph group_performer["Control Room"]
  node_control_entry["Control Room entry<br/>performer page<br/>[controlRoomPage.js]"]
  node_control_gate["Control Room gate<br/>session gate"]
  node_control_runtime["Control Room runtime<br/>capture coordinator"]
  node_audio_engine["Audio capture engine<br/>Web Audio pipeline<br/>[audioEngine.js]"]
  node_livekit_publisher["LiveKit publisher<br/>audio publisher"]
  node_presence_publisher["Stream presence publisher<br/>Collab-Hub publisher"]
end

subgraph group_server["Vercel trust boundary"]
  node_token_api{{"LiveKit token API<br/>serverless token issuer<br/>[token.js]"}}
  node_session_api{{"Control Room session API<br/>serverless auth endpoints<br/>[login.js]"}}
  node_session_security["Session signing<br/>server session logic"]
end

subgraph group_external["External systems"]
  node_max_publisher["Max metadata publisher<br/>Max/MSP patch"]
  node_collab_hub["Collab-Hub<br/>realtime service"]
  node_livekit["LiveKit Cloud<br/>audio service"]
  node_vercel{{"Vercel<br/>static and serverless host<br/>[vercel.json]"}}
end

node_public_entry -->|"boots"| node_public_page
node_public_page -->|"starts"| node_socket_client
node_socket_client -->|"guards subscriptions"| node_observation_guard
node_observation_guard -->|"observes /hub"| node_collab_hub
node_collab_hub -->|"delivers controls"| node_socket_client
node_socket_client -->|"routes messages"| node_message_router
node_message_router -->|"content updates"| node_sound_state
node_message_router -->|"heartbeat activity"| node_freshness
node_message_router -->|"stream presence"| node_stream_state
node_sound_state -->|"renders metadata"| node_public_ui
node_freshness -->|"renders status"| node_public_ui
node_stream_state -->|"renders stream UI"| node_public_ui
node_public_page -.->|"enables on demand"| node_listener
node_listener -->|"requests listener token"| node_token_api
node_token_api -->|"signs access"| node_livekit
node_listener -->|"subscribes audio"| node_livekit
node_control_entry -->|"loads first"| node_control_gate
node_control_gate -->|"checks session"| node_session_api
node_session_api -->|"signs cookies"| node_session_security
node_control_gate -->|"authorizes"| node_control_runtime
node_control_runtime -->|"captures audio"| node_audio_engine
node_audio_engine -->|"MediaStream"| node_livekit_publisher
node_livekit_publisher -->|"requests performer token"| node_token_api
node_livekit_publisher -->|"publishes audio"| node_livekit
node_control_runtime -->|"reports state"| node_presence_publisher
node_presence_publisher -->|"publishes presence"| node_collab_hub
node_max_publisher -->|"publishes metadata"| node_collab_hub
node_public_page -.->|"loads when gated"| node_diagnostics
node_vercel -->|"hosts static app"| node_public_entry
node_vercel -->|"runs function"| node_token_api

click node_public_entry "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/main.js"
click node_public_page "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/publicPage.js"
click node_socket_client "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/collabHub/socketClient.js"
click node_observation_guard "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/collabHub/observeGuard.js"
click node_message_router "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/collabHub/messageRouter.js"
click node_sound_state "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/state/soundState.js"
click node_freshness "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/state/freshness.js"
click node_stream_state "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/state/streamStatus.js"
click node_public_ui "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/public/publicContentRuntime.js"
click node_listener "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/livekit/livekitListener.js"
click node_control_entry "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/control-room/controlRoomPage.js"
click node_control_gate "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/control-room/controlRoomGatePage.js"
click node_control_runtime "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/control-room/controlRoomRuntime.js"
click node_audio_engine "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/audio/audioEngine.js"
click node_livekit_publisher "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/audio/livekitPublisher.js"
click node_presence_publisher "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/control-room/streamPresencePublisher.js"
click node_token_api "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/api/livekit/token.js"
click node_session_api "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/api/control-room/login.js"
click node_session_security "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/server/controlRoomSession.js"
click node_diagnostics "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/diagnostic/debugGate.js"
click node_max_publisher "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/max/CollabHub_Web_Text_Sender.maxpat"
click node_vercel "https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/vercel.json"

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_public_entry,node_public_page,node_socket_client,node_observation_guard,node_message_router,node_sound_state,node_freshness,node_stream_state,node_public_ui,node_listener,node_diagnostics toneBlue
class node_control_entry,node_control_gate,node_control_runtime,node_audio_engine,node_livekit_publisher,node_presence_publisher toneAmber
class node_token_api,node_session_api,node_session_security toneMint
class node_max_publisher,node_collab_hub,node_livekit,node_vercel toneRose
```

## Components

### Public browser

Persistent metadata and optional listener audio.

- [Public page entry](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/main.js): Vite entry · `src/main.js`
- [Public page composition](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/publicPage.js): page runtime · `src/publicPage.js`
- [Collab-Hub socket client](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/collabHub/socketClient.js): Socket.IO client · Connects directly to the /hub namespace. · `src/collabHub/socketClient.js`
- [Observation guard](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/collabHub/observeGuard.js): subscription guard · Prevents duplicate observation for a socket identity. · `src/collabHub/observeGuard.js`
- [Metadata router](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/collabHub/messageRouter.js): message normalization · `src/collabHub/messageRouter.js`
- [Sound state and persistence](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/state/soundState.js): browser state · Metadata is retained in localStorage for disconnected use. · `src/state/soundState.js`
- [Freshness state](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/state/freshness.js): runtime health state · Separates server, Max heartbeat, and content age. · `src/state/freshness.js`
- [Stream status](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/state/streamStatus.js): audio presence state · `src/state/streamStatus.js`
- [Public UI runtimes](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/public/publicContentRuntime.js): rendering runtime · Renders safe metadata, connection, stream, and listener UI. · `src/public/publicContentRuntime.js`
- [LiveKit listener](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/livekit/livekitListener.js): audio subscriber · Obtains a listener token and subscribes to audio. · `src/livekit/livekitListener.js`
- [Gated diagnostics](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/diagnostic/debugGate.js): diagnostic surface · Sanitizes health and bounded event exports. · `src/diagnostic/debugGate.js`

### Control Room

Performer capture, publishing, and presence.

- [Control Room entry](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/control-room/controlRoomPage.js): performer page · `src/control-room/controlRoomPage.js`
- [Control Room gate](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/control-room/controlRoomGatePage.js): session gate · Loads before the LiveKit runtime. · `src/control-room/controlRoomGatePage.js`
- [Control Room runtime](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/control-room/controlRoomRuntime.js): capture coordinator · Coordinates capture, metering, publishing, and lifecycle. · `src/control-room/controlRoomRuntime.js`
- [Audio capture engine](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/audio/audioEngine.js): Web Audio pipeline · Captures and processes the local performer stream. · `src/audio/audioEngine.js`
- [LiveKit publisher](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/audio/livekitPublisher.js): audio publisher · Publishes the captured MediaStream. · `src/audio/livekitPublisher.js`
- [Stream presence publisher](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/control-room/streamPresencePublisher.js): Collab-Hub publisher · Publishes non-secret on-air, level, and listener presence. · `src/control-room/streamPresencePublisher.js`

### Vercel trust boundary

Server-only authorization and token issuance.

- [LiveKit token API](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/api/livekit/token.js): serverless token issuer · Issues role-scoped tokens with server-only credentials. · `api/livekit/token.js`
- [Control Room session API](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/api/control-room/login.js): serverless auth endpoints · Login, session, and logout endpoints. · `api/control-room/login.js`
- [Session signing](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/src/server/controlRoomSession.js): server session logic · Signs and validates Control Room cookies. · `src/server/controlRoomSession.js`

### External systems

- [Max metadata publisher](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/max/CollabHub_Web_Text_Sender.maxpat): Max/MSP patch · `max/CollabHub_Web_Text_Sender.maxpat`
- **Collab-Hub**: realtime service · Socket.IO metadata and presence service.
- **LiveKit Cloud**: audio service
- [Vercel](https://github.com/broduoliviercontact-web/collab-hub-web-monitor/blob/main/vercel.json): static and serverless host · `vercel.json`

## Connections

- Public page entry → Public page composition: boots
- Public page composition → Collab-Hub socket client: starts
- Collab-Hub socket client → Observation guard: guards subscriptions
- Observation guard → Collab-Hub: observes /hub
- Collab-Hub → Collab-Hub socket client: delivers controls
- Collab-Hub socket client → Metadata router: routes messages
- Metadata router → Sound state and persistence: content updates
- Metadata router → Freshness state: heartbeat activity
- Metadata router → Stream status: stream presence
- Sound state and persistence → Public UI runtimes: renders metadata
- Freshness state → Public UI runtimes: renders status
- Stream status → Public UI runtimes: renders stream UI
- Public page composition → LiveKit listener: enables on demand
- LiveKit listener → LiveKit token API: requests listener token
- LiveKit token API → LiveKit Cloud: signs access
- LiveKit listener → LiveKit Cloud: subscribes audio
- Control Room entry → Control Room gate: loads first
- Control Room gate → Control Room session API: checks session
- Control Room session API → Session signing: signs cookies
- Control Room gate → Control Room runtime: authorizes
- Control Room runtime → Audio capture engine: captures audio
- Audio capture engine → LiveKit publisher: MediaStream
- LiveKit publisher → LiveKit token API: requests performer token
- LiveKit publisher → LiveKit Cloud: publishes audio
- Control Room runtime → Stream presence publisher: reports state
- Stream presence publisher → Collab-Hub: publishes presence
- Max metadata publisher → Collab-Hub: publishes metadata
- Public page composition → Gated diagnostics: loads when gated
- Vercel → Public page entry: hosts static app
- Vercel → LiveKit token API: runs function
