| 4. Web Application Architecture

*edit 2* Due to a github discussion linked below, I'm no longer attempting this approach and will instead add an application layer to my architecture.

Previously I mentioned that I wanted to stick with the idea of a "CouchApp" despite it no longer being a recommended way to use CouchDB. Part of the reason is that working with the two-tier web stack idea of CouchDB makes creating "social media" applications particularly straightforward. To simplify and clarify the technical details from page 2, here's how:

You create a signup and authentication server which adds a user, gives them their own database in a CouchDB node and returns a cookie to allow access to their database.

As mentioned two sections ago, you enable SSL and other CouchDB security measures to prevent non-authorized users from accessing anything.

Users can then determine which other users (e.g. friends) can view their private database. For example, accessing a thread and, thus, being able to leave a comment. Important! It is this part of CouchDB that is severely problematic because per-document-access is a feature still being worked on and thus this entire idea cannot be put into production until said feature is rolled out. While on this topic, I personally have a proposal in the works to suggest applying the idea of CouchDB's "validate document update functions" feature to not just PUT requests but also to GET requests. Until I finish my write-up and submit I won't know the "why not?". *Edit* I've submitted my proposal and the discussion is here.

A central "all users can view" database holds shared resources--such as icons, libraries, plugins, etc--for access by script tags in HTML files served from individual databases.

Individual databases are initialized with an HTML file that references a dynamically generated JavaScript file which loads a PouchDB instance that connects to the individualized backing CouchDB database. Small binary attachments work fine for things like personalized profile icons.

Client-side, users are given UI tools to connect with friends (reflecting user access list), set privacy settings (reflecting DB validation and access functions) and create data in their database.

And that's it. See how simple that is? It makes it a very tantalizing idea to try out.

Here's a quick visualization from trusty MSPaint because words and pictures and all that ;)

Now for mocking up the flow of how my Chalk commenting web app will work.

Next.