Frontend Data Flow and Store Ownership
This document summarizes how data moves through the frontend and which modules own which responsibilities.
Data flow overview
- Views (App.svelte, Dashboard.svelte, PlanView.svelte, LogsView.svelte, FlowView.svelte) fetch initial data with
apiFetch. - Event WebSockets fan out through event stores, which dispatch typed payloads to subscribed views.
- Session UI uses
terminalStorefor per-session state, which owns xterm setup, socket lifecycle, and history replay.
Store ownership
frontend/src/lib/terminalStore.js- Owns per-session state keyed by session ID.
- Delegates to
terminal/xterm.jsfor xterm setup,terminal/socket.jsfor WS/history, andterminal/input.jsfor input + touch scroll helpers. - Exposes status, history status, bell count, reconnect, scroll state, and input helpers.
frontend/src/lib/eventStore.js- Filesystem event stream (
/ws/events) with subscription message support.
- Filesystem event stream (
frontend/src/lib/agentEventStore.js- Agent lifecycle events (
/api/agents/events).
- Agent lifecycle events (
frontend/src/lib/terminalEventStore.js- Session lifecycle events (
/api/sessions/events).
- Session lifecycle events (
frontend/src/lib/configEventStore.js- Config change events (
/api/config/events).
- Config change events (
frontend/src/lib/workflowEventStore.js- Workflow events (
/api/workflows/events).
- Workflow events (
frontend/src/lib/notificationStore.js- Toast queue and dismissal logic for global notices.
Component responsibilities
- Views own data shaping and local UI state, not transport logic.
- Stores own WebSocket lifecycle, reconnection, parsing, and fan-out.
- Components should avoid creating new WebSocket connections directly; use stores instead.
Common patterns
- Fetch-on-mount for baseline state; subscribe to event stores for updates.
- When adding a new long-lived stream, introduce a store that owns its socket lifecycle and exposes a
subscribeAPI. - When adding a session-facing feature, keep xterm and socket changes inside
terminalStoreor its helper modules.