I've been freelancing for 5 years now and have completed more than 20 projects for about 10 clients. The projects are mostly large and long-term. I needed to come up with an approach that would allow me to use logic from one project to another. I also needed to be in the context of each project without spending a lot of time recalling logic and architecture. The best way to solve the above problems was the modular architecture that my colleagues and I came up with on one of my first projects and later improved and tested by me on other web applications. In this article, I would like to talk about the module's structure as the modular architecture's main part. This will help you understand the essence and benefits of this approach.

Module Structure

For this example, I'm using React and TypeScript, but the modular architecture can also be used with other frameworks.

Example Folder Structure:

src/
  modules/
    user-management/
      UserProfile/
        UserProfile.tsx
        UserProfile.module.css
        index.ts
      slice.ts
      types.ts
      api.ts
      index.ts
  components/
    Button/
      Button.tsx
      Button.module.css
      index.ts
  pages/
    Users/
      Users.tsx
      Users.module.css
      index.ts

You can put any other files into your modules, I just highlighted the most important ones to show you the basic idea. The main benefit of the module architecture is that it is very simple. The complexity here is to logically divide your application into modules, which should be also domain-related.

Module names shouldn’t have technical names, it should be understandable for the client. Modules can use global context, like env variables, CSS variables, and data from other modules through state management systems like redux.