Brunch-based project template with AngularJS on the frontend and a lean Express backend serving only JSON API endpoints. Largely a combination of Angular Express Seed and Angular Brunch Seed, with some explicit client/server separation and CoffeeScript.
For a discussion of the rationale behind the architecture, see http://cmme.org/tdumitrescu/blog/2013/11/lean-angular-express-architecture/.
I am making some changes to omit the coffeescript part for reading/learning purposes. I have already done plenty of mental parsing with clojurescript, so I am taking a break from that at the moment
Install in the current directory:
brunch new gh:tdumitrescu/fast-and-pointed-brunch
Run:
npm start
The app-specific code is divided into two main directories:
-
client/
: the AngularJS code which runs in the browser, along with stylesheets and view templates. The entry point of the Angular app is declared and configured inclient/app.coffee
, and further app code lives by default inclient/scripts
. -
server/
: the Express code which runs on the server with Node.js. The Express app is declared and configured inserver/server.coffee
. Code for JSON API actions lives inserver/api.coffee
.
The most significant particularity of this configuration is the enforced separation of (server-side) data and (client-side) presentation. The Express server does no view-rendering; it merely provides JSON API endpoints for the client. All HTML, CSS, and JS is pre-compiled by Brunch and served in static asset files. This includes all the Coffeescript, Jade, and Less files in client/
as well as vendored asset dependencies installed by Bower (such as jQuery and the AngularJS framework code).
In both client and server directories, the file structure is set up for a simple single-resource app. A more expansive app would benefit from further separation into resource-based subdirectories and modules (for example, splitting server/api.coffee
into server/api/widgets.coffee
and server/api/wombats.coffee
).
A simple blog using this template, based on an example by Brian Ford.
See the more extensive documentation of the parent projects: