1

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.

1 Answer 1

2

I am assuming that what you call a DataBean is a class with getters & setters and no business logic.

If the DataBean is identical to your DTO, it sounds like all your business logic is implemented in the service.

With a DDD approach, the logic would be spread in the domain value and entity objects but I don't see those in your description. It looks like there is only translation of data between different layers.

Are you sure that your bounded context is complex enough to use DDD patterns or that kind of architecture ?

I am wondering if a CRUD or classical layered architecture would not be enough.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.