Skip to content

Latest commit

 

History

History
118 lines (84 loc) · 5.84 KB

README.md

File metadata and controls

118 lines (84 loc) · 5.84 KB

Y-Sweet: a realtime CRDT-based document database, backed by object storage

GitHub Repo stars Chat on Discord

Y-Sweet is an open-source server for building realtime applications on top of the Yjs CRDT library.

Features

  • Persists document data to a network filesystem or S3-compatible storage, inspired by Figma’s infrastructure.
  • Scales horizontally with a session backend model.
  • Deploys as a native Linux process.
  • Provides document-level access control via client tokens.
  • Written in Rust with a focus on stability and performance, building on the blazing fast y-crdt library.

Y-Sweet stack

The Y-Sweet server can be used by any Yjs app, or you can use our opinionated stack to integrate Yjs and Y-Sweet into a Next.js app.

  • @y-sweet/sdk, a TypeScript library for interacting with y-sweet-server from your application backend.
  • @y-sweet/client, a TypeScript library for syncing documents from a client to a Y-Sweet server.
  • @y-sweet/react, a library of React hooks for connecting to a Y-Sweet server and manipulating Yjs docs.
  • A debugger for exploring Yjs document and presence state.

The goal of the Y-Sweet stack is to give developers the end-to-end developer ergonomics they would expect from a proprietary state-sync platform, without the lock-in.

Y-Sweet is MIT-licensed, and was created by Jamsocket.

Docs

Examples

Explore our collaborative examples to help you get started.

All examples are open source and live in this repository, within /examples.

Usage

Check the vanilla js example for more details.

On the server

import { DocumentManager } from '@y-sweet/sdk';

// Pass in a CONNECTION_STRING, which you can get from a Y-Sweet service in the Jamsocket dashboard or from running npx y-sweet@latest serve locally
const manager = new DocumentManager(CONNECTION_STRING);

// create an endpoint that auths your user and returns a Y-Sweet client token
export async function POST(request) {
  // in a production app, you'd want to authenticate the user
  // and make sure they have access to the given doc
  const body = await request.json();
  const docId = body.docId;
  const clientToken = await manager.getOrCreateDocAndToken(docId);
  return Response.json(clientToken);
}

On the client

import * as Y from 'yjs';
import { createYjsProvider } from '@y-sweet/client';

// Create the Yjs doc and link it to the Y-Sweet server:
const doc = new Y.Doc();
const docId = 'my-doc-id';
createYjsProvider(doc, docId, '/api/my-auth-endpoint');

// Now use the doc like a normal Yjs doc!
let mySharedMap = doc.getMap('thing');
mySharedMap.set("foo", 123);

// Update your UI based on `mySharedMap` changes like this, for example:
mySharedMap.observe((event) => {
  event.keysChanged.forEach((key) => {
    // do whatever you want based on the detected change:
    yourUpdateFunction(key, mySharedMap.get(key));
  });
});

Packages

Server

Package Manager Name Version Path
npm y-sweet npm js-pkg/server
crates.io y-sweet crates.io crates/y-sweet
crates.io y-sweet-core crates.io crates/y-sweet-core

Client

Package Manager Name Version Path
npm @y-sweet/sdk npm js-pkg/sdk
npm @y-sweet/client npm js-pkg/client
npm @y-sweet/react npm js-pkg/react
pypi y-sweet-sdk pypi python/y_sweet_sdk

Hosted Y-Sweet on Jamsocket

If you were to use the open source Y-Sweet server alone, you would still have to set up the infrastructure for self hosting it. With Jamsocket, Y-Sweet scales effortlessly, and every document is automatically persisted when you link your own S3 storage.

You can try it out for free today by following our quickstart guide.

If you are interested in being a build partner for early access to new features, please reach out.

We are committed to growing Y-Sweet as an open-source-first project, wherever you decide to host it.