Schema

A schema defines the structure and rules for your data — what fields exist, what types they are, and what constraints apply. Schemas appear everywhere in vibe coding: database schemas define table structures, validation schemas verify user input, and API schemas document endpoints. They're the blueprint your data follows.

Example

A user schema defines: name (string, required), email (string, unique), age (number, optional), createdAt (date, auto-generated). This schema ensures every user record follows the same structure and catches invalid data before it enters your database.

Schemas bring order to data. Without them, your database accepts anything — with them, only valid, well-structured data gets through.

Types of Schemas

Database Schema

Defines your tables, columns, and relationships:

model User {
  id    Int     @id @default(autoincrement())
  name  String
  email String  @unique
  posts Post[]
}

Validation Schema

Verifies user input meets rules:

const signupSchema = z.object({
  email: z.string().email(),
  password: z.string().min(8),
  name: z.string().min(2),
})

API Schema

Documents what endpoints accept and return.

Why Schemas Matter

Without SchemasWith Schemas
Any data acceptedOnly valid data passes
Bugs from bad dataErrors caught early
Inconsistent recordsUniform data structure
Hard to understandSelf-documenting

Schemas and AI

AI generates schemas extremely well. Describe your data model in plain language:

  • "I need a schema for a blog with posts, categories, and comments"
  • "Create a Zod validation schema for a contact form"
  • "Design a database schema for an e-commerce store"

AI understands data modeling deeply and produces clean, well-structured schemas.

The Schema-First Approach

  1. Define your data — What entities exist? What fields do they have?
  2. Generate schemas — Let AI create database and validation schemas
  3. Build from schemas — CRUD operations, forms, and APIs follow naturally
  4. Evolve with migrations — Change schemas as requirements grow