-
Notifications
You must be signed in to change notification settings - Fork 0
Sails to Express Design Decisions
Repo: github.com/dropofwill/SpaceIntentionally-LeftBlank
Server Heroku: storm-server-fun.herokuapp.com/
Client Heroku using our updates: stormclientprime.herokuapp.com/
/api
/constants
/controllers
/handlers
/middleware
/models
/services
app.js
dispatcher.js
event-stream.js
routes.js
/test
/unit
index.js
Operations that take place in a room are handled over Socket.io in realtime, everything else happens over a RESTful HTTP API. To decouple the business logic from the transport layer we made our socket handlers be triggered by an internal event emitter stream. To ensure the correct listeners get invoked all event identifier strings are stored in a constants object that is passed to the client for use.
Routing is being handled by Express-Enrouten from Paypal allowing our controllers to be thinner and better organized. Commonly used actions are stored in services and shared across handlers and controllers.
To prevent the services from bloating, as well as lowering our coupling, model focused actions have been moved into the models themselves as static methods.
We use Babel to get the latest ES6 features, as well as ESLint with a slightly modified version of Airbnb’s configurations. Mocha is being used as the testing framework, however as of now only the IdeaService tests have been converted over.
The Mongoose library was utilized to interface with our Mongo database. The Board model contains any information directly related to a Board including Users, Admins, and name. However, Ideas and Idea Collections are stored separate from the Board to reduce nested associations which can complicate and add bulk to queries later on. A generated unique string serves as a board id used to link Ideas and Idea Collections to their respective boards. Due to lacking an explicit association cleanup of Ideas from a deleted Board is left to us and is handled in a post remove hook. Pre and post hooks on saves helps to ensure more complex validation in Mongo. Statics were also used to help simplify actions that previously existed in services.