Design your schema
Choose between documents and collections, nest content, link entries, and write a schema your client understands.
Open with AI
The schema is the contract between your code and your client’s content. It decides what they can change, which values are valid, and what types your code gets back. Good schemas are small, well described, and shaped like the website rather than like a database.
Where it lives
Section titled “Where it lives”Put the schema in the project root as atmyapp.schema.ts. The CLI also finds .mts, .js, .mjs and .json versions, and the older ama.schema.* name. Export it as the default export (or as a named schema export):
import { defineSchema, defineDocument, defineCollection, defineSubmission, s } from "@atmyapp/structure";
export default defineSchema({ description: "Website of Altana, an Italian restaurant.", definitions: { // documents and collections }, submissions: { // forms },});@atmyapp/core re-exports everything from @atmyapp/structure, so either import works. Upload changes with npx atmyapp migrate. The dashboard shows the schema but can’t edit it: your repository is the source of truth.
Documents or collections?
Section titled “Documents or collections?”| Use a… | When the content is… | Examples | Read it with |
|---|---|---|---|
Document (defineDocument) |
One thing, edited as a whole | Homepage, footer, contact details, opening hours | storage.getValue("home") |
Collection (defineCollection) |
Many similar things, added and removed over time | Blog posts, services, team members, menu items | collections.list("posts") |
A useful test: if your client would ever say “add another one”, use a collection.
definitions: { footer: defineDocument({ description: "Footer shown on every page.", fields: { address: s.string(), phone: s.string({ optional: true }), instagram: s.url({ optional: true }), }, }), team: defineCollection({ description: "People on the About page.", fields: { name: s.string({ max: 60 }), role: s.string({ max: 60 }), photo: s.image({ optional: true }), }, }),}Documents are stored at <name>.json unless you set path. Keep the key stable: it’s how your code and the stored content find each other.
Collection entries each get an ID and created and updated times automatically. Don’t declare id, createdAt, updatedAt or _key yourself; those names are reserved. Add s.slug() when entries need readable URLs.
Fields
Section titled “Fields”Every field is required unless you mark it optional: true. The most common ones:
fields: { title: s.string({ max: 80 }), // a line of text summary: s.longText({ max: 300 }), // a paragraph body: s.markdown(), // formatted text (Markdown) price: s.number({ min: 0 }), // a number guests: s.integer({ min: 1, max: 12 }), // a whole number featured: s.boolean({ default: false }), // on/off date: s.date(), // "2026-10-21" kind: s.enum({ values: ["lunch", "dinner"] }),// a fixed choice website: s.url({ optional: true }), email: s.email(), photo: s.image(), // one image menu: s.file({ accept: ["application/pdf"] }),// one file photos: s.gallery(), // several images}The field reference lists every builder and option.
Writing for your client
Section titled “Writing for your client”Your client sees field names, descriptions and limits in the dashboard. The AI assistant reads them too. A few habits make a big difference:
- Describe where it appears.
"Shown under the headline on the homepage."beats"Intro text". - Use real limits. If a heading breaks the layout past 60 characters, say
max: 60. AtMyApp enforces it. - Make optional things optional. Then render the page cleanly when the value is missing.
- Avoid technical fields. Don’t ask your client for CSS classes, raw HTML or IDs. Choices belong in
s.enum().
Empty values: optional and nullable
Section titled “Empty values: optional and nullable”optional: true lets a field be missing. To let your client explicitly clear a value, such as removing an image, add nullable: true:
logo: s.image({ optional: true, nullable: true }),Your code should handle both undefined and null for such a field.
Nested content
Section titled “Nested content”Group related fields with s.object(), and repeat a group with s.array():
home: defineDocument({ fields: { hero: s.object({ fields: { title: s.string({ max: 60 }), image: s.image(), }, }), highlights: s.array({ maxItems: 3, items: s.object({ fields: { title: s.string({ max: 40 }), text: s.string({ max: 140 }), }, }), }), },}),const home = await ama.storage.getValue("home");home.hero.title;home.highlights.map((h) => h.title);Each item in a list of objects gets a stable _key, so edits and reordering don’t mix items up. Use it as a render key (for example key={item._key} in React).
Use an array for a short, bounded list that belongs to one page. If items need their own pages, references from elsewhere, or there could be many of them, use a collection.
Linking entries with references
Section titled “Linking entries with references”A reference stores the ID of a collection entry:
authors: defineCollection({ fields: { name: s.string(), avatar: s.image({ optional: true }) },}),posts: defineCollection({ fields: { title: s.string(), slug: s.slug({ source: "title" }), author: s.reference("authors"), related: s.reference({ target: "posts", multiple: true, optional: true }), },}),The editor picks entries from a list. Your code receives the ID (or a list of IDs), not the entry itself, so fetch the target when you render. Resolve references shows an efficient way. An entry that other entries reference can’t be deleted until the references are removed.
To reference by slug instead of ID, use s.reference({ target: "posts", by: "slug" }). The target must have a slug field built with s.slug().
slug: s.slug({ source: "title" }),A slug is a URL-safe name such as wood-fired-pizza: lowercase letters, numbers and single hyphens, at most 96 characters. It’s generated from source when the entry is created, and it never changes afterwards, even if the title does. Published links keep working.
Editor-controlled order
Section titled “Editor-controlled order”Collections come back newest first. When your client should decide the order, such as for menu sections or team members, add an order field:
team: defineCollection({ fields: { name: s.string(), position: s.order(), },}),Editors arrange the entries in the dashboard, and position stores each one’s rank. Sort by it in your code:
const team = (await ama.collections.list("team")).sort((a, b) => a.position - b.position);An order field must be a top-level collection field. s.order({ groupBy: "category" }) keeps a separate order per value of a single reference field.
Formatted text
Section titled “Formatted text”s.markdown()stores Markdown. Render it with your Markdown library, and decide whether to allow raw HTML.s.mdx({ config: "article" })stores MDX with only the components you allow. See MDX in the field reference.
Plain string fields are plain text. Render them as text, never as HTML.
Forms live under submissions, next to definitions. They use the same field builders:
submissions: { contact: defineSubmission({ fields: { email: s.email(), message: s.longText({ min: 10, max: 5000 }), }, }),},The service validates what visitors send and drops unknown fields. See Forms on any website.
Translations
Section titled “Translations”Localization is in early access and may change. Talk to us before you rely on it in a client project.
Turn on localization: { enabled: true } in the schema and mark text fields with localize: true. s.shortText(), s.longText() and s.markdown() are marked by default. Only string and MDX fields can be translated. Read a language with the locale option, such as getValue("home", { locale: "pl" }). Your website still owns language routing.
Files and images at a fixed path
Section titled “Files and images at a fixed path”For a single managed asset that isn’t part of a document, such as a downloadable price list, use defineFile or defineImage with a path:
priceList: defineFile({ path: "files/price-list.pdf" }),Read its URL with storage.getValue("priceList"), which returns { url }.
Check your work
Section titled “Check your work”npx atmyapp migrate --dry-run # compile and validate locallynpx atmyapp migrate # plan against the project, then apply--dry-run catches schema mistakes without contacting the server. A real migrate also checks your change against the content that already exists. It stops before anything would break, for example when a new required field is missing from existing entries. Change a live schema explains what to do then.
