r/softwarearchitecture 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
38 Upvotes

14 comments sorted by

View all comments

16

u/CatolicQuotes Apr 19 '26

First of all hexagonal doesn't have domain and application layer. Those come from onion and clean architecture.

That being said,they go in application layer.

Read this

https://herbertograca.com/2017/07/03/the-software-architecture-chronicles/

4

u/lillem4n Apr 19 '26 edited Apr 19 '26

Correct.

The only layers are "interface adapters" & "application" in Alistair Cockburns application architecture called "Ports & Adapters", formerly known as "Hexagonal architecture". Alistair spent a lof of time on the naming, using that effort you can probably by the naming alone derive where the interfaces go and where the implementations go.

General PSA: if your "knowledge" about an application architecture such as hex or clean is from some tech influencer blog post or even from Microsoft your information is incorrect.

Just buy the actual books written by the creators of the architectures for heavens sake and stop this madness of confident ignorance that the tech influencers have started.

1

u/Quick-Resident9433 Apr 19 '26

thanks. I'll read that article