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.
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.
Where the token comes from
Nobody creates collaboration tokens. The user's sign-in already produced one, and the project simply passes it along.
- User signs inwith Docyrus Supabase login or
@docyrus/signin. - Auth issues a tokenand refreshes it on its own, about every hour.
- Project connectswith that token and the document name.
- 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.
-
Point the project at the server
.env# alpha / local development VITE_COLLAB_URL=wss://alpha-collab.docyrus.app.env.productionVITE_COLLAB_URL=wss://collab.docyrus.app -
Install the provider
pnpm add yjs @hocuspocus/providerProvider v3 and v4 both work. Plate users already have it through
@platejs/yjs. -
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'sr#<recordId>. A new editor gets a new kind. -
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).
// Must be the Docyrus Supabase project: https://api.docyrus.app const { data: { session } } = await supabase.auth.getSession(); const tenantId = session?.user.app_metadata.tid; const getToken = async () => (await supabase.auth.getSession()).data.session?.access_token ?? '';The server verifies the session token's signature against the Docyrus Supabase public keys. Anonymous (anon key) sessions are rejected.
-
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();import { YjsPlugin } from '@platejs/yjs/react'; YjsPlugin.configure({ options: { providers: [{ type: 'hocuspocus', options: { url: `${import.meta.env.VITE_COLLAB_URL}/collab/${encodeURIComponent(documentName)}`, name: documentName, token: getToken } }] } });import Collaboration from '@tiptap/extension-collaboration'; import CollaborationCaret from '@tiptap/extension-collaboration-caret'; // ydoc + provider from the "Any Yjs editor" tab const editor = new Editor({ extensions: [ StarterKit.configure({ undoRedo: false }), Collaboration.configure({ document: ydoc }), CollaborationCaret.configure({ provider, user: { name: user.name, color: '#0E9F8E' } }) ] });import { CollaborationSession, WebSocketTransport } from '@docyrus/ui-pro-sheets'; // Sheets uses its own JSON protocol, so the token goes in the URL const roomName = `t#${tenantId}/sheet#${sheet.id}`; const socket = new WebSocket( `${import.meta.env.VITE_COLLAB_URL}/sheets/${encodeURIComponent(roomName)}?token=${await getToken()}` ); const session = new CollaborationSession(workbook, new WebSocketTransport(socket), { name: user.name });
Before you ship
VITE_COLLAB_URLis set for every environment- Document names start with
t#<tenantId>/ tokenis 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
| Name | Value | Type |
|---|---|---|
VITE_COLLAB_URL | wss://alpha-collab.docyrus.appwss://collab.docyrus.app | Public |
| Document name | t#<tenantId>/<kind>#<id> | Public |
| Token | The signed-in user's Docyrus token, from @docyrus/signin or Supabase | Per user, automatic |
Server configuration
| Name | Value | Used for |
|---|---|---|
SUPABASE_URL | https://api.docyrus.app | Verifying Docyrus session tokens |
DOCYRUS_API_URL | Alpha server: https://alpha-api.docyrus.com/v1 and https://beta-api.docyrus.com/v1Production: https://api.docyrus.com/v1 | Verifying @docyrus/signin tokens; the token's issuer picks the API |
JWT_ISSUER / JWT_AUDIENCE | docyrus / docyrus-collaboration | Read-only and scoped tokens |
ALLOWED_ORIGINS | * | Browser origins allowed to connect |
API_KEYS | Secret, never shown | REST API access for Docyrus Core |
CHANGE_WEBHOOK_SECRET | Secret, never shown | Signing change notifications |
COLLAB_JWT_SECRET | Secret, never shown | Issuing 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:
| Check | What it stops |
|---|---|
| A token is required | Anonymous connections, made-up tokens |
| Signature from Docyrus | Tokens from other Supabase projects or anyone else |
| Signed-in user only | Sessions created with the public anon key |
| Tenant matches the document | Opening another company's documents |
| Not suspended, not expired | Suspended users and stale tokens |
| Name matches the URL | Using 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.
{
"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.
| Method | Path | What it does |
|---|---|---|
| GET | /api/documents?prefix=t%2342%2F | List a tenant's documents |
| GET | /api/documents/:name?format=yjs|json | Read the current state; json with type=prosemirror|slate |
| POST | /api/documents/:name | Create from a Yjs update or ProseMirror JSON |
| PATCH | /api/documents/:name | Merge a Yjs update or replace with ProseMirror JSON; ?create=true to upsert |
| PUT | /api/documents/:name?type=… | Replace the content |
| DELETE | /api/documents/:name | Delete and disconnect everyone |
| GET, POST | /api/documents/:name/snapshots | List or create version snapshots |
| POST | /api/documents/:name/snapshots/:id/restore | Restore a snapshot (the current state is kept as a snapshot) |
| GET | /api/documents/:name/versions | Tiptap version history |
| POST | /api/documents/:name/versions/:version/revertTo | Restore 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 see | Why, and the fix |
|---|---|
| HTTP 400 when connecting | The name in the URL doesn't start with t#<tenantId>/. |
| Document belongs to another tenant | The tenant in the name isn't the user's. Build it from the signed-in user. |
| Document does not match the connection URL | The provider's name differs from the name in the URL. |
| Unsupported or invalid token | The token isn't from Docyrus, is anonymous, or has expired. |
| Works, then fails after about an hour | token 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.