flowchart LR
    browser[Browser SPA
    WS client]
    ws[WebSocketHandler]
    handlers[Message handlers
    src/lib/handlers/*]
    sessions[SessionManager
    and session registry]
    bridges[Permission and
    question bridges]
    relayCore[Event pipeline
    SSEConsumer
    pollers, PTY wiring]
    eventStore[SQLite event store
    projectors]
    provider[Provider adapter
    stateless execution engine]
    opencode[OpenCode server]

    browser <-->|WebSocket messages| ws
    ws --> handlers
    handlers --> sessions
    handlers --> bridges
    sessions --> relayCore
    bridges --> relayCore
    relayCore --> ws
    relayCore --> provider
    provider -->|stream events| eventStore
    provider <-->|REST, SSE, PTY upstream| opencode
    eventStore --> ws