Interest in using the sync library for other projects

Is it possible to use the synchronization logic as a library in other projects?

I am thinking about a few projects that would benefit from a simple, synchronized document-oriented store. The API would work similarly to Firebase, where you read and write documents at file paths. The library would take care of syncing the local documents with the remote ones and inform you through events about changes to folders you subscribe to. As backends I would imagine file storage like Dropbox and Nextcloud, and possibly Git or actual databases.

Joplin practically already implements something like this, so I am interested to hear whether you think it's possible to build on that work? Is there interest in extracting such a library? If this functionality cannot be embedded outside of Joplin, what are the parts of the code that would be interesting when attempting to write such a library?

It's all in the @joplin/lib package, although I don't know how easy it would be to use the same logic elsewhere.

Thanks for the pointer!

For studying the logic, is joplin/Synchronizer.ts at dev · laurent22/joplin · GitHub a good entrypoint?

Yes that would be a good entry point. You might also want to check BaseItem.ts (search for "sync" in there as it shows how items are retrieved and serialised). Also all the file-api-driver-* to check how the I/O is done. file-api-driver-memory, used in unit testings, would be the simplest one.

Thank you! :slight_smile:

Have you considered using an existing library, like CouchDB, for instance?

However, if you still decide to re-implement Joplin's sync, it may also be useful to run Joplin desktop in debug mode and see what requests it sends to the sync target and what it gets back.

Thanks, I didn't know about CouchDB.

From a first look, it seems that CouchDB requires a server running, which doesn't fit my use case. But there is PouchDB which can run in the browser, so that seems like a decent fit. Unfortunately, it seems that it doesn't currently sync to Dropbox or the like, so I'd have to investigate how that could work.

But thanks a lot for the pointer!