Wire Protocol

The 140+ operation WebSocket API: message framing, JSON and binary codecs, connection lifecycle, subscription model, and rate limiting — the complete integration surface for building clients and tools.

1. Overview 2. Transport Layer 3. Message Format 4. Operation Categories 5. Codecs (JSON & Binary) 6. Connection Lifecycle 7. Subscription Model 8. Security Features

1. Overview

Xudanu's wire protocol is a WebSocket-based request-response protocol with server-push subscriptions. Every operation has a typed request and response, identified by a numeric operation code.

The protocol is defined in src/server/transport/protocol.rs (~2,969 lines) with codecs in codec.rs (~2,902 lines) and dispatch in dispatch.rs (~2,667 lines). Together these ~8,500 lines define the entire API surface.

2. Transport Layer

3. Message Format

Every message follows a consistent structure:

{
  "op": "work_list",          // Operation name
  "request_id": 42,            // Client-assigned correlation ID
  "payload": { ... }           // Operation-specific parameters
}

Responses echo the request_id and include a value or error:

{
  "op": "work_list",
  "request_id": 42,
  "value": {
    "works": [
      { "work_be_id": 1004, "title": "Alice's Document", ... }
    ]
  }
}

4. Operation Categories

The 140+ operations are organized into these categories:

CategoryExample OperationsOp Code Range
SessionLogin, logout, public login, session info0x0001–0x000F
Work CRUDCreate, list, get, delete, search, outline0x0100–0x011F
Edition / ContentGet edition, revise, get text, goto, search content0x0200–0x021F
Club ManagementCreate club, name club, add/remove members, set credential0x0300–0x031F
Stars / FavoritesStar, unstar, is starred, starred list0x0335–0x0337
TrailsCreate, delete, rename, add stop, remove stop, reorder, list, get0x0339–0x0340
Document MapWork graph (nodes + edges for visualization)0x0338
TransclusionContent watch, find content, shared content, content match0x0400–0x041F
CRDT SyncText delta, awareness update, sync session0x0500–0x051F
Links & LabelsCreate/delete link, get links, set/get label0x0600–0x061F
BlobsUpload, get, info, exists, stats0x0700–0x071F
AnnotationsCreate, delete, list, update annotation0x0800–0x081F
EndorsementsEndorse, unendorse, list endorsements0x0900–0x091F
FederationAdd/remove peer, federated query, replicate0x0A00–0x0A1F
GovernancePropose, vote, seal, get proposals0x0B00–0x0B1F
AttributionGet attribution, verify attribution log0x0C00–0x0C1F
VersioningGet revision, revision count, compare revisions0x0D00–0x0D1F
LLMNarrate diff, auto-title, writing feedback0x0E00–0x0E1F
AdminPreflight check, verify log, checkpoint0x0F00–0x0F1F

5. Codecs (JSON & Binary)

The protocol supports two wire formats:

JSON Codec

Human-readable, easy to debug. Used by the web UI and third-party integrations. Messages are UTF-8 text frames.

{
  "op": "work_star",
  "request_id": 7,
  "payload": {
    "work_be_id": 1004
  }
}

Binary Codec

Compact, fast. Uses postcard serialization (serde-compatible) with LEB128 varint encoding. Messages are binary WebSocket frames. Typically 3-5x smaller than JSON.

[varint: op_code]
[varint: request_id]
[postcard: payload]
Codec selection: The server auto-detects the codec based on the WebSocket frame type (text = JSON, binary = postcard). A single connection can use either codec.

6. Connection Lifecycle

Client Server ① WebSocket upgrade (GET /ws?version=2) ② 101 Switching Protocols ③ public_login or login (credentials) ④ session_info (club_id, author identity) ⑤ Active session: request-response + subscriptions work_list, revise, star, trail ops, awareness relay... ⑥ WebSocket close (or TCP disconnect) ⑦ Cleanup: remove awareness, release grabs

Figure 1: WebSocket connection lifecycle from upgrade through authentication to active session and cleanup.

7. Subscription Model

Beyond request-response, clients can subscribe to real-time events:

SubscriptionTriggerPush Data
StatusWork created, deleted, or metadata changedWork list update
RevisionWork content revised by any sessionNew revision number + text delta
FillRecorder triggered (transclusion match found)Fossil ID + matched content
Content WatchNew content matching watched fingerprintsContentMatch with work/edition info
AwarenessAnother user's cursor/selection/typing state changesOtreeAwarenessState relay

8. Security Features