Assume I'm working on a JavaScript application and make extensive use of the module pattern with one file per module. Now suppose I have two folders/modules: one for module A and another for module B. Module A uses module B, and B is not used by any other module. Should I put B inside of A, or should they be equals? What are the advantages/disadvantages of each decision?Should I do this...AB (only used by A)... or this ...AB (only used by A)I'm looking for an answer that lists the benefits/tradeoffs for each option.Here's a starting point based on my experience:A containing BBenefits:The most intuitive/common decisionEnsures the location of B is immediately apparent (really, this isn't that hard either way) - no digging through lots of modules in project rootTradeoffs:Doesn't encourage developers to think of B as a standalone module, often leading to excessive couplingWhen making changes, it's easier to overlook an existing module that can be reused with minimal effort (because it's nested inside of a subfolder)With modern JavaScript, I think the tradeoffs outweigh the benefits, but I may be missing something. I'm hoping to find some kind of universal truth  maybe even one that can be applied to similar concepts (like packages, DLLs, namespaces, etc.).
When should I nest one module inside another?
javascript;architecture;project structure;modules