Please vet my app architecture

65 views
Skip to first unread message

AG

unread,
Nov 19, 2015, 6:34:32 AM11/19/15
to PouchDB
Hi,

I'm planning an offline-first app with the architecture described below. I would like folks here to vet it for any gotchas. I'm new to offline-first/document stores, having largely worked with SQL for many years.

The environment
---
I'm designing a task management and logging app, with plugins. It will probably be packaged with chrome app framework, or electron shell -- so I'm targeting offline-first on a modern browser engine, with good leveldb support.


The problem
---
So let's say various presidents are my users -- these are the top level objects. They will use my app to track their minister meeting appointments, take meeting notes, plan diplomatic missives on those meetings, track incoming money and expenses, build budgets, and attachments. Largely they deal with ministers. 

Oh, and their secretaries can access their account as well, and make changes -- from a different computer.

Proposed app architecture
---
The app will locally have a pouchdb with the recent 1 month of data. It will sync with the remote couchdb instance which will have individual dbs per user.

Schema:

Well not really scheme, but there will be 1 database of ministers (and properties like email, DOB, etc).

There will be a second 'interactions' db which will have entries with interaction type ('meeting', 'expense', 'attachment') and a foreign key pointing to the minister id.

A third 'attachments' db will be used to push files to s3, and store the md5 here. These attachments also can be added via the id to the interactions table.

On the UI front, ministers will be front and center, and all allowed actions will be on a minister. Once you've searched for a minister, you see all the interactions related to the minister. Without internet, you will be able to browse the past month of interactions.. and if any attachments are cached, they will be available.

Another big thing in the UI would be the appointment calendar. I'm not sure if I need to split appointment entries into their own db -- since otherwise I'd have to go through all the interactions with type 'meeting' and draw the calender. Perhaps a view on the interactions db would be sufficient?

Questions
---
So given above, I'd like to ask the following:

1) Is it possible to only sync the past month of data from couch into pouch. Would things work fine as I sync back from pouch one-month to couch all-time? Or would I have to do a per month db on couch too?
2) I'd like only the president to be able to merge any conflicts in documents, and moderat the changes by secretaries, but not vice-versa.
3) Is there anything I'm missing? Does the nature of the problem lend itself to pouch/couch, or should I be looking at a different solution? My main reason for couch/pouch is the offline/online sync, so presidents in bad internet connection are still able to use the app.
4) Are there sample apps close to anything I have in mind out there that I could look at?

Thanks,

Nolan Lawson

unread,
Nov 21, 2015, 1:18:55 PM11/21/15
to PouchDB
Hi AG,

Cool, that sounds like a really awesome app! :) Please see my comments below.


On Thursday, November 19, 2015 at 6:34:32 AM UTC-5, AG wrote:
Hi,

I'm planning an offline-first app with the architecture described below. I would like folks here to vet it for any gotchas. I'm new to offline-first/document stores, having largely worked with SQL for many years.

The environment
---
I'm designing a task management and logging app, with plugins. It will probably be packaged with chrome app framework, or electron shell -- so I'm targeting offline-first on a modern browser engine, with good leveldb support.


The problem
---
So let's say various presidents are my users -- these are the top level objects. They will use my app to track their minister meeting appointments, take meeting notes, plan diplomatic missives on those meetings, track incoming money and expenses, build budgets, and attachments. Largely they deal with ministers. 

Oh, and their secretaries can access their account as well, and make changes -- from a different computer.

Proposed app architecture
---
The app will locally have a pouchdb with the recent 1 month of data. It will sync with the remote couchdb instance which will have individual dbs per user.

Schema:

Well not really scheme, but there will be 1 database of ministers (and properties like email, DOB, etc).

There will be a second 'interactions' db which will have entries with interaction type ('meeting', 'expense', 'attachment') and a foreign key pointing to the minister id.

A third 'attachments' db will be used to push files to s3, and store the md5 here. These attachments also can be added via the id to the interactions table.

On the UI front, ministers will be front and center, and all allowed actions will be on a minister. Once you've searched for a minister, you see all the interactions related to the minister. Without internet, you will be able to browse the past month of interactions.. and if any attachments are cached, they will be available.

Another big thing in the UI would be the appointment calendar. I'm not sure if I need to split appointment entries into their own db -- since otherwise I'd have to go through all the interactions with type 'meeting' and draw the calender. Perhaps a view on the interactions db would be sufficient?

Questions
---
So given above, I'd like to ask the following:

1) Is it possible to only sync the past month of data from couch into pouch. Would things work fine as I sync back from pouch one-month to couch all-time? Or would I have to do a per month db on couch too?

Unfortunately since we don't have purge() implemented yet, you would have to try a few different workarounds for this case. One-db-per-month is a possibility; another is to periodically do a filtered replication between two local PouchDBs, and then destroy the source PouchDB when you're done. (Local-to-local replication is totally possible with PouchDB.)
 
2) I'd like only the president to be able to merge any conflicts in documents, and moderat the changes by secretaries, but not vice-versa.

You can use CouchDB permissions for this; give the president a special role and only allow that role to do certain operations. In this case it's a bit tricky because his permissions involve two things: 1) "blessing" certain documents with a certain status (published? visible?) and 2) resolving merge conflicts.

For the first one, I would advise having a member property on the document (e.g. "published": true) and only allowing the president to set that boolean to true, which you can accomplish with validate_doc_update on the server side.

For the second one, it's *much* trickier, because "resolving a conflict" can mean many different things - deleting the conflicting leaf node? Merging two conflicts together and producing a second one? Perhaps you could give the president the ability to be the one to add "_deleted": true, but for a generic "only this person can resolve merge conflicts" feature, you might have to write a lot of very tricky code.
 
3) Is there anything I'm missing? Does the nature of the problem lend itself to pouch/couch, or should I be looking at a different solution? My main reason for couch/pouch is the offline/online sync, so presidents in bad internet connection are still able to use the app.

For collaborative offline document editing, I think CouchDB/PouchDB are quite good. You may also want to check out Apache Wave: https://en.wikipedia.org/wiki/Apache_Wave
 
4) Are there sample apps close to anything I have in mind out there that I could look at?


No open-source ones that I'm aware of, sorry.
 
Thanks,

Cheers,
Nolan
Reply all
Reply to author
Forward
0 new messages