We already have an existing mobile application which is based on a relational database. Let’s say the database structure goes as
where One Organization has Many Employees who have many Attendance Records, Mark Records etc.
There was an existing rest service to authenticate the user.
Another thing to note is that the existing mobile application works online only.
We are planning to rewrite this application using ionic (hybrid framework on top of cordova) and pouchdb
Initially we looked at couchdb, we looked at creating a database per organization where we store all the data related to that org in its own database.
If I give an overview of the architecture we thought about with couchdb it goes like this
User logs in to the system through a rest API, in that rest API it calls another external REST API to authenticate, after authentication it checks if any roles necessary to use the app are available, if so it checks if there is a database already created for the organization, if not create it. Return a token to the user with the organization Id. The user connects to the database using the organization Id and normal sync resumes.
If we were to use the sync gateway how would this be done.
How could we handle authentication from a separate custom service? Should we create a new user locally on couchbase if it does not exist, etc?
Do we create a channel for every organization? If so we have multiple document types, does this mean EACH record should have a organization id even though some entities are part of the organization. (e.g. - Employee belongs to only one organization and Marks belongs to one employee, using this we can trace the orgaization Marks belongs to but how without having redundant organizationIds)? (Note that in documents per organization database structure did not have this problem because everything was already isolated by organization)
We also have roles on top of limiting data per organization, how would this happen?
We might have a scenario in the future where there is a backend calculation that happens. In one of our other apps it goes like this, user saves entity, in the entity backend save service the values of the entity are used to do a calculation and adds that value to the entity before it is saved. NOW this can be done by exposing a rest web service to the calculation but what happens when the user is offline? The web service won’t be called, we can make it so that when the user comes back online the rest service is called, but what if its down at that time, do we have to then implement retry logic? Sounds too much to me, managing state, IF service was called, etc. Is it a good practice to do this in the Sync function?
Essentially what we are looking for is what would be the RECOMMENDED general architecture for this.