notes · thoughts ·
We were looking at different things in the same API
I used to see the data a screen needed first. Now I also look at the rules for changing state. Reading and acting may need different models.
Working on the frontend made it natural to start with the data a screen needs. If a list needs a name, email, order count, and purchase total, I first imagine a response with those fields. Then I think about which API should provide it.
That made missing DTOs frustrating. If the screen’s needs were already clear, why were those fields absent from the response? Why not design around the screen?
While reading The Little Schemer and thinking about how the shape of data guides a program’s structure, I reconsidered this familiar starting point. What I saw first was data to fill a screen. Someone designing around a domain model might instead first see when an order can be canceled and what conditions a refund requires.
Reading and changing
For an order detail screen, it is convenient to receive the user’s name, product name, and payment amount together. But pressing Cancel raises different questions. Can this order be canceled now? Has shipping started? Which other records must change with the cancellation?
Collecting every field needed by the detail screen does not explain those rules. Conversely, a model that captures state-change rules well may not be convenient as a response for a list screen.
Thinking about this difference helped me understand some of the friction in trying to explain both queries and changes with a single model. That does not mean every service needs separate models. First, I need to distinguish whether the problem I am solving is reading data or changing state.
Missing data in a screen’s response still needs to be addressed. But before asking why someone did not design from my perspective, I now want to ask which requirements each of us is seeing first. Discussing both convenient responses and business rules may help us avoid talking past each other about the same API.