Y-SweetConceptsY-Sweet and Your App

Y-Sweet and Your App

A minimum viable app with Y-Sweet just needs these three components:

  • An auth endpoint that authorizes a user to access a document using the Y-Sweet API
  • A client that connects to the Y-Sweet server
  • A Y-Sweet server, which syncs data across users with Yjs and persists your data in blob storage. (This part is taken care of when you use Y-Sweet on Jamsocket.)

You may have additional components to your stack, like a database for saving user and document metadata. But for most collaborative realtime applications, a Y-Sweet app that follows this structure is all you need.

💡

If you’re building with a Meta Framework like NextJS, Remix, or Sveltekit, you can implement the auth endpoint in the same codebase as your client application.

Check out the following tutorials for how to setup and build a realtime, collaborative app with Y-Sweet.

How Y-Sweet interacts with your app

It can be helpful to know how Y-Sweet interacts with the client and your auth endpoint. Here’s the breakdown:

When your user opens a document…

  1. The YSweetProvider in the client will fetch a client token from an auth endpoint you’ve implemented on your server.
  2. Your auth endpoint will then make a request to the Y-Sweet API using getOrCreateDocAndToken or getClientToken. Both these functions require a connection string to authenticate your request.
  3. getOrCreateDocAndToken or getClientToken will return a client token which is sent in the auth endpoint’s response back to the YSweetProvider in the client.
  4. The YSweetProvider in your client uses this client token to connect to the Y-Sweet server via a websocket connection.
  5. When your users make changes to a document, the Y-Sweet server will broadcast the changes to all connected clients and then persist the document. This means that users returning to the document will always see the latest changes.

Next Steps

Built by Jamsocket.