Content modeling is the work of deciding what types of content a website has, which fields each type needs, and how the types relate to each other, before you build pages. In Astro, a content model becomes real code: each content type is a collection in src/content.config.ts, each field is a property in a Zod schema, and each relationship is a reference() to another collection. A good model makes pages simple to build, keeps content consistent, and lets you switch to a CMS later without rewriting templates.
This guide walks through modeling a typical business site, from listing content types to writing the schemas, with the trade-offs that come up along the way.
Key Takeaways
- Model content by what it is (a service, a case study, a person), not by the page it appears on.
- Each type becomes a collection with a loader and a Zod schema; required fields fail the build when missing.
- Use
reference()for relationships, such as a case study pointing to its author and services.- Small, repeated data (team, testimonials, FAQs) fits JSON or YAML with the
file()loader.- Keep presentation out of the model: store “featured: true”, not “show in the blue box”.
What content modeling means
A content model is a map of your content. It answers three questions:
- What types exist? Posts, services, case studies, team members, testimonials, locations, FAQs.
- What fields does each type have? A case study has a title, client, year, cover image, summary, body and services used.
- How do types connect? A case study is written by a team member and relates to one or more services.
Without a model, content ends up hard-coded across components. The same testimonial appears in three files with slightly different wording, a team member’s photo lives in four places, and changing a service name means a search across the codebase. With a model, each piece of content lives once and pages query it.
Astro’s content collections are built for exactly this. The content collections guide covers the API; this article is about deciding what to put in it.
Step 1: List content types from real content
Start from the site’s actual content, not from the page list. Take a consultancy site as an example. Its pages are Home, Services, a page per service, Work, a page per case study, About, Blog and Contact. The content types behind those pages are:
| Content type | Example | Appears on |
|---|---|---|
| Service | Brand strategy | Services index, service page, home, case studies |
| Case study | Rebrand for a regional bank | Work index, case study page, service pages, home |
| Team member | A partner’s bio and photo | About, case studies, blog posts |
| Testimonial | A client quote | Home, service pages, case studies |
| Post | An article | Blog index, post page, home |
| FAQ | “How long does a project take?” | Service pages, contact |
Notice that most types appear on several pages. That is the signal they need to be modeled once and reused. A type that appears in exactly one place (the home page hero text, for example) usually does not need a collection; it can stay in the page or a small settings file.
Step 2: Define fields for each type
For each type, list the fields an editor fills in, and mark which are required. A useful rule: if a page would look broken without a field, make it required.
For a case study:
title(required): the headlineclient(required): the client’s nameyear(required): a numbersummary(required): one or two sentences for cards and meta descriptionscover(required): an imageservices(optional): which services this project usedauthor(optional): the team member who wrote itfeatured(default false): whether it appears on the home page- body: the long-form story, written in Markdown or MDX
Keep fields about meaning, not appearance. “featured” is meaning. “background color” or “use large layout” are presentation, and they tie your content to one design. When you redesign, meaning fields survive; presentation fields become clutter.
Step 3: Write the model as collections
Now turn the model into code. Long-form types with a body (posts, case studies, services) become Markdown or MDX collections with the glob() loader. Short, structured types (team, testimonials, FAQs) fit a single JSON or YAML file with the file() loader.
// src/content.config.ts
import { defineCollection, reference } from 'astro:content';
import { glob, file } from 'astro/loaders';
import { z } from 'astro/zod';
const team = defineCollection({
loader: file('src/data/team.json'),
schema: z.object({
name: z.string(),
role: z.string(),
photo: z.string(), // path to a file in public/
bio: z.string(),
}),
});
const services = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/services' }),
schema: z.object({
title: z.string(),
summary: z.string().max(160),
order: z.number().default(0),
}),
});
const work = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/work' }),
schema: ({ image }) =>
z.object({
title: z.string(),
client: z.string(),
year: z.number().int(),
summary: z.string().max(160),
cover: image(),
services: z.array(reference('services')).default([]),
author: reference('team').optional(),
featured: z.boolean().default(false),
}),
});
const testimonials = defineCollection({
loader: file('src/data/testimonials.json'),
schema: z.object({
quote: z.string(),
name: z.string(),
company: z.string(),
service: reference('services').optional(),
}),
});
export const collections = { team, services, work, testimonials };
The file() loader expects an array of objects with an id field (or an object keyed by id):
[
{
"id": "maya",
"name": "Maya Chen",
"role": "Strategy Lead",
"photo": "/team/maya.jpg",
"bio": "Leads brand and positioning work."
}
]
Run npm run dev and Astro validates every entry. A case study missing its client, or pointing to a service id that does not exist, fails with a message naming the file and field.
Step 4: Model relationships with reference()
Relationships are where content modeling pays off. In the schema above, a case study’s services field is an array of references to the services collection. In the content file, you write ids:
---
# src/content/work/regional-bank-rebrand.md
title: Rebrand for a regional bank
client: Northfield Bank
year: 2026
summary: A new identity and website for a bank modernizing its branches.
cover: ./cover.jpg
services: [brand-strategy, web-design]
author: maya
featured: true
---
In a page, resolve the references with getEntry() and getEntries():
---
// src/pages/work/[id].astro
import { getCollection, getEntry, getEntries, render } from 'astro:content';
export async function getStaticPaths() {
const work = await getCollection('work');
return work.map((entry) => ({ params: { id: entry.id }, props: { entry } }));
}
const { entry } = Astro.props;
const { Content } = await render(entry);
const services = await getEntries(entry.data.services);
const author = entry.data.author ? await getEntry(entry.data.author) : undefined;
---
<h1>{entry.data.title}</h1>
<p>{entry.data.client}, {entry.data.year}</p>
<ul>{services.map((s) => <li><a href={`/services/${s.id}/`}>{s.data.title}</a></li>)}</ul>
<Content />
{author && <p>Written by {author.data.name}, {author.data.role}</p>}
Reverse relationships (all case studies for a service) are a filter, not a field:
// inside src/pages/services/[id].astro
const relatedWork = await getCollection('work', ({ data }) =>
data.services.some((ref) => ref.id === service.id)
);
Store a relationship on one side only. If both the service and the case study list each other, they will drift out of sync.
Common content modeling decisions
One collection or two? If two types share most fields and always appear together, use one collection with a type field. If they have different fields or different pages, split them. Blog posts and case studies usually deserve separate collections; “news” and “articles” often do not.
Markdown body or structured fields? Use the Markdown body for free-form writing. Use fields for anything a page needs to place precisely: a price, a date, a stat on a card. A case study’s “results” might be an array of { label, value } objects rather than a paragraph, so the template can show them as a grid.
Slugs and ids. With glob(), the id comes from the file path, which becomes the URL. Choose file names you are happy to keep forever, since changing them changes URLs.
SEO fields. Add an optional description (or reuse summary) and an optional image for social sharing, so every entry can produce its own meta tags. The Astro SEO checklist shows how to render them.
Drafts. A draft: z.boolean().default(false) field plus a filter in getCollection() keeps unfinished entries out of production builds.
Dates. Use z.coerce.date() so both 2026-11-03 and full ISO strings parse into a Date.
Planning for a CMS later
A model written as Zod schemas maps almost directly to a headless CMS. Each collection becomes a content type, each field a CMS field, and each reference() a reference field. When you move content to Sanity, Storyblok or a Git-based CMS, you swap the loader and keep the schema, so pages that call getCollection('work') do not change.
That is the main reason to model carefully even on a small Markdown site: the model, not the storage, is what your templates depend on. The headless CMS guide compares the options, and the Content Collections docs show how Komal themes lay out their collections.
A modeling checklist
- Every content type that appears on more than one page has its own collection
- Required fields are the ones a page cannot render without
- Fields describe meaning, not appearance
- Relationships use
reference()and are stored on one side - Short repeated data lives in JSON or YAML with
file() - Each entry has enough fields to produce its own title, description and social image
- File names (ids) are stable, because they become URLs
If you start from a Komal theme, the collections for its niche (projects, services, posts, team) are already defined, so modeling becomes a matter of adjusting fields rather than starting from nothing. For more on schemas, see Astro’s content collections reference.
FAQ
What is content modeling?
Content modeling is defining the types of content a site has, the fields each type contains, and the relationships between types. It turns loose pages of text into structured, reusable content that templates can query and that editors can fill in consistently.
How do I create a content model in Astro?
Define each content type as a collection in src/content.config.ts with a loader and a Zod schema. Use glob() for Markdown or MDX files, file() for JSON or YAML data, and reference() for fields that point to entries in another collection.
What is the difference between a content model and a database schema?
They are similar ideas. A database schema defines tables and columns for storage, while a content model defines content types and fields from an editor’s and a page’s point of view. In Astro, the content model is enforced at build time by Zod schemas rather than by a database.
How do relationships work in Astro content collections?
Use reference('collectionName') in a schema field, write the referenced entry’s id in the content file, and resolve it in a page with getEntry() for a single reference or getEntries() for an array. Astro validates that the referenced id exists.
Should I model content before choosing a CMS?
Yes. Modeling first means you choose a CMS that fits your content, not the other way around. In Astro, a model written as collection schemas can stay the same while the loader changes from local files to a headless CMS.