Only design principle to rule them all.

Only design principle to rule them all.

October 30, 20245 min read


Design principles play a crucial role in guiding the flow of components within software products, ultimately making them easier to maintain over the long term. This process can be visualized as reducing a complex, multidimensional graph into a simpler 2D representation, ideally forming a tree structure without cycles. Many new design principles often complicate concepts that have been around since the 1970s, that is Independence and Composition, which are foundational to modular design. These allow for easy swapping of components, much like breaking a branch from a tree along with its child branches, making room for a new branch to grow.

Understanding Independence in Software Design

Independence emphasizes treating each component in a software system as a separate entity. Here are the main points:

The Power of Composition

Composition focuses on how independent components work together to create a cohesive system. Here are the key aspects:

Can They Fit Common Design Principles?

DRY (Don't Repeat Yourself)

Composability avoids repetition by combining independent components, ensuring that functionality is implemented only once.

KISS (Keep It Simple, Stupid)

Independence ensures that components remain simple and focused on their single responsibility, while composability helps abstract away unnecessary complexity.

SOLID Principles

Deployment Architecture

Modular Monolith

Modular Monolith

A monolith barely has any constraints, allowing the application of both Independence and Composition principles, enabling a modular system where components are swappable at each level.

Compared to traditional monolithic architectures, modular monoliths facilitate an easier transition to microservices when necessary. Each module's independence means it can serve as a candidate for future microservices without significant rework.

Microservices

Similar to a modular monolith, this architecture utilizes APIs for interactions rather than direct function calls. This setup allows a team to work on and deploy their service independently while removing technology stack-related constraints.

Unless for a local-first product, the database management system (DBMS) should preferably be independent from the rest, even for monoliths. This independence facilitates the easy expansion of services from existing data and allows for independent auditing and changes according to future requirements.

Organizational Design

These are the guidelines for organizing the codebase. Let's explore the popular Clean Architecture.

Clean Architecture

Notice how different layers are represented in various colors, as you move from the outer levels toward the center, the degree of composition decreases while independence increases. Also, components that belongs to same layers are independent of each other. Other designs like Hexagonal and Onion architecture are also related to these concepts.

Conclusion

In the end, by maintaining a tree-like modular structure at each level, while balancing independence and composition, we create a system that is both resilient and flexible.

Should we follow the tradtion and name a new Architecture? How about The Tree Architecture?