Permalink
Switch branches/tags
660/documentation-build-process first-timers-year fozy81-patch-1 fozy81-patch-2 gr2m-patch-1 greenkeeper/async-2.6.1 greenkeeper/async-pin-2.6.0 greenkeeper/browserify-pin-14.1.0 greenkeeper/good-8.0.0 greenkeeper/good-8.0.1 greenkeeper/good-8.1.0 greenkeeper/good-8.1.1 greenkeeper/h2o2-7.0.0 greenkeeper/h2o2-7.0.1 greenkeeper/h2o2-7.0.2 greenkeeper/h2o2-8.0.0 greenkeeper/h2o2-8.0.1 greenkeeper/h2o2-8.1.0 greenkeeper/h2o2-8.1.1 greenkeeper/h2o2-8.1.2 greenkeeper/hapi-17.0.0 greenkeeper/hapi-17.0.2 greenkeeper/hapi-17.1.0 greenkeeper/hapi-17.1.1 greenkeeper/hapi-17.2.0 greenkeeper/hapi-17.2.1 greenkeeper/hapi-17.2.2 greenkeeper/hapi-17.2.3 greenkeeper/hapi-17.3.0 greenkeeper/hapi-17.3.1 greenkeeper/hapi-17.4.0 greenkeeper/hapi-17.5.0 greenkeeper/inert-5.0.0 greenkeeper/inert-5.0.1 greenkeeper/inert-5.1.0 greenkeeper/lodash-4.17.1 greenkeeper/lodash-4.17.9 greenkeeper/nock-9.0.9 greenkeeper/nock-9.0.10 greenkeeper/nock-9.0.21 greenkeeper/nock-9.0.23 greenkeeper/nock-9.0.24 greenkeeper/nock-9.0.25 greenkeeper/nock-pin-9.0.8 greenkeeper/nock-pin-9.0.22 greenkeeper/npmlog-4.0.1 greenkeeper/proxyquire-2.0.0 greenkeeper/proxyquire-2.0.1 greenkeeper/rc-1.2.4 greenkeeper/rc-pin-1.2.3 greenkeeper/request-2.83.0 greenkeeper/request-2.84.0 greenkeeper/request-2.85.0 greenkeeper/request-2.86.0 greenkeeper/request-2.87.0 greenkeeper/request-pin-2.82.0 greenkeeper/request-pin-2.83.0 greenkeeper/semantic-release-15.0.0 greenkeeper/semantic-release-15.0.1 greenkeeper/semantic-release-15.0.2 greenkeeper/semantic-release-15.0.3 greenkeeper/semantic-release-15.1.2 greenkeeper/semantic-release-15.1.3 greenkeeper/semantic-release-15.1.4 greenkeeper/semantic-release-15.1.5 greenkeeper/semantic-release-15.1.6 greenkeeper/semantic-release-15.1.7 greenkeeper/semantic-release-15.1.8 greenkeeper/semantic-release-15.1.11 greenkeeper/semantic-release-15.3.0 greenkeeper/semantic-release-15.4.1 greenkeeper/semantic-release-15.4.2 greenkeeper/semantic-release-15.4.3 greenkeeper/semantic-release-15.4.4 greenkeeper/semantic-release-15.5.0 greenkeeper/semver-5.5.0 greenkeeper/semver-pin-5.4.1 greenkeeper/tap-12.0.0 greenkeeper/tap-12.0.1 greenkeeper/yargs-8.0.1 greenkeeper/yargs-9.0.1 greenkeeper/yargs-10.0.3 greenkeeper/yargs-10.1.1 greenkeeper/yargs-11.0.0 hoodie-client-legacy legacy master
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (40 sloc) 2.13 KB

How Hoodie Works

Hoodie has several components that work together in a somewhat atypical way to deliver our promise of simplicity, out-of-the-box syncing, and offline capability.

Everything starts in the frontend, with your app. This is your user interface, your client side business logic, etc.

1.jpg

The app code only talks to the Hoodie frontend API, never directly to the server-side code, the database, or even the in-browser storage.

2.jpg

Hoodie uses PouchDB for storing data locally, which uses IndexedDb or WebSQL, whatever is available. Hoodie saves all data here first, before doing anything else. So if you’re offline, your data is safely stored locally.

3.jpg

This, by itself, is already enough for an app. But if you want to save your data remotely or send an email, for example, you’ll need a bit more.

Hoodie relies on CouchDB, the database that replicates. We use it to sync data back and forth between the server and the clients, which is something that CouchDB happens to be really good at.

4.jpg

A small aside: In CouchDB, each user has their own private database which only they can access, so all user data is private by default. It can be shared to the public if the user decides to do so, but it can’t happen by accident. This is why we’ll often mention sharing and global data as a separate feature.

Behind the database, we have the actual server code in the form of a small node.js core with various plugins running alongside it. These then act upon the data in the CouchDB, which then replicates the changes back to the clients.

5.jpg

So Hoodie does client ↔ database ↔ server instead of the traditional client ↔ server ↔ database, and this is where many of its superpowers come from.

The clever bit is indicated by the dotted line in the middle; the connection between clients and server can be severed at any time without breaking the system. Frontend and backend never talk directly to each other. They only leave each other messages and tasks. It’s all very loosely-coupled and event-based, and designed for eventual consistency.