Data Model First: Planning a Web App for AI Agents
Why the tables come before the screens.
Hello. In this lesson I will take you through 3 ideas, one at a time.
Why it matters: Why the tables come before the screens. After each idea I will ask you one quick question.
In this lessonFollows you as you read
Screens follow data
The short version: Agents build quickly on a stable data model and badly on a moving one.
Agents build quickly on a stable data model and badly on a moving one. If the tables change after ten screens exist, every screen needs rework. Decide the entities, their fields and their relations first.
Write each entity with the reason it exists. Bookings, customers, payments, staff. For every field ask who writes it, who reads it and whether it is personal data.
Why decide the data model first?
Rules live with the data
The short version: Put access rules beside the model: who can read a row, who can change it, what is logged.
Put access rules beside the model: who can read a row, who can change it, what is logged. If the rules live only in screen code, the next generated screen will forget them.
Enforce rules in the API or database layer. A screen is a convenience. The rule is the control.
Where should access rules be enforced?
Migrations as reviewed changes
The short version: Every change to the model is a migration file reviewed by a person.
Every change to the model is a migration file reviewed by a person. The data agent may draft it. An engineer reads it, because a wrong migration loses data.
Test migrations on a copy of real-shaped data before they touch production. Agents are good at writing the migration and poor at knowing what your production data looks like.
- Fix the data model before building screens
- Record why each field exists and if it is personal data
- Access rules belong in the API or database
- Migrations are always reviewed by a person
Model a clinic booking system: list five entities with fields, mark personal data, and write who may read and change each entity.
Mark it complete to track your progress on this device.