I am building an Electron note-taking app to yjs with the following capabilities:
- Offline-only support where all notes are stored on disk
- “online mode” option: If a user opts-in to “online” mode, they can access their notes from anywhere.
- Share option to enable collaborating on notes with others. For example user A shares note N1 with user B in read-write mode and note N2 in read-only mode. Meanwhile, note N3 is private to A.
Yjs seems to be a really good fit for the collaboration part, however I’m having trouble figuring out some important details about local storage and syncing.
I’m considering the following setup:
-
There’s central server that acts as “gatekeeper” for user accounts and authorization/permissions.
-
The server also acts as yjs peer for shared notes.
-
In “online” mode, user’s notes are shared with the central server over y-websocket.
-
In order to share notes, encrypt user’s notes with public/private key and give out/revoke keys for shareable notes from the central server.
-
Offline mode does not require any servers or any web connection, ever
I’ve done a similar app in the past (with firebase+firepad), and know that typical users have upwards of 1000 notes stored. 2-3K notes is typical after a year of using the app. Notes are usually <1K in size.
How would I go about:
-
Supporting offline-only: writing notes on disk?
I read through yjs/yjs: Peer-to-peer shared types#Document Updates and it seems like I can usedoc.on('update' ,...)
and write the updates for a note to append-only file on disk. Is this the recommended way to persist the notes? I’m thinking one file per note currently. I looked at yjs/ydb: A distributed database for Yjs documents (github.com), however it seems deprecated. -
Syncing thousands of notes effectively?
I assume that if I put each note in a separate yjs document, using something like y-websocket to sync 1000+ notes will be slow or open too many connections from the electron app or cause other issues. If I put all notes in a single doc somehow, I’m not sure how to do sharing at a note level - does YDoc have ability to share (encrypt) only parts of it?
Any pointers are much appreciated! Thanks a lot for reading and for your help!