Docyrus Collaboration

Write together in every Docyrus editor.

Docyrus Collaboration keeps Plate, Tiptap, diagram and sheets documents in sync between everyone who has them open. Your project connects with the token its user already has — no keys, no registration.

Production collab.docyrus.app Alpha alpha-collab.docyrus.app
t#42/plate#q3-launch-plan

Q3 launch plan

  • Migrate documents from Tiptap Cloud
3 people editing. All changes saved.

What it is

Docyrus Collaboration is our own real-time sync server. When two people open the same document, every keystroke, cursor and selection reaches the other person in milliseconds, and the document is saved without anyone pressing save.

It replaces Tiptap Cloud collaboration. It speaks the same protocol, so the Hocuspocus and Tiptap providers our editors already use connect to it unchanged. We run it on Cloudflare, close to every user, and we own the data.

Hocuspocus v4Open-source Yjs collaboration server by Tiptap. Handles sync, presence and auth hooks.
YjsConflict-free document model. Edits merge automatically, even after working offline.
Workers + Durable ObjectsOne Durable Object per document holds it in memory while people edit.
R2 + QueuesBackups, version snapshots and change notifications for Docyrus Core.

How it works

Every document gets its own Durable Object, found by the document's name. People editing the same document always meet in the same place, so there is no extra database or Redis to keep in sync.

Clients connect to the Worker, which routes each document to its Durable Object; documents are stored in SQLite, backed up to R2 and announced through a queue. Plate and Tiptapeditors in the browser Diagram and Sheetseditors in the browser Docyrus Coreserver, REST + API key collab.docyrus.app Worker: checks the token, routes by document name, serves REST + these docs t#42/plate#q3-planDurable Object + SQLite t#42/r#1001Durable Object + SQLite t#7/sheet#budgetDurable Object (relay) R2backups,snapshots Queuechangewebhook
Solid lines are live WebSocket connections; the dashed line is Docyrus Core using the REST API.

Where the token comes from

Nobody creates collaboration tokens. The user's sign-in already produced one, and the project simply passes it along.

  1. User signs inwith Docyrus Supabase login or @docyrus/signin.
  2. Auth issues a tokenand refreshes it on its own, about every hour.
  3. Project connectswith that token and the document name.
  4. Server verifiesthe signature and that the document's tenant is the user's.

Quick start

Five steps take a project from nothing to live editing. There is nothing to register and no key to request.

  1. Point the project at the server

    .env
    # alpha / local development
    VITE_COLLAB_URL=wss://alpha-collab.docyrus.app
    .env.production
    VITE_COLLAB_URL=wss://collab.docyrus.app
  2. Install the provider

    pnpm add yjs @hocuspocus/provider

    Provider v3 and v4 both work. Plate users already have it through @platejs/yjs.

  3. Name the document

    // t#<tenantId>/<kind>#<id> — the tenant prefix is required
    const documentName = `t#${tenantId}/plate#${doc.id}`;

    The tenant prefix is what access is checked against. Kinds in use today: plate, markdown, diagram, notion, sheet, and Docyrus Core's r#<recordId>. A new editor gets a new kind.

  4. Get the tenant and the token

    import { useDocyrusAuth } from '@docyrus/signin';
    
    const { user, client } = useDocyrusAuth();
    
    const tenantId = user?.tenant?.id;
    // A function, so every reconnect gets the current, refreshed token
    const getToken = async () => (await client?.getAccessToken()) ?? '';

    The server verifies this OAuth2 token by asking the Docyrus API who it belongs to (cached for a minute).

  5. Connect your editor

    import { HocuspocusProvider, HocuspocusProviderWebsocket } from '@hocuspocus/provider';
    import * as Y from 'yjs';
    
    const ydoc = new Y.Doc();
    const websocketProvider = new HocuspocusProviderWebsocket({
      // The document name must be in the URL: it routes you to the document
      url: `${import.meta.env.VITE_COLLAB_URL}/collab/${encodeURIComponent(documentName)}`
    });
    const provider = new HocuspocusProvider({
      websocketProvider,
      name: documentName,
      document: ydoc,
      token: getToken,
      onAuthenticationFailed: ({ reason }) => showNoAccess(reason)
    });
    
    provider.attach(); // needed when you pass your own websocketProvider
    
    // on unmount
    provider.destroy();
    websocketProvider.destroy();

Before you ship

  • VITE_COLLAB_URL is set for every environment
  • Document names start with t#<tenantId>/
  • token is a function, not a fixed string
  • A failed authentication shows “no access” instead of an empty editor
  • Provider and socket are destroyed when the editor closes
  • No API key or secret appears anywhere in client code

Values you need

Client projects only need public values. Secrets exist for server-to-server work and never leave the servers that use them; they are listed here by name only.

In a client project

