Y-Sweet and Your App
A minimum viable app with Y-Sweet just needs these three components:
- A server that makes HTTP requests to 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 that don't require authentication, a Y-Sweet app that follows this structure is all you need.
If you're building with Nextjs, your server and client will server
and client
will refer to the server-side and client-side 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...
- Your server will make an authenticated request to the Y-Sweet API using
getOrCreateDoc
orgetClientToken
. Both these functions require aconnection string
to authenticate your request. getOrCreateDoc
orgetClientToken
will return aclient token
.- Your client will use this
client token
to connect to the Y-Sweet server via a websocket connection that's managed on the client-side byYDocProvider
. - 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.