Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between Layered architecture with dependencies inversion and Hexagonal architecture?

I have been reading a bit on software architecture.

I noticed that I have used layered architecture with dependencies inversion. I have controller layer classes that are dependent on the service layer interfaces, and the services layer implementations are dependent on the repository layer interfaces. None of the layers are dependent on the concrete classes.

Now, I have come across the hexagonal architecture as well, and the idea of port and adapter feel pretty similar to a layered architecture with dependencies inversion.

What are the differences between these two architectural styles?

like image 751
jndp Avatar asked Oct 31 '25 20:10

jndp


1 Answers

I find that Hexagonal Architecture makes the following more clear than a traditional (i.e., vertically-stacked) layered architecture:

  • That the "inside" of the Hexagon is the most important part, at least to those who are asking for the application to be built, as it has the Core Domain (works well with modeling from Domain-Driven Design).

  • The "inside" of the Hexagon provides a strong boundary where there is no dependencies on hardware, infrastructure, or I/O. This makes writing fast unit tests easy.

  • The Adapters on the outside of the hexagon are separate from one another, ensuring that changes to one don't affect the others. It also makes it easy to "unplug" an Adapter that's no longer needed, or plug-in new Adapters without requiring changes inside the hexagon.

Hexagonal Architecture is a layered architecture, but I find the addition of clear boundaries above to make it easy to work with.

like image 166
Ted M. Young Avatar answered Nov 02 '25 13:11

Ted M. Young



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!