Sunday, February 26, 2012

Domain Driven Design, Grocery Lists, and Node.js

To begin building this grocery list system, we need to first establish some of the baseline requirements and the domain model.  First, we have npmnvm, and the latest node environment installed.  Next, install jasmine node (this, with the latest version of npm, can be done via npm -g install jasmine-node, at least on a mac).  I'm also going to use Jake, which installs via npm as well.

Now that we have the requisite tools installed, we build the project directory.  I like to use a pretty common structure stolen from Ruby projects I've worked on in the past, with a the subdirectories bin, etc, lib, and test, with a README and a makefile of some kind at the top level of the directory structure.  The Item entity is pretty straightforward:


It defines an item with a name and a description. We may elaborate on this in the future, but it's fine for now.

Likewise, we're going to use a named collection of objects:

The idea behind this simple collection is that folks will want to name their lists, and so we've provided a way for a JavaScript array to be named. Next time, we'll go over the tests in place to exercise these objects, and we'll delve into the command line interface. Eventually, we will host this service on Heroku, and initially at least we'll access that service via the command line interface we develop.