If I understand your app correctly, you have docs that look something like this:
{
"_id": "event-{timestamp/name/something}",
"organizer": "alice",
"attendees": [
"alice", "bob", "charlie"
]
}
If that's roughly right, then I'd propose the following architecture to make it work with PouchDB & CouchDB's replication.
The goal here is to "cut with the grain" of CouchDB's replication protocol, compartmentalize permissions into containers (database-per-user and database-per-share/relationship), and provide a latent-friendly sharing/distribution model...because the cloud goes away sometimes. ;)
In the flowchart below, you can see Alice's "device" (or app, etc) on the left. Alice keeps events in a private-user-space
database. Any event document (like the one above) with attendees on it, gets copied (possibly via a background, filtered replication process) to share databases based on the user identifiers used in the attendees
key (or however you model your stuff).
Each of those share-with-*
database is continuously (ideally) replicated to a cloud-hosted (most likely) CouchDB (or compatible) database. Bob and Charlie have their apps connected to the same cloud-hosted CouchDB (or compatible) database, and get Alice's event replicated into their share-with-alice
database.
The app then provides those events to Bob and Charlie, let's them make their edits, replicates those changes back to the share-with-alice
database, and then (eventually; because network) back up to the cloud and back to Alice.
In all of this, the cloud bit is optional. ;) Depending on the deployment these could be three devices on the same network finding each other someway or other and replicating as available.
From what I understand of your app, this should work. :) You mentioned that there are other comment documents also, and they'd need to be modeled in a similar way--or the app would leverage their relationship with the event document to do the Right Thing with the related comments.
I'd be very curious to know if this sounds like a possible path as I'm exploring it myself for a few projects.
Hope something in there's helpful regardless. :)
share-with-*
databases also do an unfiltered replication back to theprivate-user-space
db? If so, this actually seems like a great design. Should work well with PouchDB. :) Although a downside is that you're duplicating a bit of data on the client side, the upside is that replication is super clear and straightforward. – Pulvinate