Status
Partially superseded by ADR-071,
which replaces the origin allow-list client-registration requirement, and
ADR-074, which makes the
server catalogue device-local. ADR-079
replaces the sliding bearer-token lifetime. The multi-server client
architecture remains current. ADR-111
moves the registry, sessions, and stores into @chatto/client; the frontend
keeps URL routing and the Svelte route scope.
Context
Chatto's frontend was originally designed as a single-server client — the SPA was always served by the Chatto server it connected to, and all state (auth, rooms, notifications) was implicitly scoped to that one server.
Users wanted to connect to multiple Chatto servers from a single client (similar to how Discord or Slack allow multiple workspaces). This required rethinking how the frontend manages authentication, state, and routing.
Decision
Server-Agnostic UI
The frontend is server-agnostic by default. It doesn't assume it is served by a Chatto server. Instead:
- Probe-based origin detection: Discover an HTTP or HTTPS origin through
chatto.discovery.v1.ServerDiscoveryService.GetServer. Register it when discovery succeeds. Native shell origins cannot host the backend and are not probed. Route loading waits for origin discovery and registration. - No
isHomeflag: The origin server is identified by comparingserver.urltowindow.location.originat runtime — no stored flag. - Cookie-only origin auth: The client uses the HttpOnly cookie for the server that serves the SPA. Dedicated browser authentication does not issue bearer credentials for that server. During migration, the client revokes old origin bearer authority before it removes the local credentials. Remote servers use persisted renewable bearer sessions obtained through Chatto OAuth.
Bearer tokens are only handed to API clients that need to authenticate ConnectRPC, realtime WebSocket, or direct HTTP API traffic. Browser media elements do not receive bearer tokens; remote attachment media uses direct per-user asset access tickets on stable asset URLs instead.
Server Catalogue, Sessions, and Retained State
ADR-064 supersedes this decision's original unified registration-and-session
model. Public server catalogue metadata and device-local authentication are
separate reactive state owners. ServerRegistry composes them with per-server
state stores and connections. Catalogue registration and store creation remain
atomic: when a server is added, its retained store exists immediately.
The persisted localStorage slot intentionally remains named instances, and
its combined record remains a compatibility adapter. It is split into catalogue
and session state at runtime. Authentication fields migrate into independently
keyed per-server records; combined-record saves merge those authoritative
fields so a stale tab cannot restore an older rotated credential generation.
The catalogue and sessions are device-local under ADR-074. A server can remain
known while signed out, and selecting it starts the normal Chatto OAuth flow.
The existing chatto:instances compatibility record accepts former provenance
fields but rewrites every registration into the device-local catalogue. The
frontend has no global identity-provider session or synchronized catalogue.
URL-Based Server Routing
The URL is the sole source of truth for which server is active:
-segment = origin server- Hostname segment = remote server (e.g.,
chat.example.com)
The [serverId]/+layout.svelte resolves the segment and provides the server ID,
connection, and store through ServerScopeProvider. The provider is keyed by
store identity, so session replacement also replaces the route scope. There
is no mutable active-server singleton.
Per-Server Permissions
Each server state store has permission and viewer-capability state loaded from ConnectRPC viewer/server-state APIs. This lets the UI show only actions the viewer can perform on the selected server.
Renewable Bearer Lifetime
Human bearer sessions use short fixed-lifetime access tokens and rotating refresh credentials. The frontend serializes rotation, refreshes before access expiry, and advances the renewable-session window without user action. Origin cookie sessions renew one stable handle in the final quarter of the current credential window. ADR-079 and ADR-081 own the detailed renewal, recovery, revocation, and expiry contract.
Consequences
Positive
- Users can connect to multiple Chatto servers from one client
- The SPA can be served statically (CDN) without a Chatto backend
- Server-scoped screens share stores and API adapters. Origin cookie sessions and remote bearer sessions retain their own authentication and recovery paths.
- Short access lifetimes bound an access token stolen without its refresh credential, while background rotation avoids frequent interactive login
Negative
- Remote-server bearer credentials in
localStorageare vulnerable to XSS (origin cookie auth is not) - This makes XSS prevention part of the auth boundary. The shipped frontend enforces a CSP. It uses build-time hashes for inline bootstrap scripts and does not allow general inline scripts.
- All public HTTP and realtime entry points permit browser transport from any syntactically valid origin without credentialed CORS. Cross-origin clients must present bearer tokens; ambient cookie credentials remain same-origin only.
- Separately hosted frontends publish a CIMD document and send its URL as
client_id. Chatto validates the exact callback from that document, while Desktop uses its fixed built-in registration. - Users approve the first OAuth authorization for each client; Chatto remembers consent per user + stable client ID without an operator-managed registration table.
- Signing in to each Chatto server remains a separate authorization and creates a device-local session.
- Startup waits for network discovery and account loading. The client stores no chat data on the device; see ADR-107.
Trade-offs
- Bearer refresh failure preserves the route and marks only that server as requiring explicit authentication, while an invalid origin cookie session can still require server-side logout plus a hard reload. The two presentations retain distinct disconnect flows.
- SvelteMap for the store map enables reactive
$derivedreads but requires careful separation of imperative writes (addServer) from pure reads (getStore)