# Schema Model

> **Section:** [Concepts](https://docs.atmyapp.com/concepts.md)
> **Also:** [HTML version](https://docs.atmyapp.com/concepts/schema) · [Docs index](https://docs.atmyapp.com/llms.txt)

---
The canonical schema model lives in `@atmyapp/structure` and is re-exported from `@atmyapp/core`.

Use schemas to describe what clients can edit, what data your app can read, and what the platform should validate before publishing.

## Definitions

AtMyApp supports two main content definition shapes:

- `defineCollection()` for repeatable content such as posts, authors, products, or case studies.
- `defineDocument()` for singletons such as home page copy, navigation, settings, or SEO defaults.

```ts
import {
  defineCollection,
  defineDocument,
  defineSchema,
  s,
} from "@atmyapp/structure";

export default defineSchema({
  definitions: {
    posts: defineCollection({
      fields: {
        title: s.string({ min: 3 }),
        slug: s.slug({ source: "title" }),
        cover: s.image({ optional: true }),
        publishedAt: s.date({ optional: true }),
      },
    }),
    settings: defineDocument({
      fields: {
        theme: s.string({ default: "light" }),
        supportEmail: s.string({ format: "email" }),
      },
    }),
  },
});
```

## Fields

Fields describe validation, editor behavior, and generated platform payloads. Common field types include strings, dates, images, objects, and references.

## Compilation

The CLI finds `atmyapp.schema.*`, validates it, compiles it with `@atmyapp/structure`, writes normalized canonical JSON to `.ama/definitions.json`, and uploads that same contract during `atmyapp migrate`. The platform stores it as `.structure.json`; legacy input is converted at the compatibility boundary. Schema changes belong to the website repository and CLI workflow.

## Package roles

- `@atmyapp/structure` owns schema authoring, compilation, validation, and introspection.
- `@atmyapp/core` owns runtime client access and re-exports schema helpers.
- `@atmyapp/cli` connects local schemas to the hosted AtMyApp platform.
- `@atmyapp/astro` provides Astro-specific helpers.

## Next steps

Follow [schema design](/guides/structure/) for a full model, [field types](/reference/fields/) for every option, and [JavaScript setup](/quick-start/) to render content. A schema defines editable data; your website code defines its presentation.