NameValueType
VITE_COLLAB_URLwss://alpha-collab.docyrus.app
wss://collab.docyrus.app
Public
Document namet#<tenantId>/<kind>#<id>Public
TokenThe signed-in user's Docyrus token, from @docyrus/signin or SupabasePer user, automatic

Server configuration

NameValueUsed for
SUPABASE_URLhttps://api.docyrus.appVerifying Docyrus session tokens
DOCYRUS_API_URLAlpha server: https://alpha-api.docyrus.com/v1 and https://beta-api.docyrus.com/v1
Production: https://api.docyrus.com/v1
Verifying @docyrus/signin tokens; the token's issuer picks the API
JWT_ISSUER / JWT_AUDIENCEdocyrus / docyrus-collaborationRead-only and scoped tokens
ALLOWED_ORIGINS*Browser origins allowed to connect
API_KEYSSecret, never shownREST API access for Docyrus Core
CHANGE_WEBHOOK_SECRETSecret, never shownSigning change notifications
COLLAB_JWT_SECRETSecret, never shownIssuing read-only and scoped tokens

Never put a secret in a browser bundle. If client code seems to need one, the work belongs on a server: call the REST API from there, or have a backend issue a scoped token.

Access rules

Knowing the address is not enough to connect. Every connection is checked when it opens:

CheckWhat it stops
A token is requiredAnonymous connections, made-up tokens
Signature from DocyrusTokens from other Supabase projects or anyone else
Signed-in user onlySessions created with the public anon key
Tenant matches the documentOpening another company's documents
Not suspended, not expiredSuspended users and stale tokens
Name matches the URLUsing one connection to reach a different document

A user can open every collaborative document of the tenants they belong to. Record-level permissions are not enforced yet; use a scoped token when you need them.

Read-only and scoped access

Docyrus tokens give read and write access. For viewers, share links, embeds or “only these documents”, a backend holding COLLAB_JWT_SECRET issues a short-lived token and the client uses it instead.

collab JWT, HS256
{
  "iss": "docyrus",
  "aud": "docyrus-collaboration",
  "sub": "<userId>",
  "tid": "<tenantId>",
  "docs": ["t#42/r#1001", "t#42/d#7/*"],
  "ro": true,
  "exp": 1790000000
}

ro: true makes the connection read-only. docs limits it to exact names or prefixes ending in *.

REST API

For servers that read or write documents without a user: indexing, imports, exports. Authenticate with Authorization: Bearer <API key>. Document names are URL-encoded in the path.

MethodPathWhat it does
GET/api/documents?prefix=t%2342%2FList a tenant's documents
GET/api/documents/:name?format=yjs|jsonRead the current state; json with type=prosemirror|slate
POST/api/documents/:nameCreate from a Yjs update or ProseMirror JSON
PATCH/api/documents/:nameMerge a Yjs update or replace with ProseMirror JSON; ?create=true to upsert
PUT/api/documents/:name?type=…Replace the content
DELETE/api/documents/:nameDelete and disconnect everyone
GET, POST/api/documents/:name/snapshotsList or create version snapshots
POST/api/documents/:name/snapshots/:id/restoreRestore a snapshot (the current state is kept as a snapshot)
GET/api/documents/:name/versionsTiptap version history
POST/api/documents/:name/versions/:version/revertToRestore a Tiptap version (same path as Tiptap Cloud)
curl -H "Authorization: Bearer $API_KEY" \
  "https://collab.docyrus.app/api/documents/t%2342%2Fr%231001?format=json"

Change webhook

When documents change, the server sends batched notifications to Docyrus Core so it can index content or react. Each request is signed with CHANGE_WEBHOOK_SECRET.

POST <CHANGE_WEBHOOK_URL>
x-docyrus-timestamp: 1790000000
x-docyrus-signature: sha256=HMAC_SHA256(secret, "<timestamp>.<body>")

{"events":[{"type":"document.changed","documentName":"t#42/r#1001","tenantId":"42","revision":7,"updatedBy":"u1"}]}

Troubleshooting

What you seeWhy, and the fix
HTTP 400 when connectingThe name in the URL doesn't start with t#<tenantId>/.
Document belongs to another tenantThe tenant in the name isn't the user's. Build it from the signed-in user.
Document does not match the connection URLThe provider's name differs from the name in the URL.
Unsupported or invalid tokenThe token isn't from Docyrus, is anonymous, or has expired.
Works, then fails after about an hourtoken was a fixed string. Pass a function.
Origin not allowed (403)Add the site to ALLOWED_ORIGINS.

Open source

Docyrus Collaboration is built on Hocuspocus (MIT) by the Tiptap team and Yjs (MIT) by Kevin Jahns. We use Hocuspocus v4 unmodified from npm; our code adds the Cloudflare runtime, Docyrus authentication, storage, the REST API and the sheets relay.

Further reading: Hocuspocus documentation, Yjs documentation, Cloudflare Durable Objects.