Introduction
Ports and adapter is a very old and clean architecture to write modular and decoupled code. It was formally known as Hexagonal due to its diagram. Which shows as a hexagonal.
Here is a sample diagram, which, shows the different parts of this amazing pattern. It gives the flexibility to make a decoupled applications for core logic. The core logic is independent and you can use any implementation adapter to inject any functionality without making any change in Core.
Let us see how

First, we need to understand the basic component of this design. This is divided into three parts,
application - defines how the outside world interacts with an application, it is a gateway to an application core. It might be by Rest controllers/WebAPIs, but it could be also by some kind of a message service (like Kafka, RabbitMQ, etc.).
core - the heart of the complete application. Which is implemented as on DDD (Domain Driven Design) approach. Here sits the business logic of your application. The goal is to have it written in plain language so that any technical or even non-technical person could understand. Inside it, we use a domain-specific language, which can be easily understood by business people. The most important thing, it should be agnostic of any framework, because these are only scaffolding of an application. The core is the heart of an application, something that encapsulates the logic in a plain C#/Java code.
infrastructure - it’s the last part, most of the applications does not only contain business logic but usually, they also need to use some external systems, like database, queue, third party services, other application and so on. In this part, we say how this communication will be implemented (in a core we only say what is needed). For example, in order to persist data in a database, we can use several approaches like NHibernate, ADO.Net, Entity Framework, or whatever framework we like.
“For some people, it looks like a normal layered application, but the key difference here is the Core does not know anything about the Application and Infrastructure. It should not know anything about the outside world, which keeps it decoupled from any change in the infrastructure of the application.”
Wait, what? How it could be achieved?
In addition, the answer is, inside the core, we define something that is called Port, and it defines all the interactions that a core will have with anything outside. These ports are like contracts (or APIs/Interface) and can be divided into two groups incoming (primary) and outgoing (secondary).







E SequinelPosted Jan 11, 2023, 10:05 AM
It looks like you are implementing the CQRS pattern, is that right?