I’ve a spring application (webservice that connect to a database and retrieve data) using a hexagonal architecture and DDD (Domain-Driven Design).
The basic struture is
Application
Controller to webservice
Spring security configuration
Domain
Services
Exception
Infrastructure
Persistence (repository + entities)
I’m facing some questions related with DTO (data transfer object) layer location.
From what I understood it’s recommended to have DTOs on Application layer but it also implies to duplicate code and harder maintenance for simple project like mine.
To respect the architecture as is we’d need to follow this logic
Application
DataController (webservice)
DataDto
Domain
DataService
DataBean
Mapper (to convert from DataBean to DataDto -> used by DataService)
Infrastructure
Mapper (to convert from DataEntity to DataBean)
DataEntity
But what if DataDto is the same as DataBean? Aren’t this counter-productive since we are duplicating code and make the maintenance harder?
It wouldn’t be better to have Dto on domain like the following?
Application
DataController (webservice)
Domain
DataService
DataDto
Infrastructure
Mapper (to convert from DataEntity to DataDto)
DataEntity
What is the best way? Thanks for your inputs.