The Vertical Codebase

The blog post advocates for a vertical codebase structure, emphasizing organizing code by domain rather than type. This approach, also called domain-driven design, aims to enhance scalability and reduce cognitive load.

Horizontal vs. Vertical Structure:

  • The conventional horizontal codebase organizes by components, hooks, types, and utilities. This can result in a lack of cohesion and high coupling, with related files scattered, making navigation challenging.
  • A vertical structure groups all related code into one folder based on functionality, improving discoverability and cohesion.

Benefits of Vertical Structure:

  • Code colocation ensures that elements which change together are located together, simplifying maintenance and updates.
  • Aligning code organization with product teams improves domain ownership and aligns development processes.
  • Vertical grouping aligns with feature teams, enabling dedicated spaces for team-specific code.

Implementation in Practice:

  • Evaluate code functionality to determine logical groupings, such as features or routes (e.g., dashboard or widgets).
  • Shared code, often a concern, can be grouped by its own vertical if it crosses domains, ensuring clear ownership and accessibility.

Addressing Boundaries:

  • Define public interfaces within each vertical to establish which parts are accessible externally, minimizing unintended dependencies.
  • Employ tools like eslint-plugin-boundaries and encapsulate verticals in separate packages if using a monorepo, enforcing boundaries and dependencies rigorously.

Challenges:

  • Identifying suitable verticals requires thoughtful consideration and can be complex.
  • Maintaining private code sections may lead to redundancy, necessitating increased inter-team communication.

Conclusion:

The author encourages adopting vertical structures for scalable codebases, acknowledging the inherent challenges of implementation but asserting the long-term benefits for maintainability and team alignment.

Visit

Do you like my content?

Sponsor Me On Github