#article/done/published
#Architecture
#Three-layer fractal architecture
When studying architecture, various layered architectures are often encountered, such as traditional three-layer, four-layer, DDD, hexagonal, MVC, MVP, MVVM, etc., and new layered methods are constantly emerging.
Do we really need to constantly learn so many layered methods? Is there a universal layered method that can be learned?
Architectural methodology - the three-layer fractal architecture attempts to use a methodology to generate applicable layered methods.
Why layering?#
The essence of layering is focus. Traditional three-layer architecture focuses on business logic, MVC focuses on interaction flow control, ORM focuses on data mapping, and DDD focuses on domain services.
How to layer?#
First of all, the core of a software system is business logic, so we have the first layer, the business logic layer.
Business logic cannot be directly used by users, so we need an interaction layer (or presentation layer, access layer) to apply business logic.
Business logic cannot be built out of thin air, it needs support from other applications, so we also need a foundation layer (or data layer).
Do we need other layers?
Currently, it is not necessary.
The foundation layer here is also the application of other systems. That is, the application of one system supports other systems, and the core of one system depends on the application of other systems. Because the relationship between systems and systems, and systems and users is nothing more than support and dependence, this already covers all cases.
What is the three-layer fractal architecture?#
So why does the layered design of DDD have four layers, and the network has 7 layers, and so on, exceeding three layers?
Designs with more than three layers are actually based on the three-layer architecture, and one of the layers is refocused on a different core, resulting in a redivision of three layers.
For example, if the core layer refocuses on entities and aggregates, then the application domain entities will require an application service layer, and support for domain entities will require repositories, domain event buses, and other support.
In the interaction layer, the focus is on interaction flow control. The core layer is the controller, the application layer is the view, and the support is the model. The focus is on different presentations of the interface. The core layer is the presenter, the application is the view, and the support is the model.
Three-layer architecture refers to focusing on a certain core, and based on the relationship between support and application, dividing it into three layers.
Three-layer fractal architecture refers to applying the three-layer architecture method, and recursively using the three-layer architecture in each layer. Because it is the repeated application of the three-layer architecture, it resembles a fractal, so it is named the three-layer fractal architecture.