DDD layered architecture
Clean architecture
Clean architecture is also known as the Onion architecture. Why is it called onion architecture? Take a look at the picture below. The layers of a clean architecture are like onion slices, reflecting the idea of layered design.
The most important principle of clean architecture is the dependency principle, which defines the dependencies at each level, the lower the dependencies, the higher the code level, and the more core capabilities. The outer circle code depends on pointing only to the inner circle, and the inner circle doesn’t need to know anything about the outer circle.
Hexagonal structure
Hexagonal architecture is also known as “port adapter architecture”. Tracing the origins of microservices architectures, it is common to refer to hexagonal architectures.
The core idea of the hexagonal architecture is that applications interact with the outside world through ports. I think this is the main reason for the popularity of API gateways in microservices architecture.
Comparison and analysis of three microservice architecture models
All three architectures allow for changing front-end requirements and invariant domain models.
DDD hierarchical architecture, clean architecture, and hexagonal architecture are all based on domain model and implement hierarchical architecture. The internal core business logic is isolated and decoupled from external applications and resources. Please keep this design idea in mind, it will be of great use in the future.
Project-level microservices
Internally, project-level microservices follow a layered architecture model. The core logic of the domain model is implemented in the domain layer, and the combination and orchestration of services are implemented in the application layer. The front-end applications are provided with services through THE API gateway to achieve the separation of the front and back ends. But project-level microservices may call other microservices, as you can see in the figure below. For example, A project-level microservice B calls authentication microservice A to complete login and permission authentication.
Enterprise micro services in Taiwan
We can add a layer on top of the Micro services in China Platform. You can see the figure below. The added layer is located in the red box. If I expand the scope of its business, I can make it a service platform for different industries and channels.
The BFF microservice differs from other microservices in that it has no domain model and therefore no domain layer within the microservice. BFF microservices can assume the main functions of the application layer and user interface layer, complete the service composition and arrangement of various micro services in Taiwan, and can meet the requirements of different front-end and channel.
Finally, welcome to pay attention to my public account: Java programmers gathering place, Maidong will share Java related technical articles or industry information every day, welcome to pay attention to and forward the article!