Y-Sweet and Your App
A minimum viable app with Y-Sweet just needs these three components:
- A server 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.
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 Nextjs, your server and client will be part of the same Nextjs codebase.
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
Y-sweet speaks to both your client and server to serve your users realtime collaborative documents. It can be helpful to know how y-sweet interacts with the client and server. Here's the breakdown:
When your user opens a document...
- The
YSweetProvider
in the client will fetch a client token from an auth endpoint you've implemented on your server. - Your server's auth endpoint will make a request to the Y-Sweet API using
getOrCreateDocAndToken
orgetClientToken
. Both these functions require aconnection string
to authenticate your request. getOrCreateDocAndToken
orgetClientToken
will return a client token which is sent in the auth endpoint's response.- The
YSweetProvider
in your client will use thisclient token
to connect to the Y-Sweet server via a websocket connection. - When your users make changes to a document, the Y-Sweet server will register those changes, resolve conflicts, and persist your data. This means that users returning to the document will always see the latest changes.