--- name: astro description: "Building fast, optimized websites using Astro with TypeScript and optional React islands. SSG, SSR, partial hydration, component islands. Trigger: When building Astro websites, implementing component islands, or configuring SSG/SSR." skills: - conventions - a11y - react - typescript - architecture-patterns - humanizer dependencies: astro: ">=5.0.0 <6.0.0" typescript: ">=5.0.0 <6.0.0" react: ">=18.0.0 <19.0.0" allowed-tools: - documentation-reader - web-search --- # Astro Skill ## Overview This skill provides guidance for building static sites with Astro, focusing on SSG patterns, minimal JavaScript, proper directive usage, and integration with React islands. ## Objective Enable developers to build fast, optimized static sites using Astro with proper TypeScript support, minimal runtime JavaScript, and effective use of client directives for interactivity. --- ## When to Use Use this skill when: - Building static websites with SSG (Static Site Generation) - Creating server-rendered sites with SSR (Server-Side Rendering) - Implementing hybrid SSG + SSR approaches - Creating content-focused sites (blogs, documentation, marketing) - Implementing partial hydration with component islands - Using React/Vue/Svelte components selectively - Optimizing for performance and minimal JavaScript - Building with dynamic data that needs server rendering Don't use this skill for: - Full SPA applications (use react or vue directly) - Highly dynamic, client-heavy apps requiring constant client state - Real-time dashboards with WebSocket connections --- ## 📚 Extended Mandatory Read Protocol **This skill has a `references/` directory with detailed guides for rendering strategies, content, and interactivity.** ### Reading Rules **Read references/ when:** - **MUST read [ssg-patterns.md](references/ssg-patterns.md)** when: - Building static sites (no adapter) - Using getStaticPaths for dynamic routes - Fetching data at build time - **MUST read [ssr-patterns.md](references/ssr-patterns.md)** when: - Building dynamic pages with user-specific data - Using Astro.locals, server endpoints - Implementing authentication - **MUST read [hybrid-strategies.md](references/hybrid-strategies.md)** when: - Combining SSG + SSR in same project - Migrating from SSG to Hybrid - Deciding which pages should be static vs dynamic - **MUST read [client-directives.md](references/client-directives.md)** when: - Adding interactivity to static pages - Choosing load/visible/idle/only strategies - Optimizing JavaScript bundle size - **CHECK [content-collections.md](references/content-collections.md)** when: - Managing blog posts, documentation - Type-safe content with schemas - **CHECK [actions.md](references/actions.md)** when: - Handling form submissions - Server-side validation **Quick reference only:** Use this SKILL.md for project type detection and quick decisions. Decision Tree below directs you to specific references. ### Reading Priority | Situation | Read This | Why | | ------------------------ | ----------------------------------- | ------------------------------ | | Static site (no adapter) | **ssg-patterns.md** (REQUIRED) | 50+ SSG-specific patterns | | Dynamic site (adapter) | **ssr-patterns.md** (REQUIRED) | Authentication, server context | | Mixing SSG + SSR | **hybrid-strategies.md** (REQUIRED) | Decision matrix, migration | | Adding interactivity | **client-directives.md** (REQUIRED) | 6 hydration strategies | | Content management | **content-collections.md** (CHECK) | Type-safe schemas | | Form handling | **actions.md** (CHECK) | Server validation | **See [references/README.md](references/README.md)** for complete navigation guide. --- ## Critical Patterns ### ✅ REQUIRED: Detect Project Type First ```javascript // Check astro.config.mjs to understand project type: // ✅ SSG-only project (no adapter) export default defineConfig({ output: 'static', // or omit (default) // No adapter = SSG-only project }); // ✅ SSR project (has adapter) export default defineConfig({ output: 'server', adapter: node(), // Adapter present = SSR capable }); // ✅ Hybrid project (has adapter + hybrid mode) export default defineConfig({ output: 'hybrid', adapter: node(), // Can do both SSG and SSR }); // ❌ WRONG: Using SSR patterns in SSG-only project // If no adapter in config, DON'T use: // - export const prerender = false // - Astro.locals // - Server endpoints with POST/PUT/DELETE ``` ### ✅ REQUIRED: Use .astro Components by Default ```astro --- interface Props { title: string; } const { title } = Astro.props; ---

{title}

``` ### ✅ REQUIRED: Use Client Directives Sparingly ```astro