Lesson 1 of 4 · 30 min

Data Model First: Planning a Web App for AI Agents

Why the tables come before the screens.

XDQ Tutor · AI guide

Hello. In this lesson I will take you through 3 ideas, one at a time.

  1. Screens follow data
  2. Rules live with the data
  3. Migrations as reviewed changes

Why it matters: Why the tables come before the screens. After each idea I will ask you one quick question.

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.

Quick check

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.

Quick check

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.

Key takeaways
  • 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
Try it

Model a clinic booking system: list five entities with fields, mark personal data, and write who may read and change each entity.

That is the lesson.
Mark it complete to track your progress on this device.
← CourseCourse overviewNext lesson →How to Build an Admin Panel with AI Agents