Payment Service With Clean Architecture In .Net – Part I Understanding The Clean Architecture

In this series of posts, I will be diving into Clean Architecture. We will build a project in Clean Architecture.

We will;

  • Understand Clean Architecture
  • Clarify business requirements, create initial design
  • Set up Application Core
  • Set up Persistence and Infrastructure
  • Implement CQRS and Structural Logging
  • Implement Caching and Queue System
  • Integrate PayPal or Stripe as payment provider
  • Add .NET API
  • Add UI to the application(Blazor or MVC)
  • Add Authentication and Authorization
  • Add Unit and Integration tests

But in this post we are going to take a look at what Clean Architecture is and about, clearly understand it.

Understanding Clean Architecture

Clean Architecture was introduced in 2012 and is one of the “domain centric” architectures. Other domain centric variants are Hexagonal and Onion architectures, respectively. Although there are differences between them, a common point they all sharing is that they put the domain at the center of the architecture, all dependencies point inwards towards the domain. Thus making them “domain centric” architectures. 

With the domain being the heart of the architecture, we have the following;


  • Less coupling is possible compared to database centric architecture
  • Domain is the focus
  • There is room for strategies of domain driven design(the DDD)


  • Modification is difficult
  • Requires more thought process on the Domain and Application layers(the Core)
  • Initial cost is higher compared to database centric architecture
Figure 1.1

As obvious as in the Figure 1.1, the Clean Architecture structures the application in a way that business logic encapsulated at the heart of the application. The Application Core consists of Application and Domain layers. The Core Layer is completely agnostic to any outer layers around it, meaning it doesn’t know the implementation details.

In order to understand more clearly, let’s examine the layers of Clean Architecture;


  • Entities
  • Interfaces of Core and Infrastructure layers
  • Services
  • Exceptions
  • Agnostic to outer circles
  • Has no external dependencies


  • Depends on the Core
  • Implements interfaces from the Core
  • Data Access
  • Logging
  • API clients
  • Identity


  • API or MVC or Blazor
  • Middleware, filters
  • Interacts with services through MediatR

The Clean Architecture is trying to achieve the following important principles in software engineering;

  • Dependency Inversion(the “D” of SOLID)
  • Single Responsibility(the “S” of SOLID)
  • Separation Of Concerns
  • Persistence/Ignorance
  • Loose Coupling
  • DRY

Benefits of Clean Architecture

If implemented correctly, the clean architecture offers following benefits;

  • Independent of UI or used frameworks
  • Loose coupling thanks to Mediator pattern
  • Testable and maintainable

We will be able to understand more clearly once we have the actual project. Now we are ready to move into business requirements and begin our design.

About the author

Yasin Sunguray
By Yasin Sunguray


Yasin Sunguray

Hi there,

I write about full stack development, Laravel, .NET, C#, JavaScript, Vue, React and others.