preamble
Project architecture patterns play a vital role in software development; they provide developers with a set of guiding principles for organizing and managing code to improve the maintainability, scalability, reusability, and testability of software.
If you have any other project architecture patterns to recommend, feel free to leave a comment at the end of the article 🤞!!!!
Project Architecture Patterns Usage Collection (WeChat Voting, please open in WeChat to participate):/s/kr1vlt4tj3dSyXyRv-GqOw
three layer architecture (OSI)
Three-tier architecture is a classic software architecture pattern that divides an application into three main layers: the representation layer (UI), the business logic layer (BLL), and the data access layer (DAL).
Hierarchical responsibilities
- Representation layer (UI): responsible for the user interface and user interaction, is the part of the user direct contact.
- Business Logic Layer (BLL): handles business rules and business logic and is the core part of the application. It is responsible for data processing, validation, calculation and other business operations.
- Data Access Layer (DAL): responsible for interaction with the database, including CRUD (create, read, update, delete) operations on data.
MVC architecture
The MVC architecture pattern distinguishes an application into three main components: the model, the view, and the controller. This pattern facilitates the separation of concerns, as user requests are routed to the controller, which is responsible for collaborating with the model to perform user actions and/or return request results. This greatly improves the maintainability and scalability of the application.
Hierarchical responsibilities
- Model: represents the state of the application and any business logic or operations that should be performed by it. The business logic should be encapsulated in the model along with any implementation logic that maintains the state of the application.
- Views: are responsible for displaying content through the user interface. They use the Razor view engine to embed .NET code in HTML markup. There should be minimal logic in the view, and any logic in it must be relevant to the content being displayed.
- Controller: The component that handles user interaction, uses the model, and ultimately selects the view to be rendered. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. In the MVC model, the controller is the initial entry point and is responsible for selecting the type of model to use and the view to render.
DDD Layered Architecture
Domain-Driven Design (DDD) is a software design methodology and philosophy, proposed by Eric Evans in 2004. It transforms complex business logic into maintainable and extensible software systems through an in-depth understanding of the business domain.The core of DDD lies in the creation of a rich domain model that reflects business entities, business rules, and business processes.
DDD emphasizes the domain model as the core to drive software design and development.
Hierarchical responsibilities
- Representation Layer (UI): Responsible for handling the user interface and user interaction, which can be in the form of a web interface, a mobile application or a desktop application, etc. The representation layer is responsible for receiving user input and presenting data to the user, but it contains no business logic. The UI is responsible for receiving user input and presenting data to the user, but it does not contain business logic.
- Application: The intermediary between the representation layer and the domain layer, orchestrating business objects to perform application-specific tasks and implementing use cases using application logic.
- Domain: Contains business objects and business rules, and is the core of the application. The design of the domain layer should follow the principle of domain-driven design, and encapsulate the business knowledge and business logic in the domain model through in-depth understanding of the business domain, in order to improve the maintainability and scalability of the software system.
- Infrastructure: Provides technical infrastructure support, such as database access, message queuing, caching, and so on.
clean structure
Clean Architecture (Clean Architecture) is a software architecture design principles, by Robert C. Martin (Robert C. Martin), it aims to make software systems more flexible, maintainable and testable, and its core goal is to build a simple, flexible and easy to maintain the system structure.
Hierarchical responsibilities
- Entities: The entities layer represents the core business concepts and objects in the system. This layer contains entities that persist throughout the system's lifecycle and have a clear business meaning.
- Use Cases Layer (Use Cases): The Use Cases layer contains the specific business logic and use cases of the system. It coordinates the interaction between the entity layer and other layers to achieve specific business functions.
- Interface Adapters: The interface adapter layer connects the use case layer to external systems (such as databases, user interfaces, external services, etc.). It converts the interface of the external system into a form that can be understood by the use case layer, and converts the output of the use case layer into a format suitable for the external system.
- Frameworks and Drivers: The Frameworks and Drivers layer contains external frameworks and tools, such as databases, web frameworks, message queues, and so on. This layer is usually composed of specific technical implementations that provide infrastructure support for the upper layers.
CQRS Architecture
CQRS (Command and Query Responsibility Separation) is an architectural pattern designed to separate the read operations (queries) and write operations (commands) of a system. With this separation, the system can be optimized differently for processing read and write requests, thus improving system performance, scalability and maintainability.
Hierarchical responsibilities
- Presentation (presentation layer): responsible for handling user interface requests and responses. It receives user input and passes it to the back-end service, and displays the response from the back-end service to the user.
- Validation: Validates the data entered by the user before the command is processed, ensuring the legitimacy and integrity of the data.
- Commands: Encapsulates user-requested write operations such as creating, updating, or deleting data.
- Domain Logic: Execute the core business logic and rules. The command processor usually invokes the domain model and domain services to execute the business logic and ensure that the business rules are correctly applied.
- Data Persistence: After command processing is complete, the data is saved to the write data store to ensure data consistency and persistence.
- Write Data Store: The Write Data Store is responsible for managing the data for all write operations, including transaction processing and data consistency.
- Read Data Store: The Read Data Store optimizes the performance of read operations and provides fast response to query results.
- Queries: Query objects are passed to the query processor, which fetches data directly from the read data store and generates DTOs to be returned to the presentation layer.
final conclusion
Each project architecture model has its own characteristics and applicable scenarios, developers should choose the most appropriate project architecture model based on the specific needs of the project and technology stack.
reference article
- /zh-cn/aspnet/core/mvc/overview?view=aspnetcore-8.0
- /zh-cn/azure/architecture/patterns/cqrs
- /developer/article/2324905