Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

All application logic is defined using routines. Routines are loaded on runtime and are passed a global event emitter instance, called the mediator.

##Example The following describes an application example structure.

Application objective: create a http server and serve a RESTful API (serves current music stations and the current songs for each station).

###File tree

  • src/ (contains source files)

    • bootstrap.js (initializes the application and loads routines)

    • config.js (contains environment-dependent project config, used by routines)

    • routines/ (the application logic routines loaded on runtime)

      • debug/ (outputs debug information to stdout)

        • server.js (outputs server debug information by listening to server events)
        • boot.js (outputs boot debug)
      • db/ (deals with storing and retrieving data from the database)

        • connector.js (connects with the db on boot)
        • stations/ (deals with stations storage and retrieval)
          • pop.js (stores new songs from the discjockey in the database and retrieves current songs on request)
      • stations/ (stations related routines)

        • provider.js (provides stations on request)
        • pop/ (the pop station)
          • provider.js (provides station info when received by db after a request)
          • creator.js (creates the pop station and emits its existence event)
          • discjockey.js (periodically searches for new songs to be picked up by the queue)
      • server/ (contains server related routines)

        • creator.js (creates the http server on boot)
        • configurer.js (configures the http server when created)
        • runner.js (runs the http server when configured)
        • routes/ (defines RESTful routes)
          • stations.js (answers /api/stations)
          • songs.js (answers /api/songs/station+name)
    • definitions/ (contains shared object definitions, used by routines)

      • station.js (defines what a station is, eg. name, nr of listeners, current song)
      • song.js (defines what a song is, eg. artist name, title and thumbnail url)
    • util/ (contains shared utility modules, used by routines)

      • moduleloading.js (contains module loading utilities)
  • test/ (contains unit tests)

  • node_modules/ (contains general node modules, used by routines and utils)

  • Makefile (contains project commands such as test and deploy)

  • package.json (contains project information and dependencies)

  • README.md (general project readme)

  • LICENSE (general project license)

###A note about working with the database Because the structure is completely event-based (with the exception for node modules, definitions and utilities), database interaction has to be thought of different, in a more intuitive chronological event based way.

The following describes a procedure from a client making a http request to receive a list of stations.

  1. client performs http request /api/stations
  2. server route stations receives request: mediator.emit('server.req.stations', req, res)
  3. stations database routine recognizes this request, collects stations from db and: mediator.emit('db.stationsreceivedonreq', req, res, stations)
  4. stations provider recognizes this event and provides data to http client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment