What is a DTO and Why?

TL;DR

A DTO (Data Transfer Object) is an interface for a domain model between applications or layers. In a simple app, it may not add much.

Context

DTOs show up often in architecture talk, yet I rarely use them. Writing Python dataclasses reminded me they are DTOs in practice, so it’s worth being clear about what they are.

DTO as an Interface

I use dataclass definitions to share structures across modules and to keep them separate from persistence concerns. Each class becomes an interface into the domain that exposes shape but not behavior. In that sense, a DTO is a read-and-write interface for data, not a bundle of logic.

When Do We Use It?

Only when modules truly need a shared contract. In those situations, DTOs decouple modules by hiding implementation details from other layers.

Why?

The same reason we use interfaces: DTOs improve maintainability and extensibility by isolating data representation from business or persistence logic.

Appendix

Why I hate DTOs (and many clean architecture patterns)