A code architecture optimization system based on DDD congestion model and CQRS

By optimizing the three-tier architecture using the DDD richness model and CQRS, the development and maintenance difficulties caused by the inconsistency between the memory model and the database model are resolved, enabling flexible expansion and high-quality code that is suitable for various databases and application types.

CN112181375BActive Publication Date: 2024-10-29SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011037796.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-28
Publication Date
2024-10-29
Estimated Expiration
2040-09-28

AI Technical Summary

Technical Problem

The existing three-tier architecture, when the memory model and database model are kept consistent, leads to high development difficulty, maintenance difficulties, and poor code quality. In particular, when the granularity of the database model is not appropriate, reusability, stability, and scalability are insufficient.

Method used

The code architecture optimization method based on DDD richness model and CQRS is adopted, which is divided into domain layer, use case layer, adaptation layer and framework layer. Domain entities include attributes and behaviors, adopt independent query model, and divide client requests into commands and queries. The code is divided through Java9 module system or Maven aggregation module.

Benefits of technology

It achieves framework independence, business rule testability, and functionality implementation that does not depend on UI or database details. It supports use in different databases, and the code can be shared in both web applications and native app applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112181375B_ABST
    Figure CN112181375B_ABST
Patent Text Reader

Abstract

The present invention provides a code architecture optimization system based on a DDD enriched model and CQRS, belonging to the field of software / data processing technology. The present invention includes architecture layering, domain entities and query models. Under the background of the mainstream three-tier architecture, through the division of architecture layering, optimization of domain entities and splitting of query models, many characteristics such as business logic not depending on implementation details are realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to software / data processing technology, and in particular to a code architecture optimization system based on a DDD congestion model and CQRS. Background Art

[0002] In software architecture, the three-tier architecture has become the mainstream. The three-tier architecture divides the entire business application into: interface layer (presentation layer, presentation layer), business logic layer, and data access layer. The interface layer displays data and receives data transmitted by users, providing an interactive operation interface for the software. The business logic layer performs business logic judgment and processing on specific issues, and realizes data connection and instruction transmission between the three layers. The data access layer provides operations such as adding, deleting, modifying, and querying data in the database. Data transfer in the three layers is usually undertaken by business entities (entity) or data transfer objects (data transferobject).

[0003] The three-tier architecture is essentially a process-oriented programming concept with the following characteristics:

[0004] 1. The business entity class only has attributes but no methods.

[0005] 2. The classes in the business logic layer only have methods but no attributes.

[0006] 3. The data table structure is usually mapped to the business entity class.

[0007] The fundamental problem of the three-tier architecture is that the memory model is usually consistent with the database model. If the database model is small in granularity, a large number of table connections will lead to difficulties in development, maintenance, and performance issues. If the database model is large in granularity, the quality of the code (reusability, stability, and scalability) will be poor. Since each class is not carefully defined from a business perspective, the related classes will continue to grow and become difficult to maintain as the business develops. What's worse, the business logic is also written into SQL or JS statements. Summary of the invention

[0008] In order to solve the above technical problems, the present invention provides a code architecture optimization method based on the DDD congestion model and CQRS.

[0009] The technical solution of the present invention is:

[0010] A code architecture optimization system based on DDD congestion model and CQRS.

[0011] Includes architectural layers, domain entities, and query models;

[0012] The architecture layers include domain layer, use case layer, adaptation layer and framework layer, and their dependencies are from outside to inside;

[0013] The domain entity is designed as an entity object including attributes and behaviors;

[0014] The query model separates the query operations of the client.

[0015] Furthermore,

[0016] The domain layer encapsulates the core business rules. A domain entity contains both attributes and behaviors and can be flexibly expanded with the business entity as the core.

[0017] The use case layer contains the application of business rules, integrating and implementing all the use cases required in the system. These use cases coordinate the data flow between entities.

