Back to Blog

Astro Content Collections: Managing Content Without a Database

#astro#webdev#cms
Astro Content Collections: Managing Content Without a Database

When I rebuilt this site with Astro — migrating away from the old Laravel CMS, Postgres and Docker included — one of the features that gave me the most relief was Content Collections. It’s what lets my blog and portfolio run without a database at all. All the content is just Markdown files in the src/content/ folder.

How it works

You define a schema (using Zod) for each “collection” — this site has two, blog and portfolio — with required fields (title, description, publish date) and optional ones (tags, image, video). Astro automatically validates every Markdown file against that schema at build time. If a field has the wrong type, or is missing, the build fails immediately with a clear error pointing at exactly which file and field is the problem. That’s a lot safer than a database-backed CMS, which usually doesn’t have type validation that strict — in my old setup, a typo in a publish-date field wouldn’t show up until the page was already live and looking broken.

What makes this fit my case

Writing a new post now is just creating a new .md file with the right frontmatter, commit, push. No logging into an admin panel, no API call to a backend, no database to back up or maintain separately. Compared to the old CMS, where I had to keep Postgres itself up and running, that’s a meaningful difference — one less thing that can go down in the middle of the night.

It also fits my workflow well, since I often brainstorm content with AI and then hand-edit it. Markdown files are easy to generate and edit directly, both by me in a regular editor and by the AI tools I use for a first draft — there’s no API layer or proprietary format to translate through first.

There’s one thing I had to build a habit around: since each collection has its own locale (id/ and en/), I have to be disciplined about keeping filenames identical across both folders — this site’s language switcher assumes the slugs match exactly, it doesn’t translate the path automatically. The one time I forgot and the English file ended up with a different name, the language switcher just 404’d. Not hard to fix, but it’s a convention I have to maintain manually, not one the system enforces on its own.

If you’re building a personal blog or portfolio and don’t need complex CMS features — multi-user editing, approval workflows, and the like — Astro’s content collections are well worth trying.