LukeSwart/ecometrix_site-api — pull request #1 by LukeSwart (2014-07-01 02:42:16+00:00)
Title: Code review for Ecometrix MVP

Hi Mike,

Here's a pull request covering the site, app, and API as we discussed this morning. I should also have the corresponding sequence diagram ready for our meeting tomorrow or Wednesday for you to review as well. I think the diagram can be reviewed separately, but I'll post a draft on the repo.

Just to clarify, here is an outline of the API and app interaction, which provides sessions management and content update services:

### Session Management
The session management is handled by the `userlist` and `sessions` collections on our server side database. Session management is initiated by the app by `app_login.js`, which uses the following calls to the `login` router:
* **adduser:** When the new user form is filled, this POST request to `userlist` to insert a new user and update the corresponding session in `sessions`. Note that sessions are created automatically by MongoStore, and we are also appending `username`, `isLogged` (the number of times user has logged in), and `token` (the md5 hash of the current time and username).
* **verify** This is a GET request from `userlist` to service the existing user login scenario. The router receives the request and checks the username and password from the `userlist` collection. Upon verification, we update the `sessions` collection with a new token that was generated at the time of the request.
* **resumeSession** This is a GET request from `sessions` to determine whether a session matching the request's session username exists. The read query is handled by MongoStore, so we just use the wrapper to check for an existing username via `req.sessions.username`.

### Content Update
Eventually this will include progress updates as well. All content updates are initiated by `app.js` and directed to the `posts` router by requesting the **posts/index** for each batch of questions, where "index" determines which batch of questions to return. The `posts` router is currently storing all of our questions in JSON, although we may start storing the JSON content in another location, such as `Firebase io` or another location that we discussed.

### Next steps
Sorry for the long description, but let me know if it can be improved in any way. Here are some next immediate steps after this code review:
* Before we reach our "triage-able" MVP, I believe the only thing left to add is meaningful content. I will send you the GoogleDoc soon.
* I also think that the description and diagram (which I will post tomorrow or Wednesday) may be useful to explain the backend service related aspects for any upcoming MVP demos. I will work on this and it can be reviewed separately.