[0018] The adaptation layer contains various adapters, which are responsible for converting the data flowing from the domain layer and the use case layer into the data format required by the outer layer;

[0019] The framework layer is the outermost layer, where the specific implementation details of many tools or libraries are located.

[0020] Domain entities should follow object-oriented design. The domain model has its own attributes, behaviors and states, and is mapped to real-world business objects.

[0021] Domain entities have clear division of responsibilities, and domain object elements cooperate through aggregation and reference relationships to solve actual business applications and rules.

[0022] Furthermore,

[0023] Using a separate query model

[0024] Client requests are divided into commands and queries. Commands perform business logic operations such as adding, modifying, and deleting business logic through domain objects, and queries convert the data in the database into the required form and return it through the query model.

[0025] The query model changes as the needs of the UI change, while isolating the domain objects from being affected by this change.

[0026] Furthermore,

[0027] The architecture divides the entire code into five directories, which can be implemented through the Java9 module system or Maven aggregation modules, or divided through the simplest package.

[0028] The domain layer directory is named domain, which includes three subdirectories: service, event, and repository;

[0029] a) Domain entities are placed in the domain directory. Domain entities are business logic carriers and are named using domain names.

[0030] b) Place domain services in the service directory. Domain services are used when business logic is not suitable for being placed in domain entities. Domain services are named xxxService (xxx represents the domain name, the same below);

[0031] c) Domain events are placed in the event directory. When the state of a domain entity changes, a domain event needs to be issued. Domain events are named xxxyyyEvent (yyy represents the operation).

[0032] d) The repository interface is placed in the repository directory. The repository is used by business use cases and implemented by the provider. The repository is named xxxRepository.

[0033] The use case layer directory is named usecase, which includes four subdirectories: command, query, event, and impl;

[0034] a) Place the business use case interface in the usecase directory, and name the business use case interface using xxxUsecase;

[0035] b) Place the business use case implementation in the impl directory and name it xxxUsecaseImpl.

[0036] c) Place DTO in the command and query directories, divided into two categories: command and query, which are used as parameters or return values ​​of business use cases. Command is named with xxxCmd, and query is named with xxxQry;

[0037] d) Place the event listener in event. The listener is named xxx Listener.

[0038] The adaptation layer is divided into two parts: the application entry adapter directory and the data provider adapter directory;

[0039] a) The application entry is named entry, which includes three directories: rest, job, and listener.

[0040] b) Place the rest api in the rest directory to respond to rest requests and name it xxxRest.

[0041] c) Place scheduled tasks in the job directory and name them as xxxJob.

[0042] d) Place the message queue receiver in message and name it xxxMessage.

[0043] e) Data provider is named provider, which includes directories such as db, mq, cache, search, file, and external, which are used for database access, message sending, cache, search engine query, file storage, and external service call, respectively.

[0044] The framework layer directory is named boot, which includes the config directory and the main() method. In addition, it should provide a unified dependency management and construction method.

[0045] a) Global configuration is placed in the config directory to integrate components at all layers. Its responsibilities include dependency injection and framework integration.

[0046] The beneficial effects of the present invention are

[0047] 1) Framework-independent, that is, the architectural design does not rely on any existing development framework, so theoretically any framework can be used.

[0048] 2) Business rule testability, that is, the code involved in the business logic can be easily tested without relying on external elements such as UI, database or Web services.

[0049] 3) Functional implementation does not depend on UI implementation details. For example, the same backend system can be used in Web applications as well as in App native applications.

[0050] 4) The business logic does not depend on the implementation details of the database. The data can be stored in any database such as Oracle, SQL server, MongoDB, MySQL, etc., and the business logic does not need to be changed. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 It is a schematic diagram of the architectural layering of the present invention. DETAILED DESCRIPTION

[0052] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0053] 1. Architecture Layering and Dependency Principles

[0054] The overall architecture is divided into domain layer, use case layer, adaptation layer and framework layer, such as Figure 1 As shown,.

