Aoba Sync WebSocket API 1.0.0

Dedicated WebSocket endpoint for cr-sqlite CRDT synchronization between multiple devices for the same user.

Purpose

This API enables offline-first messaging by synchronizing local SQLite databases across devices using cr-sqlite's CRDT-based merge algorithm.

Architecture

  • Each client maintains a local cr-sqlite database
  • Changes are tracked via crsql_changes virtual table
  • Sync messages are routed only to other devices of the same user
  • Server acts as a relay (no persistence of sync data)

Connection Lifecycle

  1. Client opens WebSocket to /api/v1/sync
  2. Server validates JWT from auth_token cookie
  3. Client sends sync_request to get changes from other devices
  4. Devices exchange sync_push/sync_ack messages for incremental updates
  5. Connection closes on logout, token expiry, or network failure

Servers

  • ws://localhost:8082/wsdevelopment

    Local development server

  • wss://staging.aoba.chat/wssstaging

    Staging server (TLS required)

  • wss://api.aoba.chat/wssproduction

    Production server (TLS required)

Operations

  • SEND /api/v1/sync

    Dedicated WebSocket channel for cr-sqlite synchronization.

    Authentication: JWT token must be present in auth_token cookie. Connection is rejected with close code 4001 if token is invalid or expired.

    Routing: Messages are broadcast to all other connections belonging to the same user (identified by JWT sub claim).

    Request changes from other devices

    Sent when a device comes online or reconnects to request any changes that occurred while it was offline. Other devices respond with sync_response.

    Operation IDrequestSync

    Available only on servers:

    object

    Accepts the following message:

    Sync RequestSyncRequest

    Request changes from other devices

    Message IDSyncRequest
    allOf

    Examples

  • RECEIVE /api/v1/sync

    Dedicated WebSocket channel for cr-sqlite synchronization.

    Authentication: JWT token must be present in auth_token cookie. Connection is rejected with close code 4001 if token is invalid or expired.

    Routing: Messages are broadcast to all other connections belonging to the same user (identified by JWT sub claim).

    Receive sync response with changes

    Response to a sync_request containing changes since the requested version.

    Operation IDrespondToSync

    Available only on servers:

    object

    Accepts the following message:

    Sync ResponseSyncResponse

    Response containing requested changes

    Message IDSyncResponse
    allOf

    Examples

  • SEND /api/v1/sync

    Dedicated WebSocket channel for cr-sqlite synchronization.

    Authentication: JWT token must be present in auth_token cookie. Connection is rejected with close code 4001 if token is invalid or expired.

    Routing: Messages are broadcast to all other connections belonging to the same user (identified by JWT sub claim).

    Push local changes to other devices

    Sent after local database modifications to propagate changes to other devices. Recipients should apply changes and respond with sync_ack.

    Operation IDpushChanges

    Available only on servers:

    object

    Accepts the following message:

    Sync PushSyncPush

    Push local changes to other devices

    Message IDSyncPush
    allOf

    Examples

  • RECEIVE /api/v1/sync

    Dedicated WebSocket channel for cr-sqlite synchronization.

    Authentication: JWT token must be present in auth_token cookie. Connection is rejected with close code 4001 if token is invalid or expired.

    Routing: Messages are broadcast to all other connections belonging to the same user (identified by JWT sub claim).

    Receive acknowledgment of applied changes

    Confirmation that pushed changes were received and applied (or rejected).

    Operation IDacknowledgeChanges

    Available only on servers:

    object

    Accepts the following message:

    Sync AcknowledgmentSyncAck

    Acknowledgment of received changes

    Message IDSyncAck
    allOf

    Examples

Messages

  • #1Sync RequestSyncRequest

    Request changes from other devices

    Message IDSyncRequest
    allOf
  • #2Sync ResponseSyncResponse

    Response containing requested changes

    Message IDSyncResponse
    allOf
  • #3Sync PushSyncPush

    Push local changes to other devices

    Message IDSyncPush
    allOf
  • #4Sync AcknowledgmentSyncAck

    Acknowledgment of received changes

    Message IDSyncAck
    allOf

Schemas

  • object
  • allOf
  • allOf
  • allOf
  • allOf
  • object

    Request changes from other devices since a specific version

  • object

    Response containing changes since requested version

  • object

    Push local changes to other devices

  • object

    Acknowledgment of received and applied changes

  • object

    Single cr-sqlite CRDT change record from the crsql_changes virtual table. Represents a column-level change that can be merged across devices.

  • object

    Error encountered during sync operation

  • object

    Reason for WebSocket connection close