Curs - 7 - Clean Architecture

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

CLEAN ARCHITECTURE

PRINCIPLES
What is Software Architecture?

Set of rules that Provides a limitation


to the Software Development
Why is Software Architecture Good

Modularity and Separation of Concerns: The architecture should promote modularity

Clarity and Understandability: A good architecture is clear and understandable to all stakeholders involved in the process

Scalability and Flexibility: A good architecture is flexible and able to accommodate changes and growth in the software over time

Performance and Efficiency: The architecture should be designed with performance and efficiency in mind

Robustness and Reliability: The architecture should be robust and resilient to failures, errors, and unexpected inputs

Maintainability and Extensibility: A good architecture is maintainable and extensible

Alignment with Business Goals and Requirements: The architecture should align with the business&requirements of the project
What is Complexity?
"Complexity is anything related to the structure of a software
system that makes it hard to understand and modify the
system.” - "A Philosophy of Software Design" by John
Ousterhout Stanford University

"Making code simpler and more obvious"


"Encapsulate complexity (also called modular design)"
Strategic vs. Tactical Programming
How to deal with complexity?
Separation: The word “separation” emphasizes the act of isolating or distinguishing different concerns within a system
Concerns: represents a specific aspect of functionality, behaviour, or responsibility within the system.
How to deal with complexity?
Clean Architecture
Clean Architecture
Clean Architecture – Domain Layer
• Domain Layer
── Domain
├── Entities
├── Interfaces
└── Services
Clean Architecture – Infrastructure Layer
Infrastructure Layer
── Infrastructure
├── Data
├── Services
└── Repositories
Clean Architecture – Presentation Layer
Presentation Layer
── Presentation
├── Controllers
├── DTOs
├── Extensions
└── Middleware
Clean Architecture – Benefits
• Apply Clean Architecture to projects => the code remains maintainable
and extensible over time by SoC (Separation of Concerns)
• Enhances maintainability
• Facilitates modularity
• Helps with testability
• Clean & modularized code => applications run faster and more efficiently
Clean Architecture – Challenges
• Ensure code is separated into distinct components
• Ensure that each component is responsible for a single concern
• Difficult to apply the principles to existing software projects
• Existing code may need to be rewritten
CQRS Pattern in C# and Clean Architecture
CQRS (Command Query Responsibility Segregation)
used for segregating different responsibility types in a software application

Commands -> are responsible for changing the state of the application
Queries. -> retrieve data without changing any state
CQRS Pattern in C# and Clean Architecture
CQRS Pattern in C# and Clean Architecture
CQRS Pattern in C# and Clean Architecture
CQRS (Command Query Responsibility Segregation)
Benefits:
Higher Scalability
Read and Write Scalability
Infrastructure Optimization
Simplified Code Maintenance
Clear Separation of Concerns
Reduced Complexity
Targeted System Needs
Customization
Consistency Handling
CQRS Pattern in C# and Clean Architecture
CQRS (Command Query Responsibility Segregation)
Challenges:
Increased Complexity
Implementation Overhead
Data Consistency
Command and Query Handling
Command Handlers
Query Handlers
CQRS Pattern in C# and Clean Architecture
CQRS (Command Query Responsibility Segregation)
When to use?

Complex Domain Models


High-Performance Applications
Event-Sourced Systems
Microservices Architectures
CQRS with Mediator pattern
CQRS with Mediator pattern
CQRS with Mediator pattern
CQRS with Mediator pattern

You might also like