Model the Data

Keys & Validation — Backend Fundamentals

Keys and validation make generated requests predictable before data reaches custom logic.

Task

Mark the fields that identify records, enforce uniqueness, speed up lookup, or reject invalid input.

SettingUse it whenAvoid
Primary KeyEvery record needs a stable identifierAdding more than one primary identity without a clear reason
RequiredThe backend cannot create a valid record without this valueMarking optional profile or metadata fields as required
UniqueNo two records can share the valueApplying it to names or labels that may repeat
IndexThe app searches, filters, or joins by the field oftenIndexing every field by default
Auto IncA numeric identifier should increase automaticallyUsing it for external IDs, UUIDs, or business codes
ValidationThe value must match a format ruleReplacing clear field types with complex patterns

Steps

  1. Give stored entities a reliable identifier.
  2. Mark required fields only when the caller must provide them during creation.
  3. Use unique for login emails, usernames, slugs, or external references.
  4. Add indexes to fields used in frequent filtering or lookup.
  5. Add validation patterns after the field name and type are final.
  6. Re-run workspace validation before generating code.

Expected Result

Swagger should show the right required fields, the generated database should protect key constraints, and invalid input should fail before the logic flow depends on it.

Next

Use Diagram Builder for field settings and Diagram Builder for validation rules.