[0055] The domain layer encapsulates core business rules. A domain entity contains both attributes and behaviors and can be flexibly expanded with the business entity as the core.

[0056] The use case layer contains the application of business rules, integrating and implementing all the use cases required in the system, which coordinate the flow of data between entities.

[0057] The adaptation layer contains various adapters, which are responsible for converting the data flowing out of the domain layer and the use case layer into the data format required by the outer layer (for example, converting it into a format suitable for database storage or a format suitable for web page display).

[0058] The framework layer is the outermost layer, which is where the specific implementation details of many tools (or libraries) are located, such as web frameworks, database frameworks, and drivers.

[0059] Each concentric circle in the architecture diagram represents a different layer in software development. The closer to the center, the more abstract the concentric circle represents. The inner layer defines the rules, and the outer layer defines the implementation mechanism. Only the outer layer code is allowed to depend on the inner layer code, and vice versa. In other words, the code of the inner concentric layer should not know any code of the outer concentric layer. For example, the inner layer code is prohibited from referencing functions, classes, variables or any other elements declared in the outer layer. When there is data transmission, only the outer layer is allowed to accept the data format of the inner layer, and vice versa.

[0060] 2. Reasonable division of domain entities

[0061] Domain entities should follow object-oriented design. The domain model has its own attribute behavior and state, and is mapped to the business objects in the real world. Domain entities have clear division of responsibilities, and domain object elements cooperate to solve actual business applications and rules through aggregation and reference relationships. It is reusable, maintainable, and easy to expand, and can be designed in detail using appropriate design models. In short, domain entities should have business logic methods rather than being used only as data structures.

[0062] 3. Use an independent query model

[0063] Client requests are divided into commands and queries. Commands perform business logic operations such as adding, modifying, and deleting through domain objects, and queries convert the data in the database into the required form and return it through the query model. The query model can change according to the needs of the UI, while isolating the domain objects from being affected by such changes.

[0064] 4. Architecture Solution

[0065] The architecture divides the entire code into five directories, which can be implemented through the Java9 module system or Maven aggregation module, or it can be divided through the simplest package.

[0066] 1) The domain layer directory is named domain, which includes three subdirectories: service, event, and repository.

[0067] a) Domain entities are placed in the domain directory. Domain entities are the main business logic carriers and are named using domain names.

[0068] b) Place domain services in the service directory. Domain services are used when business logic is not suitable to be placed in domain entities. Domain services are named xxxService (xxx represents the domain name, the same below).

[0069] c) Domain events are placed in the event directory. Domain events need to be issued when the state of a domain entity changes. Domain events are named xxxyyyEvent (yyy represents the operation).

[0070] d) The repository interface is placed in the repository directory. The repository is used by business use cases and implemented by the provider. The repository is named xxxRepository.

[0071] 2) The use case layer directory is named usecase, which includes four subdirectories: command, query, event, and impl.

[0072] a) Place the business use case interface in the usecase directory. The business use case interface is named xxxUsecase.

[0073] b) Place the business use case implementation in the impl directory and name it xxxUsecaseImpl.

[0074] c) Place DTO in the command and query directories, which are divided into two categories: command and query, which are used as parameters or return values ​​of business use cases. Command is named with xxxCmd, and query is named with xxxQry.

[0075] d) Place the event listener in event. The listener is named xxx Listener.

[0076] 3) The application entry adaptation layer is named entry, which includes three directories: rest, job, and listener.

[0077] a) Place the rest api in the rest directory to respond to rest requests and name it xxxRest.

[0078] b) Place scheduled tasks in the job directory and name them as xxxJob.

[0079] c) Place the message queue receiver in message and name it xxxMessage.

[0080] 4) The data provider adaptation layer is named provider, which includes directories such as db, mq, cache, search, file, and external, which are used for database access, message sending, cache, search engine query, file storage, and external service call, respectively.

