Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java code example of Hexagonal Architecture?

I've been doing a lot of research on Hexagonal Architecture aka ports and adapters. I like the concepts, but struggling with some of the practicality. For example, the Domain isn't supposed to have the database access details (implementation). Instead that should be in the Framework layer. But there's a lot of "smarts" involved with data access in order to get the right data and it would seem to me that should belong in the Domain? So I'm looking for an example Java project that practically demonstrates the interactions between the Domain, Application, and Framework layers. Anyone know if something like this exists? I've not had much luck finding it. Lots of blogs about Hexagonal Architecture concepts, but nothing with concrete examples.

like image 498
Michael Remijan Avatar asked Jan 28 '26 20:01

Michael Remijan


1 Answers

I saw upvote on my comment, so I came with the idea that I will describe the best way to learn hexagonal architecture, in my opinion.

  1. Read what is DDD. Those two topics are practically the same. For this purpose I recommend the creator of this term Eric Evans and his book "Domain-Driven Design: Tackling Complexity in the Heart of Software".
  2. Read what is hexagonal architecture. There are good books. Uncle bob's: "Clean Architecture: A Craftsman's Guide to Software Structure and Design". Short description can be found here, on his website
  3. Watch some talks just in case. The one I found really helpful was Victor Rentea's presentation od Devoxx
  4. Analyse access modifiers in language you are developing. They are doing half the work.
  5. Work on it. Try to implement the way you understand it. Then you will see that those things works better those are missing and those are over engineering.
  6. Compare it with others code. It is really good feeling when you see that someone who has bigger experience implemented this the same way you did. This is the clue of this question. For this I recommend you this links.

Guy talk how important are access modifiers in hexagonal architecture. Example of code

Specific only implementation. Given in comment.

like image 173
Kacper Avatar answered Jan 31 '26 11:01

Kacper



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!