Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pertio's avatar

Best way to think about modules in JavaScript?

Ok so I understand you’re supposed to follow SOLID principles and that objects in JavaScript are supposed to have only one responsibility. I also understand that it’s best practice to modularize these objects. But does EVERYTHING need to be contained in modules? If you’re creating a complicated website with a lot of moving parts and EVERY single piece of functionality has to go in its own module won’t that created a very convoluted code base ?

0 likes
1 reply
nexxai's avatar

There's no right answer here. Yes, you want to follow SOLID principles, but you also don't want to prematurely optimize your codebase. The idea of splitting out functionality is to make it more easy to maintain and reason about later, but that doesn't mean you need to go balls to the wall from day 1.

Long story short: yes, things should be modularized, but only so much as the complexity of your application in its current form demands. If it's a simple app, simple modularization probably makes sense. If it's a giant application, you should spend more time considering how you can split things out that make sense.

Please or to participate in this conversation.