Your database is your API
Collapse the layers, declare the shape once, and keep access rules beside it.
Somewhere in the last decade we stopped thinking of databases as places where things live and started thinking of them as things that need a layer in front before anyone can touch them. A table in one place, a service in front of it, an API in front of that, a client library in front of that. Four layers to read a row.
I want to argue for collapsing them. Not always, but more often than we do.
The pile of translation
Consider a simple request: show me the posts I wrote last week. In a typical stack, that question is translated at least four times. It becomes a query, then an object, then a JSON shape, then a typed client call, then a view model. At each step a bit of meaning is renamed, and a bit of safety is hoped for.
Most of those layers exist for good historical reasons. But when the data is small, the schema is shared, and the team is a handful of people, they are mostly ceremony. Each one is a place for a field name to drift, a type to disagree, a permission check to be forgotten.
Every layer you add is a place for the truth to be told slightly differently.
One declaration
The alternative I keep returning to is declaring the shape of the data once, and letting everything else follow from it. The table, the validation, the read endpoint, the types and the form all derive from one description of what a post is.
When the description changes, everything that depends on it changes with it, or fails loudly at build time. There is no layer where the name was spelled slightly differently, because there is only one place the name was ever spelled.
Where this goes wrong
I do not want to oversell it. A few honest caveats:
Scale changes the answer. A system with millions of users and many teams needs boundaries, and boundaries need contracts.
Not every read is a table. Some endpoints compute, join and aggregate. Derived views deserve their own names.
Access rules are easy to forget. When the data layer is the API, permissions must live in the declaration too, not in a later layer you might skip.
The permission question
The third point deserves attention. A common worry about exposing data directly is that every row becomes readable by everyone. That only follows if access is an afterthought.
The better design treats access as part of the description. For each collection, say who may read and who may change. Public reading of published posts, owner only editing, anonymous likes. If that is declared next to the shape, nobody has to remember it later.
A small experiment
Try this on a side project. Write one file that says what a post is, what its fields are, and who can read and change it. Generate or derive the endpoints from that file. Then add a field, and notice how many places you had to touch. If the answer is one, you have felt what I am describing.
If the answer is five, you have found exactly the places where the truth is being retold, and each of them is worth asking whether it needs to exist.
The goal is not fewer lines of code for their own sake. It is fewer places where two parts of a system can quietly disagree about what a post is.