# lethalchip/spacechatdb architecture

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

- Interactive diagram: https://gitdiagram.com/lethalchip/spacechatdb
- Repository: https://github.com/lethalchip/spacechatdb

## Overview

SpaceChatDb is a browser-based chat and voice/video calling app backed by SpacetimeDB. The apparent workflow is to connect, exchange chat or call actions, and stream media during calls; the sampled connection code also routes incoming media events to call runtime handlers. The README is only a Svelte starter template and does not document product capabilities. The page and several runtime sections were not excerpted, so UI-to-state wiring and parts of the connection/subscription flow are not asserted.

Main entry points: [`src/module_bindings/index.ts`](https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/index.ts) (Typed module API), [`src/lib/stdb.ts`](https://github.com/lethalchip/spacechatdb/blob/main/src/lib/stdb.ts) (App connection state), [`src/lib/callRuntime.ts`](https://github.com/lethalchip/spacechatdb/blob/main/src/lib/callRuntime.ts) (Call runtime), [`src/routes/+page.svelte`](https://github.com/lethalchip/spacechatdb/blob/main/src/routes/%2Bpage.svelte) (Chat UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client state and runtime"]
  node_ui["Chat UI<br/>[+page.svelte]"]
  node_state["App connection state<br/>[stdb.ts]"]
end

subgraph group_bindings["SpacetimeDB bindings"]
  node_module["Typed module API<br/>[index.ts]"]
  node_call_actions["Call reducers"]
  node_message_actions["Chat reducers"]
  node_audio_action["Audio frame reducer"]
  node_video_action["Video frame reducer"]
  node_session_table[("Call sessions")]
  node_chat_table[("Chat messages")]
  node_users_table[("Users<br/>[user_table.ts]")]
  node_settings_table[("Media settings table")]
  node_audio_events[("Audio frame events")]
  node_video_events[("Video frame events")]
end

subgraph group_call["Calling and media"]
  node_settings["Media settings<br/>[mediaSettings.ts]"]
  node_runtime["Call runtime<br/>[callRuntime.ts]"]
  node_worklet["PCM capture worklet"]
end

node_user(("User"))
node_remote[("SpacetimeDB")]
node_browser_media["Browser media APIs"]

node_user -.->|"uses"| node_ui
node_ui -.->|"invokes"| node_state
node_state -->|"connects through"| node_module
node_module -->|"connects to"| node_remote
node_module -->|"registers schemas"| node_call_actions
node_module -->|"registers schema"| node_message_actions
node_module -->|"registers schema"| node_audio_action
node_module -->|"registers schema"| node_video_action
node_module -->|"registers schema"| node_session_table
node_module -->|"registers schema"| node_chat_table
node_module -->|"registers schema"| node_users_table
node_module -->|"registers schema"| node_settings_table
node_module -->|"registers schema"| node_audio_events
node_module -->|"registers schema"| node_video_events
node_state -->|"dispatches media events"| node_runtime
node_state -->|"updates settings"| node_settings
node_runtime -->|"reads configuration"| node_settings
node_runtime -->|"captures and plays"| node_browser_media
node_runtime -->|"loads worklet"| node_worklet

click node_ui "https://github.com/lethalchip/spacechatdb/blob/main/src/routes/%2Bpage.svelte"
click node_state "https://github.com/lethalchip/spacechatdb/blob/main/src/lib/stdb.ts"
click node_settings "https://github.com/lethalchip/spacechatdb/blob/main/src/lib/mediaSettings.ts"
click node_runtime "https://github.com/lethalchip/spacechatdb/blob/main/src/lib/callRuntime.ts"
click node_worklet "https://github.com/lethalchip/spacechatdb/blob/main/src/lib/pcm-capture-worklet.ts"
click node_module "https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/index.ts"
click node_call_actions "https://github.com/lethalchip/spacechatdb/tree/main/src/module_bindings"
click node_message_actions "https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/send_message_reducer.ts"
click node_audio_action "https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/send_audio_frame_reducer.ts"
click node_video_action "https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/send_video_frame_reducer.ts"
click node_session_table "https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/call_session_table.ts"
click node_chat_table "https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/chat_message_table.ts"
click node_users_table "https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/user_table.ts"
click node_settings_table "https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/media_settings_table.ts"
click node_audio_events "https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/audio_frame_event_table.ts"
click node_video_events "https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/video_frame_event_table.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_ui,node_state,node_user,node_browser_media toneBlue
class node_module,node_call_actions,node_message_actions,node_audio_action,node_video_action,node_session_table,node_chat_table,node_users_table,node_settings_table,node_audio_events,node_video_events,node_remote toneAmber
class node_settings,node_runtime,node_worklet toneMint
```

## Components

### Client state and runtime

- [Chat UI](https://github.com/lethalchip/spacechatdb/blob/main/src/routes/%2Bpage.svelte): `src/routes/+page.svelte`
- [App connection state](https://github.com/lethalchip/spacechatdb/blob/main/src/lib/stdb.ts): `src/lib/stdb.ts`

### SpacetimeDB bindings

- [Typed module API](https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/index.ts): `src/module_bindings/index.ts`
- [Call reducers](https://github.com/lethalchip/spacechatdb/tree/main/src/module_bindings): `src/module_bindings`
- [Chat reducers](https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/send_message_reducer.ts): `src/module_bindings/send_message_reducer.ts`
- [Audio frame reducer](https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/send_audio_frame_reducer.ts): `src/module_bindings/send_audio_frame_reducer.ts`
- [Video frame reducer](https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/send_video_frame_reducer.ts): `src/module_bindings/send_video_frame_reducer.ts`
- [Call sessions](https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/call_session_table.ts): `src/module_bindings/call_session_table.ts`
- [Chat messages](https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/chat_message_table.ts): `src/module_bindings/chat_message_table.ts`
- [Users](https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/user_table.ts): `src/module_bindings/user_table.ts`
- [Media settings table](https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/media_settings_table.ts): `src/module_bindings/media_settings_table.ts`
- [Audio frame events](https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/audio_frame_event_table.ts): `src/module_bindings/audio_frame_event_table.ts`
- [Video frame events](https://github.com/lethalchip/spacechatdb/blob/main/src/module_bindings/video_frame_event_table.ts): `src/module_bindings/video_frame_event_table.ts`

### Calling and media

- [Media settings](https://github.com/lethalchip/spacechatdb/blob/main/src/lib/mediaSettings.ts): `src/lib/mediaSettings.ts`
- [Call runtime](https://github.com/lethalchip/spacechatdb/blob/main/src/lib/callRuntime.ts): `src/lib/callRuntime.ts`
- [PCM capture worklet](https://github.com/lethalchip/spacechatdb/blob/main/src/lib/pcm-capture-worklet.ts): `src/lib/pcm-capture-worklet.ts`

### Other components

- **User**
- **SpacetimeDB**
- **Browser media APIs**

## Connections

- User → Chat UI: uses
- Chat UI → App connection state: invokes
- App connection state → Typed module API: connects through (evidence: `src/lib/stdb.ts`)
- Typed module API → SpacetimeDB: connects to (evidence: `src/module_bindings/index.ts`)
- Typed module API → Call reducers: registers schemas (evidence: `src/module_bindings/index.ts`)
- Typed module API → Chat reducers: registers schema (evidence: `src/module_bindings/index.ts`)
- Typed module API → Audio frame reducer: registers schema (evidence: `src/module_bindings/index.ts`)
- Typed module API → Video frame reducer: registers schema (evidence: `src/module_bindings/index.ts`)
- Typed module API → Call sessions: registers schema (evidence: `src/module_bindings/index.ts`)
- Typed module API → Chat messages: registers schema (evidence: `src/module_bindings/index.ts`)
- Typed module API → Users: registers schema (evidence: `src/module_bindings/index.ts`)
- Typed module API → Media settings table: registers schema (evidence: `src/module_bindings/index.ts`)
- Typed module API → Audio frame events: registers schema (evidence: `src/module_bindings/index.ts`)
- Typed module API → Video frame events: registers schema (evidence: `src/module_bindings/index.ts`)
- App connection state → Call runtime: dispatches media events (evidence: `src/lib/stdb.ts`)
- App connection state → Media settings: updates settings (evidence: `src/lib/stdb.ts`)
- Call runtime → Media settings: reads configuration (evidence: `src/lib/callRuntime.ts`)
- Call runtime → Browser media APIs: captures and plays (evidence: `src/lib/callRuntime.ts`)
- Call runtime → PCM capture worklet: loads worklet (evidence: `src/lib/callRuntime.ts`)
