Port and adapters — a practical introduction. Part 1.

Tomasz Kasprzycki
1 min readApr 9, 2020

This is a practical introduction to Port and adapters architecture. I will go through one business example and explain all the major parts of this architecture. As an example, I would use a banking system that has an account and balance features.

Let’s start first from the Account entity:

It’s very simple, it has

  • account number,
  • currency code
  • user unique identifier

This entity is one of the fundamentals of our system. In most cases, it will be also a table in the database but it’s not required at this point. Once we have this entity the next step is to create functionality that allows us to interact with it by reading and writing. We define a port for this.

You can thing about port the same way you think about port in networking nomenclature. It’s an entry to your functionality — traffic goes through it. Another example often use is that port in your application is like an electrical socket and you can attach to it many different devices depending on your need.

In practice, the port is an interface and an adapter is an implementation. AccountRepository is a port to our Account entity. We can fetch, update, delete entity through the port. A precise description of how to do it is provided in the implementation — adapter. You can use a database or in-memory functionality.

In the next part, we will see more examples and try to explain different types of ports and adapters.

--

--