golang-clean-architecture
golang-clean-architecture copied to clipboard
Refactor DTO Usage to Separate Data Transfer from Usecase Logic
trafficstars
Currently, DTOs are being used within the usecase layer, which couples data transfer with business logic. To improve modularity and maintain independence in our usecase layer, we should refactor as follows:
- DTO Responsibility: Use DTOs solely for receiving data from external sources such as HTTP requests, RPC calls, and message queues. Separation of Concerns: Create specific DTOs for each external protocol or source.
- Conversion Process: Convert the received DTOs into the application's domain model in a separate layer or component, ensuring that the usecase layer remains independent and focused solely on business logic.
- This refactoring will enhance code maintainability and adhere to best practices by decoupling data representation from usecase functionality.