Layered Architecture

Overview

The layered architecture has several other names, such as onion architecture, the clean architecture, etc. The basic theory is, you organize the components layer by layer in which only the upstream layer can make calls to the downstream layers.

Most systems are designed in the layered architecture.

Use

Uni-directional Dependency

In layered architecture, nothing in the lower layer can make calls to the upper layer. However, cross-layer up-down calls or equivalent-layer calls are allowed.

More strictly, no name in the upper layer is allowed to appear in the lower layer, which includes variables, functions, classes, or even comment. However, error propagation is a special case.

Below are some examples of the directions of the calls.

Uni-directional Examples

Breaking such rule causes leaky abstraction, meaning lower layer failed to hide details from the upper layer.

Advantage and Disadvantage

Conclusion

In layered architecture, a layer serves the layer above it and is served by the layer below it. 1 The data flow is simple and easy to trace by making call uni-directional from top to bottom. Such architecture leads to a clean and elegant design.