Lesson 2

Application Requirements

Discussing the requirements for the application

PRO

Lesson Outline

Application Requirements

Throughout this module, we will be creating an application called Hangz that will provide a space for users of the application to post onto a shared notice-board (for things like upcoming events) and it will also provide a live chat feature so that the entire group can chat to each other.

This is a very high-level description, and we're going to need to drill down into some lower level details before we start building this thing. Let's establish some high-level goals for the application.

  • Users can post notices to a shared notice-board
  • A notice must contain a title, and can optionally contain a description
  • Only the user who created a notice should be able to edit or delete it
  • Users can participate in a live chat room with all other users of the application
  • A chat should contain a message, and each message should be attributed to the author
  • Only registered and authenticated users should have access to the application
  • If a user has previously logged in, and they have an unexpired token, they should be automatically logged in when returning to the application
  • Users should have offline access to the data in the application that syncs when online

Most of these goals are quite straightforward, and overall it is a reasonably simple application. However, the last point:

  • Users should have offline access to the data in the application that syncs when online

has the potential to be quite a bit more complicated. We will be using a method that will greatly reduce the difficulty of implementing this kind of functionality, but I want to talk a little about why we would want to implement that.

Let's imagine a scenario that would justify offline data access with online syncing as a requirement. This is an application where the intent is for a group to chat and organise places to hang out. A person could be using the application and see a post from their friend that there is a party a few blocks over that they are headed to. They jump in their car and start driving, when they arrive at the street they realise they don't know which house it is. They open up the Hangz application only to find that nothing loads, they don't have a Wifi connection or any data on their phone plan, which renders the application useless.

If we add functionality to the application that allows access to previously loaded data whilst offline, that person would still be able to view the address within the application and make their way promptly to the party. Then the other side of this is, what if they want to also post a message back to the app whilst offline? Maybe they wrote out a list of their song suggestions for the party without realising that they didn't have an Internet connection. If we set this up properly then that person can still send that message even though they don't have a connection, and it will just sync to the remote database the next time that they do have a connection.

This type of functionality is expected of a lot of applications these days. Where possible, an application should continue to function as much as possible even when no Internet connection is available. It's easy to just add a blanket "Sorry, no Internet access. Try again later." statement, but that does not provide a good user experience. Another good example is to think of a note taking application like Evernote - imagine if you couldn't access any of your notes without an Internet connection, that would be quite annoying.

However, handling this online/offline data syncing situation can be quite a complex task, there are many factors to consider such as:

  • How do we keep track of what local data has and has not already been synced to the remote database?
  • When do we trigger the syncing process? How often do we do it?
  • How do we tell if both the remote data and the local data has been modified at the same time, creating a conflict?
  • How do we handle these conflicts?

As we build the application, you will quickly see why CouchDB and PouchDB are such appealing technologies for this situation. All of this is built into CouchDB directly, and implementing it in an application requires almost zero effort.

Summary

This should give you a basic outline of the goals we have for this application and the approach we are going to take to build it. In the following lesson, we will be walking through the finished application in detail on video for a little more context.