Modules (./src/modules) need to be refactored.
We moved from a role-based architecture to a feature-driven one in #5.
However, since that wasn't the main focus of that PR, modules implementation is not really complete.
Those two principles are important when it comes to modules:
- Low coupling: it means that modules should be as independent as possible from one another, so that changes to one module have zero or minimal impact on other modules. Modules shouldn't have knowledge of the inner workings of other modules.
- High cohesion: it means that modules should comprise a collection of code that acts as a system. They should have clearly defined responsibilities and stay within boundaries of certain domain knowledge. Consider a sample ebook application. It might be inappropriate to mix book and payment related code together in the same module as they are two different functional domains.
Currently, modules are not properly isolated and any module can and does access any file of any other module with no strategy in mind.
So to work on this, the idea is to:
- implement an
index.js
file at the root of each module that
- only export the entities of the module that are meant to be public
- everything else should not be exported and not used in any other module
- the
index.js
file formally acts as the public interface of the module
- a module should exclusively interact with another module through its public interface
- keep in mind that, as JavaScript doesn't really offer a way to tweak the export and imports of modules, we don't have a way to enforce the rule that any other file outside of
index.js
is not allowed to be imported
EDIT: as for the last point, you can actually do that with npm packages, but for now I'm going to keep things simple.