Clean Architecture - SA Guest lecture
Clean Architecture - SA Guest lecture
Architecture
Obaid ur Rehman
Software Architect / Engineering Manager @ Folio3
Who are you?
⬢ Software Architect / Engineering Manager at
Folio3
⬢ Over 18+ years of experience
⬢ IBA: Taught Introduction to DevOps in Spring 2024
Agenda
● What is clean Architecture
● Theory of Clean Architecture
● Design Principles
● Implementation
● Real life example
● Benefits
● QA
What is Clean Architecture?
What is it exactly?
What is Clean Architecture?
https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html
History
● For example, a "Place Order" use case interacts with the Order
entity to validate items and calculate the total cost.
Interface Adapters
Interface Adapters bridge the core logic (Entities and Use Cases)
with external systems (databases, UI, or APIs).
They convert data formats between layers and keep business logic
unaware of external data structures.
Interface Adapters / Controllers
They receive HTTP @RestController
@RequestMapping("/orders")
requests, extract data, public class OrderController {
private final PlaceOrderUseCase placeOrderUseCase;
and call the
public OrderController(PlaceOrderUseCase placeOrderUseCase)
appropriate Use Case. {
this.placeOrderUseCase = placeOrderUseCase;
}
Example on right for a
@PostMapping
sample Controller public ResponseEntity<Map<String, Object>>
implementation. placeOrder(@RequestBody List<OrderItem> items) {
double total = placeOrderUseCase.execute(items);
Map<String, Object> response = Map.of("total", total);
return ResponseEntity.ok(response);
}
}
Interface Adapters / Gateways
Gateways abstract external systems like databases or APIs and
provide clean interfaces.
}
Frameworks and Drivers
● This outermost layer includes the technical details of the
system, such as frameworks, databases, UI, and external APIs.
Example:
Single
Separation of Dependency
Responsibility
concerns Inversion
Principle
Persistence
Ignorance
Separation of concerns
The practice of dividing a software system into distinct sections,
each responsible for a specific aspect of the application:
● Inner layers can be tested in isolation because they are not coupled with
external systems.
● Components like the user interface or database can be swapped with minimal
impact. For example, transitioning from a REST API to GraphQL affects only the
Interface Adapters layer.
● External systems (for example, web frameworks) are often volatile, with
frequent updates or deprecations. By isolating these changes, the core remains
unaffected.
Persistence Ignorance
Persistence Ignorance advocates for a clear separation between
the domain model and the infrastructure concerns such as data
storage. This principle posits that domain classes should solely
encapsulate the business logic and rules pertinent to the
application, without being polluted by technical details related to
persistence mechanisms.
Implementation of
Clean Architecture
in .NET
Source: Design Application using Clean Architecture | by .Net Labs | Stackademic
Domain Layer
● Entities
● Interfaces for Presentation
abstraction Application
● Exceptions
● Enums
Domain
Infrastructure
Application Layer
● Orchestrate the domain
● Business Logic Presentation
(Application) Application
Infrastructure
Infrastructure Layer
● Interface to External
Systems like: Presentation
● Email Application
● Storage
● Database
Domain
● Message Queues
● Cache
Infrastructure
Presentation Layer
● Entry point to system
● gRPC Presentation
Presentation
Application
Domain
Infrastructure
Demo
In Conclusion
● When to use Clean Architecture
● Steep Learning Curve
● Performance Concerns
Questions?