Part 01 - Clean Architecture Overview

enggaruny

Arun Yadav

Posted on February 6, 2023

Part 01 - Clean Architecture Overview

Clean Architecture: Maintainable, Testable, and Scalable Applications

Originally Posted on: https://www.arunyadav.in/codehacks/blogs/post/20/part-01-clean-architecture-overview

In software development, creating a well-designed and organized application is crucial for success. Clean Architecture is a software design principle that can help you achieve this goal by separating an application into distinct parts. This makes it easier to maintain, test, and scale the application over time.

The main idea behind Clean Architecture is to keep the business logic of an application isolated from external factors, such as presentation, infrastructure, and persistence. This separation of concerns makes it easier to change and maintain the application, as well as test it without affecting other parts of the code.

Clean Architecture consists of several circles or layers, each with a specific responsibility. The innermost circle is the business logic, which is the core of the application. This layer is isolated from external factors and communicates with other layers through well-defined interfaces. The business logic should not depend on the outer layers, and instead should rely on abstractions.

The next layer is the interface adapters, which are responsible for converting data between the business logic and the outer layers. This layer includes things like presentation logic, data access, and infrastructure.

Finally, the outer layer is the frameworks and drivers, which are responsible for providing external services to the application. This layer includes things like databases, web servers, and operating systems.

Let's understand by Onion View

Clean Architecture Onion View

The flow of dependencies in the diagram moves towards the center. The centermost point is referred to as the Application Core, which acts as the nucleus of the diagram and is not dependent on any other layers. The entities and interfaces occupy the central position while domain services, which provide implementation to the central interfaces, surround them. The UI and Infrastructure layers, located on the exterior, are both dependent on the Application Core.

Let's understand by Horizontal View

Clean Architecture Horizontal View

In the clean architecture, the direction of solid arrows indicates compile-time dependencies, while the dashed arrow signifies a dependency that only exists at runtime. The UI layer interacts with the interfaces specified in the Application Core during compilation, without having knowledge of the concrete implementations in the Infrastructure layer. At runtime, these implementations become necessary for the operation of the app, and must be connected to the Application Core interfaces through dependency injection.

Let's understand by ASP.NET Core architecture diagram following Clean Architecture.

Clean Architecture ASP.NET Core View

Support For Docker

Clean Architecture Docker

Here is forked Gihub https://github.com/engg-aruny/CleanArchitecture

Organizing code in Clean Architecture

Application Core types

  • Entities (business model classes that are persisted)
  • Aggregates (groups of entities)
  • Interfaces/Contracts
  • Domain Services
  • Specifications
  • Custom Exceptions and Guard Clauses
  • Domain Events and Handlers
  • Behaviours
  • Mappers

Infrastructure Types

  • Identity Services
  • File Storage
  • Queue Storage
  • Payment Services
  • Third-party services
  • Notifications
  • Email Services
  • Sms Services

UI Layer

  • Controllers
  • Custom Filters
  • Custom Middleware
  • Views
  • ViewModels
  • Startup

Persistence Types

  • Data Context
  • Repositories
  • Data Seeding
  • Data Migrations
  • Caching

Domain Types

  • Domain Entities
  • Domain Events
  • Value Objects
  • Aggregates
  • Enums
  • Constants

Here is the diagram of all types into layers

Clean Architecture View

Source from https://medium.com/dotnet-hub/clean-architecture-with-dotnet-and-dotnet-core-aspnetcore-overview-introduction-getting-started-ec922e53bb97

References

💖 💪 🙅 🚩
enggaruny
Arun Yadav

Posted on February 6, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related