Frameworks can help in this situation to some extent, but if going frameworkless is okay for you, Francesco Strazzullo's book "Frameworkless Front-End Development" did an excellent job of explaining what, why, and how to organize a js codebase without using external codebase, at least it did for me.