Skip to main content
Prompts Astro v6 Strict Architecture Rules

developer coding developer risk: low

Astro v6 Strict Architecture Rules

Outlines strict rules for Astro v6 development, emphasizing HTML-first philosophy, islands architecture, minimal JavaScript, explicit hydration directives, server-side logic prefer…

PROMPT

# Astro v6 Architecture Rules (Strict Mode)

## 1. Core Philosophy

- Follow Astro’s “HTML-first / zero JavaScript by default” principle:
  - Everything is static HTML unless interactivity is explicitly required.
  - JavaScript is a cost → only add when it creates real user value.

- Always think in “Islands Architecture”:
  - The page is static HTML
  - Interactive parts are isolated islands
  - Never treat the whole page as an app

- Before writing any JavaScript, always ask:
  "Can this be solved with HTML + CSS or server-side logic?"

---

## 2. Component Model

- Use `.astro` components for:
  - Layout
  - Composition
  - Static UI
  - Data fetching
  - Server-side logic (frontmatter)

- `.astro` components:
  - Run at build-time or server-side
  - Do NOT ship JavaScript by default
  - Must remain framework-agnostic

- NEVER use React/Vue/Svelte hooks inside `.astro`

---

## 3. Islands (Interactive Components)

- Only use framework components (React, Vue, Svelte, etc.) for interactivity.

- Treat every interactive component as an isolated island:
  - Independent
  - Self-contained
  - Minimal scope

- NEVER:
  - Hydrate entire pages or layouts
  - Wrap large trees in a single island
  - Create many small islands in loops unnecessarily

- Prefer:
  - Static list rendering
  - Hydrate only the minimal interactive unit

---

## 4. Hydration Strategy (Critical)

- Always explicitly define hydration using `client:*` directives.

- Choose the LOWEST possible priority:

  - `client:load`
    → Only for critical, above-the-fold interactivity

  - `client:idle`
    → For secondary UI after page load

  - `client:visible`
    → For below-the-fold or heavy components

  - `client:media`
    → For responsive / conditional UI

  - `client:only`
    → ONLY when SSR breaks (window, localStorage, etc.)

- Default rule:
  ❌ Never default to `client:load`
  ✅ Prefer `client:visible` or `client:idle`

- Hydration is a performance budget:
  - Every island adds JS
  - Keep total JS minimal

📌 Astro does NOT hydrate components unless explicitly told via `client:*` :contentReference[oaicite:0]{index=0}

---

## 5. Server vs Client Logic

- Prefer server-side logic (inside `.astro` frontmatter) for:
  - Data fetching
  - Transformations
  - Filtering / sorting
  - Derived values

- Only use client-side state when:
  - User interaction requires it
  - Real-time updates are needed

- Avoid:
  - Duplicating logic on client
  - Moving server logic into islands

---

## 6. State Management

- Avoid client state unless strictly necessary.

- If needed:
  - Scope state inside the island only
  - Do NOT create global app state unless required

- For cross-island state:
  - Use lightweight shared stores (e.g., nano stores)
  - Avoid heavy global state systems by default

---

## 7. Performance Constraints (Hard Rules)

- Minimize JavaScript shipped to client:
  - Astro only loads JS for hydrated components :contentReference[oaicite:1]{index=1}

- Prefer:
  - Static rendering
  - Partial hydration
  - Lazy hydration

- Avoid:
  - Hydrating large lists
  - Repeated islands in loops
  - Overusing `client:load`

- Each island:
  - Has its own bundle
  - Loads independently
  - Should remain small and focused :contentReference[oaicite:2]{index=2}

---

## 8. File & Project Structure

- `/pages`
  - Entry points (SSG/SSR)
  - No client logic

- `/components`
  - Shared UI
  - Islands live here

- `/layouts`
  - Static wrappers only

- `/content`
  - Markdown / CMS data

- Keep `.astro` files focused on composition, not behavior

---

## 9. Anti-Patterns (Strictly Forbidden)

- ❌ Using hooks in `.astro`
- ❌ Turning Astro into SPA architecture
- ❌ Hydrating entire layout/page
- ❌ Using `client:load` everywhere
- ❌ Mapping lists into hydrated components
- ❌ Using client JS for static problems
- ❌ Replacing server logic with client logic

---

## 10. Preferred Patterns

- ✅ Static-first rendering
- ✅ Minimal, isolated islands
- ✅ Lazy hydration (`visible`, `idle`)
- ✅ Server-side computation
- ✅ HTML + CSS before JS
- ✅ Progressive enhancement

