DDD combat (1): How to design a layered architecture?

I. Introduction

Two years earlier, I began to see various tweets talking about how good DDD is, for example: Microservices are dead! DDD is king! . When I heard this slogan at the time, I was shocked. Could it be that microservices will die within two years of landing? What the hell is DDD? Is it good to learn? Is everyone so curly? Quietly come up with such an awesome thing?

With curiosity, I went to listen to the so-called "introductory class" of a teacher from a large factory. After listening to it, I felt that DDD was too awesome, and I was so excited that I couldn't sleep.

Urgently want to ask:

Is there any demo code?

Is there any demo code?

Is there any demo code?

Is there any demo code?

I began to privately message some authors who wrote DDD articles on the Internet, and I was a little disappointed after learning about it. Almost no projects that have landed are in use. After getting these results, I put it down temporarily. I started a new project 3 months ago. At that time, I wondered if I could use DDD to implement it. Then I started to analyze requirements, make models, and write specifications... Finally last night (August 25th) The first issue is online.

The launch of the project is not the end, on the contrary, it is just the starting point, and it is unknown whether it can be maintained well or how long it will be maintained. Next, I will slowly share the landing process and subsequent iterations with you.

2. Project introduction

Some specific DDD (Domain Driven Design) concepts are believed to be familiar to everyone soon, so I won’t talk about them here. It mainly explains the layered architecture design of the project.

2.1 Project Description

Based on the DDD (Domain Driven Design) lightweight rapid development framework, it is committed to the precipitability and inheritance of enterprise technology architecture, and solves the expansion problem of complex business scenarios. It has been implemented in the company's core business areas.

2.2 Project structure

./itunion-ddd-common // collection of basic components
├── itunion-ddd-common-base // common class library
├── itunion-ddd-common-exception // unified exception
├── itunion-ddd-common-mybatis // mybatis--plus
├── itunion-ddd-common-redis // redis cache
├── itunion-ddd-common-swagger // api visualization
└── pom.xml
.itunion-ddd-service // core service
├── itunion-ddd-web // WEB side-interface layer
├── itunion-ddd-application // application layer
├── itunion-ddd-domain // domain layer
├── itunion-ddd-infra // basic service layer
└── pom.xml

2.3 Construction purpose

  • Solve the pain points of chaotic maintenance logic and high maintenance costs in the later stage of the development process.
  • Transition from the MVC framework to a development framework more suitable for complex businesses.
  • Promote the germination of DDD ideas in the team and find better development ideas.

2.4 Principles must be adhered to

  • Domain-driven design (DDD) is the basis, and layering is used as the default development specification.

2.5 DDD layered architecture

Layer description:

  • Adaptation layer (Web): responsible for the routing and adaptation of the front-end display, which can be understood as the Controller of MVC.
  • Business application layer (Application): responsible for obtaining input, assembling context, parameter verification and calling domain layer for business processing. This layer is open and can bypass the domain layer and directly access the infrastructure layer.
  • Domain layer (Domain): also known as the model layer, encapsulates the core business logic, and provides business entities and business logic calculations to the application layer through domain services and domain objects.
  • Infrastructure layer (Infrastructure): Responsible for the processing of technical details, such as CRUD for databases, message queues, Redis, search engines, etc. The anti-corrosion layer of the domain is also placed here, and external dependencies need to be escaped before they can be called by the domain layer and the application layer.

PS: When designing and developing, do not put the business logic that should be placed in the domain layer into the application layer, because the huge application layer will make the domain model lose focus, and your service will evolve into a traditional one over time. With a three-tier architecture, business logic will become chaotic.

3. Deployment

3.1 Source address

A rapid development framework for microservices based on Domain Driven Design (DDD). https://gitee.com/itunion/ddd-framework

3.2 Early preparations

  • Pull the Master branch code
  • Necessary environment for installation: jdk1.8+, mysql5.7+, redis, etc.
  • Start the itunion-ddd-web project

3.3 Access address

http://127.0.0.1:8080/itunion-ddd-web/api

Guess you like

Origin blog.csdn.net/zhenghhgz/article/details/126547786