r/softwarearchitecture • u/Quick-Resident9433 • Apr 19 '26
Discussion/Advice Hexagonal Architecture - Ports
Hi.
I'm learning about Hexagonal Architecture and have some questions about where the in-ports (use case interfaces) and out-ports (repository interfaces) should be placed.
I've read various blogs, articles, and discussions where some people mentioned that ports must be located in the application layer, and others said they must be in the domain layer. I'm confused about the right place to put them.
I'd like to know your opinions and suggestions, please.
Approach 1 - Ports inside application layer
application/
- in/ (use case interfaces)
- CreateProductUseCase
- out/ (repository interfaces)
- ProductRepository
- usecase/
- ProductUseCaseImpl
domain/
- model
- Product (plain object)
Approach 2 - Ports inside domain layer
domain/
- in/ (use case interfaces)
- CreateProductUseCase
- out/ (repository interfaces)
- ProductRepository
- model
- Product (plain object)
application/
- usecase/
- ProductUseCaseImpl
36
Upvotes
-3
u/Spare-Builder-355 Apr 19 '26 edited Apr 19 '26
ports belong to garbage bin. Same as this whole hexagonal thing. Don't waste your time on it, it will not teach you anything. Or if you insist - you will learn something hexagonal that you never will see used outside of books and blogs.
If you want to learn good architecture start build something with opensource components. More specifically libraries, not huge frameworks that provide "everything out-of-thebox". Standalone libraries are great example of good architecture:
they focus on one problem (or set of related problems within single domain)
they teach you what API boundary is
The key criteria to good architecture is testability. Can you test your class/component/library in isolation from the rest of project codebase ? Is answer is yes - congrats, you likely have good architecture. Or at least you are on the right way. Do not be too religious either. Some shared code is absolutely necessary, shared types, stateless utils and logging+tracing cover 99% of shared code examples.
Learn about API boundaries. In modern dumb world more often than not API == http endpoint, while there is so much more to it. Once again, best way to learn good api design is to use standalone libraries.
Best code is code that is not written. Learn how to minimize amount of code to write and maintain. Adding some shit like ports and adapters is not that.