---

## 11. Decision Framework (VERY IMPORTANT)

For every feature:

1. Can this be static HTML?
   → YES → Use `.astro`

2. Does it require interaction?
   → NO → Stay static

3. Does it require JS?
   → YES → Create an island

4. When should it load?
   → Choose LOWEST priority `client:*`

---

## 12. Mental Model (Non-Negotiable)

- Astro is NOT:
  - Next.js
  - SPA framework
  - React-first system

- Astro IS:
  - Static-first renderer
  - Partial hydration system
  - Performance-first architecture

- Think:
  ❌ “Build an app”
  ✅ “Ship HTML + sprinkle JS”

ROLES & RULES

  1. Follow Astro’s “HTML-first / zero JavaScript by default” principle.
  2. Everything is static HTML unless interactivity is explicitly required.
  3. JavaScript is a cost → only add when it creates real user value.
  4. Always think in “Islands Architecture”.
  5. The page is static HTML.
  6. Interactive parts are isolated islands.
  7. Never treat the whole page as an app.
  8. Before writing any JavaScript, always ask: "Can this be solved with HTML + CSS or server-side logic?".
  9. Use `.astro` components for layout, composition, static UI, data fetching, server-side logic (frontmatter).
  10. `.astro` components run at build-time or server-side.
  11. Do NOT ship JavaScript by default.
  12. Must remain framework-agnostic.
  13. NEVER use React/Vue/Svelte hooks inside `.astro`.
  14. Only use framework components (React, Vue, Svelte, etc.) for interactivity.
  15. Treat every interactive component as an isolated island: independent, self-contained, minimal scope.
  16. NEVER hydrate entire pages or layouts.
  17. NEVER wrap large trees in a single island.
  18. NEVER create many small islands in loops unnecessarily.
  19. Prefer static list rendering.
  20. Hydrate only the minimal interactive unit.
  21. Always explicitly define hydration using `client:*` directives.
  22. Choose the LOWEST possible priority: `client:load` only for critical above-the-fold, `client:idle` for secondary, `client:visible` for below-fold, `client:media` for responsive, `client:only` only when SSR breaks.
  23. Never default to `client:load`.
  24. Prefer `client:visible` or `client:idle`.
  25. Keep total JS minimal.
  26. Prefer server-side logic (inside `.astro` frontmatter) for data fetching, transformations, filtering / sorting, derived values.
  27. Only use client-side state when user interaction requires it or real-time updates are needed.
  28. Avoid duplicating logic on client.
  29. Avoid moving server logic into islands.
  30. Avoid client state unless strictly necessary.
  31. Scope state inside the island only.
  32. Do NOT create global app state unless required.
  33. For cross-island state: use lightweight shared stores (e.g., nano stores).
  34. Avoid heavy global state systems by default.
  35. Minimize JavaScript shipped to client.
  36. Prefer static rendering, partial hydration, lazy hydration.
  37. Avoid hydrating large lists.
  38. Avoid repeated islands in loops.
  39. Avoid overusing `client:load`.
  40. Each island: has its own bundle, loads independently, should remain small and focused.
  41. Keep `.astro` files focused on composition, not behavior.
  42. NEVER using hooks in `.astro`.
  43. NEVER turning Astro into SPA architecture.
  44. NEVER hydrating entire layout/page.
  45. NEVER using `client:load` everywhere.
  46. NEVER mapping lists into hydrated components.
  47. NEVER using client JS for static problems.
  48. NEVER replacing server logic with client logic.
  49. Use static-first rendering.
  50. Use minimal, isolated islands.
  51. Use lazy hydration (`visible`, `idle`).
  52. Use server-side computation.
  53. Use HTML + CSS before JS.
  54. Use progressive enhancement.

EXPECTED OUTPUT

Format
markdown

CAVEATS

Missing context
  • Specific task or code to apply these rules to (e.g., code review, generation)

QUALITY

OVERALL
0.92
CLARITY
0.95
SPECIFICITY
0.95
REUSABILITY
0.85
COMPLETENESS
0.90

IMPROVEMENT SUGGESTIONS

  • Add concrete code examples for key rules and anti-patterns.
  • Include enforcement mechanisms like ESLint rules or CI checks.
  • Transform decision framework into a prompted step-by-step reasoning chain for AI use.

USAGE

Copy the prompt above and paste it into your AI of choice — Claude, ChatGPT, Gemini, or anywhere else you're working. Replace any placeholder sections with your own context, then ask for the output.

MORE FOR DEVELOPER