[0081] 5) The framework layer directory is named boot, which includes the config directory and the main() method. In addition, a unified dependency management and construction method should be provided (such as pom.xml based on Maven).

[0082] a) Global configuration is placed in the config directory to integrate components at all layers. Its main responsibilities are dependency injection and framework (web framework, database driver, etc.) integration.

[0083] The above description is only a preferred embodiment of the present invention, which is only used to illustrate the technical solution of the present invention, and is not used to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A code architecture optimization system based on DDD congestion model and CQRS, characterized in that: Includes architectural layers, domain entities, and query models; The architecture layers include domain layer, use case layer, adaptation layer and framework layer, and their dependencies are from outside to inside; The domain entity is designed as an entity object including attributes and behaviors; The query model separates the query operations of the client; The domain layer encapsulates the core business rules. A domain entity contains both attributes and behaviors and can be flexibly expanded with the business entity as the core. The use case layer contains the application of business rules, integrating and implementing all the use cases required in the system. These use cases coordinate the data flow between entities. The adaptation layer contains various adapters, which are responsible for converting the data flowing from the domain layer and the use case layer into the data format required by the outer layer; The framework layer is the outermost layer, where the specific implementation details of the tool or library are located; Domain entities should follow object-oriented design. Domain models should have their own attributes, behaviors, and states, and be mapped to business objects in the real world. Domain entities have clear division of responsibilities, and domain object elements cooperate to solve actual business applications and rules through aggregation and reference relationships; The architecture divides the entire code into five directories, namely, the domain layer directory, the use case layer directory, the application entry adaptation layer, the data provider adaptation layer, and the framework layer directory. This is achieved through the Java 9 module system or Maven aggregation module, or through the simplest package. The domain layer directory is named domain, which includes three subdirectories: service, event, and repository; Domain entities are placed in the domain directory. Domain entities are business logic carriers and are named after the domain name. Domain services are placed in the service directory. Domain services are used when business logic is not suitable for being placed in domain entities. Domain services are named xxxService, where xxx represents the domain name, and the same applies below. Domain events are placed in the event directory. When the state of a domain entity changes, a domain event needs to be issued. Domain events are named xxxyyyEvent, where yyy represents the operation. The repository interface is placed in the repository directory. The repository is used by business use cases and implemented by the provider. The repository is named xxxRepository. The use case layer directory is named usecase, which includes four subdirectories: command, query, event, and impl; The business use case interface is placed in the usecase directory and is named xxxUsecase. Place the business use case implementation in the impl directory. The business use case implementation is named xxxUsecaseImpl. DTOs are placed in the command and query directories, divided into two categories: commands and queries, which are used as parameters or return values ​​of business use cases. Commands are named with xxxCmd, and queries are named with xxxQry. Place the event listener in event. The listener is named xxx Listener. The application entry adaptation layer is named entry, which includes three directories: rest, job, and listener; a) Place the rest api in the rest directory to respond to rest requests and name it xxxRest. b) Place scheduled tasks in the job directory and name them as xxxJob; c) Place the message queue receiver in message and name it xxxMessage; The data provider adaptation layer is named provider, which includes db, mq, cache, search, file, and external directories, which are used for database access, message sending, cache, search engine query, file storage, and external service call respectively; The framework layer directory is named boot, which includes the config directory and the main() method. In addition, it should provide a unified dependency management and construction method. The config directory contains global configurations, which are used to integrate components at all levels. Its responsibilities include dependency injection and framework integration.

2. The system according to claim 1, characterized in that Using a separate query model Client requests are divided into commands and queries. Commands perform business logic operations such as adding, modifying, and deleting through domain objects, and queries convert the data in the database into the required form and return it through the query model. The query model changes as the needs of the UI change, while isolating the domain objects from being affected by this change.

Citation Information

Patent Citations

  • Componential research and development mode and domain driving model combined application development system and platform

    CN103761082A

  • e-ENABLER PRESCRIPTIVE ARCHITECTURE

    US20080052664A1