Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created November 13, 2011 11:49
Show Gist options
  • Save Raynos/1362025 to your computer and use it in GitHub Desktop.
Save Raynos/1362025 to your computer and use it in GitHub Desktop.
Arch demo
// bootstrap starts the server, does shit
module.exports = function (app) {
var routes = readdirSync("/routes");
routes.forEach(function (name) {
require("/routes/" + name)(app);
});
// MOAR bootstrap
// init database connections
// configure server
app.listen(process.env.PORT);
}
// data object talks to database
var db = require("db");
module.exports = {
store: function () {
// store in db
}
};
// domain object does domain logic >_<
var data = require("../data/x.js");
function sanitize(..) {
}
var X = function (data) {
};
X.prototype.foo = ...
module.exports = {
create: function (data, cb) {
var data = sanitize(data);
data.store(data, function (err, result) {
cb(X(result));
});
}
}
// index is tiny
var bootstrap = require("bootstrap"),
app = require("socket.io");
bootstrap(app);
// Router takes incoming requests and puts them through wrappers
// It either sends info to data/domain or asks for information from data/domain
// it then puts them through the view layer before sending back to client
var x = require("../domain/x.js"),
view = require("../view/x.js");
module.exports = function (app) {
app.on("a", function (data) {
if (data.method === "POST") {
x.create(data.data, function (obj) {
app.emit("a", {
type: "create",
obj: view.create(obj)
});
});
}
// yada yada
});
};
// views transform data objects or domain objects into data that you want to send to clients.
// Use this to remove properties clients don't care about and minimize bandwidth
// Also use this to transform data objects into objects clients want to consume
module.exports = {
create: function (x) {
var o = {};
o["care about"] = x["care about"];
...
return o;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment