iTranslated by AI
Principles and Methods for Building a Product-Specific Architecture [Reading Log]
Q. Why Do We Want to Build Good Architecture?
It is to minimize the number of people required to build and maintain the system. If the architecture is not designed well, the system becomes harder to change over time and also harder to release.
Software should always be "soft." In other words, software that is hard to change is dangerous. Architects have a responsibility to keep the system soft so that it can be continuously developed and operated.
Universal Principles for Building Good Architecture
Regardless of the product, following the steps below keeps the system in a soft state:
- Consider the purpose of the architecture (e.g., "keeping options open," "emphasizing use cases")
- Create components according to SOLID
- Assemble an architecture that fits the purpose by following the three principles of component cohesion and the three principles of component coupling (described later)
- As the development phase progresses, shift the emphasis among the cohesion principles and let the architecture follow suit
Below is an example architecture of a fictional shopping app built according to the various principles.
Architecture of a fictional shopping app built according to the principles
From here, we will look at the three principles of component cohesion and the three principles of component coupling (SOLID is omitted here due to many existing references).
Three Principles of Component Cohesion
The following are the three principles for grouping components:
- Reuse/Release Equivalence Principle (REP): The granule of reuse is the granule of release.
- Common Closure Principle (CCP): Gather into components the classes that change for the same reasons and at the same times. Classes that change for different reasons or at different times should be placed in separate components.
- Common Reuse Principle (CRP): Don't force users of a component to depend on things they don't need.
The Reuse/Release Equivalence Principle is easier to understand by considering a violation. For example, imagine putting a utility class A and a domain model B into the same package and reusing them together. In that case, even if you want to update only utility class A to the latest version, domain model B would also be updated together. To avoid this, separately reused items should be separated so they can be released independently.
The Common Closure Principle is the "Single Responsibility Principle" at the component level. There should not be multiple reasons to change a component.
The Common Reuse Principle is very intuitive. If you depend on a component, you should depend on all classes in that component. Otherwise, changes to a class you don't depend on would still require redeployment, which should be avoided.
The Principles to Emphasize Change Depending on the Development Phase
These three principles conflict with each other, and it is impossible to fully satisfy all three simultaneously.
For example, if you emphasize the Reuse/Release Equivalence Principle and create many reusable components, you will likely violate the Common Closure Principle (because classes that change for different reasons end up in the same component). Conversely, if you strongly emphasize the Common Closure Principle, you may have to put similar changes into dozens of components.
In the diagram below, each side represents the cost incurred when the vertex not connected by that side is ignored.
Triangle representing the trade-offs among the three principles. Each side represents the cost of neglecting the opposite principle.
Of course, just because you cannot satisfy all three principles simultaneously does not mean you can ignore all of them. The important thing is to judge which principle should be emphasized in the current product. It is the architect's role to appropriately identify which principle to prioritize according to the development phase and to flexibly modify the architecture.
In fact, it is impossible to build the best architecture from the start. Aim to create a soft architecture that can be changed at any time according to the situation.
Emphasis on CCP in Early Development, REP in Mid-to-Late Development
There are general guidelines for which principles to emphasize, and to some extent, it does not depend on the product.
- Early development: The Common Closure Principle and the Common Reuse Principle are important.
- After development has progressed to a certain extent: The Reuse/Release Equivalence Principle and the Common Reuse Principle become important.
In the early stages of development, the application specifications are not stable, and it is not yet possible to judge "what can be reused." Therefore, the Common Closure Principle is more important than the Reuse/Release Equivalence Principle.
Conversely, in the later stages of development, efficiency suffers unless you enable reuse to reduce the number of components to which the same change must be applied. Thus, it becomes important to increase reusable components (of course, you must carefully judge what to reuse).
Three Principles of Component Coupling
- Acyclic Dependencies Principle (ADP) (Omitted here as it is self-evident)
- Stable Abstractions Principle (SAP): The abstractness of a component should be proportional to its stability.
- Stable Dependencies Principle (SDP): Components that are expected to change should not be depended upon by components that are hard to change.
Each component has stability, which refers to "ease of change and susceptibility to change."
- A stable component: Depended upon by many components.
- An unstable component: Depends on many components.
A "stable component" cannot be easily changed because changing it would affect many components. Conversely, an "unstable component" is easily affected because it has many dependencies.

In this diagram, the web server is unstable, making it easy to change. On the other hand, the price calculation service is stable, and changes affecting other components cannot be made easily.
SAP: Stability and Abstractness Should Be Aligned
A component's abstractness should be roughly equal to its stability. In other words, place highly stable components for high-level policies with high abstractness, and place low-stability components for low-level layers with low abstractness.
Architecture diagram where higher-level policy components are more stable.
In this diagram, the policy levels are as follows:
- Highest-level policy: Price calculation service (most closely related to business logic)
- High-level policy: Use cases
- Lowest-level policy: Web server
Correspondingly, the components are connected so that stability decreases from the price calculation service (highest) to use cases to the web server (lowest). This is the Stable Abstractions Principle.
SDP: Depend from Less Stable to More Stable
A component that is depended upon by a component that is hard to change becomes hard to change itself. Therefore, make sure that components you want to keep easy to change (such as UI) depend on components that are hard to change. (Stable Dependencies Principle)
Example of violating SDP
The diagram above violates SDP. It shows a high-abstraction component depending on a low-abstraction component, and a component that should be hard to change depends on a component that is prone to change. This leaves the business logic in a very unstable state.
Following SDP, the dependencies should be corrected to flow from the web server to the order package to the price calculation service. By adhering to this order, the changeable layers depend on stable layers, preserving overall flexibility.
How to Cut Components and Build Architecture Tailored to Your Product
So far, we have discussed universal principles. From here, we will take the perspective of an actual product or business and explain how to cut components and draw boundaries.
The Architecture Must Support the System's Intent
A good architecture must be able to effectively support the intent of the system. For example, a shopping cart application needs to clearly support the use cases of a shopping cart. When an architecture is well-designed, the system's use cases become clearly visible within its structure.
For an architecture to support intent, independence is crucial. It is essential that it can be independently developed, operated, deployed, and that options are kept open. To achieve this, following the principles discussed so far is important.
The Architecture Must Communicate the System Itself
With a good architecture, you can defer and postpone decisions about details like databases and frameworks for a long time. A good architecture emphasizes use cases and decouples them from peripheral concerns.
You can evaluate an architecture by what it "shouts." If the top-level directory structure or package names shout about use cases, it is a good architecture. If they shout about framework names, then the use cases are not being emphasized effectively.
# Good Example: Shouting use cases
my-app/
└ modules/
├ healthcare-system/
├ accounting-system/
└ inventory-management-system/
# Bad Example: Shouting framework names
my-app/
└ modules/
├ rails-app/
├ spring-hibernate/
└ asp-inventory/
In summary, the architecture must communicate information about the system itself. It is important to show the system's use cases, not the framework names.
"Details" Must Be Easily Changeable and Replaceable
Input/Output layers (UI, databases, frameworks, etc.) that are far from business logic should be easily replaceable. In other words, aim for a plugin architecture.
UI and databases are details and low-level policies. If these are hard to replace, it will also be difficult to change the higher-level business logic, which is a very undesirable state. Higher levels should not be affected by lower levels.
Follow the Stable Abstractions Principle and Stable Dependencies Principle to make details pluggable. In other words, design so that business logic depends on UI and databases. This makes UI and databases pluggable and replaceable.
A state where details are replaceable.
You Should Adopt Package by Component
Packages should be created per component. Here, a component refers to "a bundle of business logic and persistence processing."
This restricts access to persistence processing and confines related functionality behind a clean interface, realizing highly cohesive components. Including controllers would also drag in details.
Conclusion
- Consider the purpose of the architecture (e.g., "keep options open," "emphasize use cases").
- Create components that follow SOLID principles.
- Following the 3 principles of component cohesion and 3 principles of component coupling, assemble an architecture that fits the purpose.
- As the development phase progresses, change which cohesion principle you prioritize, and make the architecture follow suit.
By following these steps, you can reduce the cost of building and maintaining the system. Creating a system that is always easy to change (soft) is extremely important for conducting business.
Finally, this article was organized based on a reading log of the following book. Many parts have been omitted boldly, so if this article was helpful, please read the actual book as well.
Title of the book I read
It is "Clean Architecture: A Craftsman's Guide to Software Structure and Design."
Since "Clean Architecture" has become a buzzword in the industry and lost its meaning, I intentionally avoided using the word "clean" in this article.
Discussion