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.mjsandastroinpackage.json.astrofiles with a---frontmatter script fence at the topclient:load,client:visibleorclient:idleon components
Where things usually live
- src/pages/
- Routes:
.astro,.mdand.mdxpages, plus.tsendpoints. - 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
astro.config.mjs, to learn the output mode and integrations- The page under
src/pages/and its frontmatter script content.config.ts, for how content is structured
How a request moves through the code
- At build (or request) time, Astro matches a file under
src/pages/. - The frontmatter script runs on the server: fetching data or querying collections.
- The template renders to HTML, including the server output of island components.
- Islands 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.