tl;dr; We should both standardize the directory layout of stex for both "model" and "controller" files and automatically load them at stex initialization
Problem
The CommonJS model for adding module dependencies is nice for being explicit about inter-module dependencies and has overall led to much better javascript code. However, it can lead to very large sections of "require" blocks at the top of each file that can distract from the function of the module, and more importantly it leaves each module the freedom to name the symbols that it imports, leading to naming inconsistencies:
// in module 1:
var wallet = require('wallet');
// in module 2:
var Wallet = require('wallet');
Furthermore, within a single node project you are forced to use relative requires, leading to friction when you restructure your project or rename a file:
// when in a sibling module
var wallet = require("./wallet")
// when in a child module
var wallet = require("../wallet")
Proposal
There exists a set of modules within a stex application that are used quite often throughout nearly all the other modules in a stex application: the "models" and the "controllers". By automatically loading these files we will reduce duplication and increase clarity. I propose we automatically load files underneath /lib/controllers and /lib/models. For example, the routes file (app.js) could go from this:
var walletsCtrl = require("./controllers/wallets")
var totpCtrl = require("./controllers/totp")
var recoverCtrl = require("./controllers/recovery")
router.post("/v2/wallets/create", walletsCtrl.create);
router.post("/v2/wallets/update", walletsCtrl.update);
router.post("/v2/totp/enable", totpCtrl.enable);
// etc.
to:
router.post("/v2/wallets/create", stex.controllers.wallets.create)
router.post("/v2/wallets/update", stex.controllers.wallets.update)
router.post("/v2/totp/enable", stex.controllers.totp.enable);
// etc.
tl;dr; We should both standardize the directory layout of stex for both "model" and "controller" files and automatically load them at stex initialization
Problem
The CommonJS model for adding module dependencies is nice for being explicit about inter-module dependencies and has overall led to much better javascript code. However, it can lead to very large sections of "require" blocks at the top of each file that can distract from the function of the module, and more importantly it leaves each module the freedom to name the symbols that it imports, leading to naming inconsistencies:
Furthermore, within a single node project you are forced to use relative requires, leading to friction when you restructure your project or rename a file:
Proposal
There exists a set of modules within a stex application that are used quite often throughout nearly all the other modules in a stex application: the "models" and the "controllers". By automatically loading these files we will reduce duplication and increase clarity. I propose we automatically load files underneath /lib/controllers and /lib/models. For example, the routes file (app.js) could go from this:
to: