module.exports = function (config, next) {

  require('../db')(config, function (err, client) {

    if (err) { return next(err); }

    var messaging = require('../db/messaging')(config);
    var keyspace = config.keyspace || 'seguir';

    // TODO: Refactor out into iteration over array of modules
    var auth = require('./auth');
    var common = require('./common');
    var user = require('./user');
    var post = require('./post');
    var like = require('./like');
    var feed = require('./feed');
    var friend = require('./friend');
    var follow = require('./follow');
    var migrations = require('../db/migrations');

    var api = {};
    api.client = client;
    api.config = config;
    api.messaging = messaging;

    // Auth and migrations both run on core keyspace
    api.auth = auth(keyspace, api);
    api.migrations = migrations(keyspace, api);

    // Other APIs get their keyspace with each api request
    api.common = common(api);
    api.follow = follow(api);
    api.feed = feed(api);
    api.friend = friend(api);
    api.like = like(api);
    api.post = post(api);
    api.user = user(api);

    next(null, api);

  });

};

@@ -1,12 +1,41 @@
+var path = require('path');%0A%0A
 module.expor
@@ -211,24 +211,25 @@
 onfig);%0A
+%0A
     var 
 keyspace
@@ -224,425 +224,189 @@
 var 
-keyspace = config.keyspace %7C%7C 'seguir';%0A%0A    // TODO: Refactor out into iteration over array of modules%0A    var auth = require('./auth');%0A    var common = require('./common');%0A    var user = require('./user');%0A    var post = require('./post');%0A    var like = require('./like');%0A    var feed = require('./feed');%0A    var friend = require('./friend');%0A    var follow = require('./follow');%0A    var migrations = require(
+api = %7B%7D;%0A    api.client = client;%0A    api.config = config;%0A    api.messaging = messaging;%0A%0A    var modules = %5B'auth', 'common', 'user', 'post', 'like', 'feed', 'friend', 'follow', 
 '../
@@ -423,500 +423,173 @@
 ons'
-);%0A
+%5D;
 %0A    
-var api = %7B%7D;%0A    api.client = client;%0A    api.config = config;%0A    api.messaging = messaging;%0A%0A    // Auth and migrations both run on core keyspace%0A    api.auth = auth(keyspace, api
+modules.forEach(function (module) %7B%0A      var moduleName = path.basename(module
 );%0A    
+  
 api
-.migrations = migrations(keyspace, api);%0A%0A    // Other APIs get their keyspace with each api request%0A    api.common = common(api);%0A    api.follow = follow(api);%0A    api.feed = feed(api);%0A    api.friend = friend(api);%0A    api.like = like(api);%0A    api.post = post(api);%0A    api.user = user(api
+%5BmoduleName%5D = require(path.resolve(__dirname, module))(api);%0A    %7D
 );%0A%0A

Make api initialisation more modular