Skip to content

How to understand a Astro codebase

Astro renders pages to HTML with no JavaScript by default. Interactive parts are islands: components from React, Vue, Svelte or others that hydrate only when marked with a `client:` directive. Content sites keep Markdown and data in content collections with typed schemas.

How to tell it's Astro

  • astro.config.mjs and astro in package.json
  • .astro files with a --- frontmatter script fence at the top
  • client:load, client:visible or client:idle on components

Where things usually live

src/pages/
Routes: .astro, .md and .mdx pages, plus .ts endpoints.
src/layouts/
Page shells that wrap content with <slot />.
src/components/
Astro components and framework islands.
src/content.config.ts
Content collection definitions and schemas (Astro 5); older versions use src/content/config.ts.
src/content/
Markdown and data files for collections.
src/middleware.ts
Runs on requests in server-rendered mode.
astro.config.mjs
Integrations, adapter, output mode, site URL.

Conventions, not rules. Real projects rename and move things, so confirm against the repository.

Where to start reading

  1. astro.config.mjs, to learn the output mode and integrations
  2. The page under src/pages/ and its frontmatter script
  3. content.config.ts, for how content is structured

How a request moves through the code

  1. 1At build (or request) time, Astro matches a file under src/pages/.
  2. 2The frontmatter script runs on the server: fetching data or querying collections.
  3. 3The template renders to HTML, including the server output of island components.
  4. 4Islands with a client: directive ship their JavaScript and hydrate in the browser.

Questions to ask about the repository

  • Which components hydrate in the browser, and with which directive?
  • Is this site static, server-rendered or hybrid, and which pages are which?
  • How are content collections defined, and which pages list them?

What trips people up

  • Frontmatter code runs only on the server; it can't respond to clicks.
  • Without a client: directive, a React or Vue component renders as static HTML, so interactivity silently does nothing.
  • Content collection APIs changed in Astro 5; check the version before copying examples.