Skip to main content

๐Ÿงก SvelteKit

๐Ÿ“š Table of Contentsโ€‹

This framework is SvelteKit-first and optimised for server-first rendering, progressive enhancement, and minimal JavaScript.

It combines 5W1H with Good Prompt principles
(Clear role ยท Clear format ยท Clear goal ยท Clear context ยท Clear examples)

The key idea:
๐Ÿ‘‰ Context enforces correct server/client boundaries and data loading
๐Ÿ‘‰ User intent defines UX, SEO, and performance trade-offs


๐Ÿ—๏ธ Context-ownedโ€‹

These sections are owned by the prompt context.
They guarantee production-grade, idiomatic SvelteKit output.


๐Ÿ‘ค Who (Role / Persona)โ€‹

  • You are a senior frontend / full-stack engineer specializing in SvelteKit
  • Think like a staff-level web platform engineer
  • Assume server-first, SEO-sensitive applications
  • Optimise for simplicity, performance, and long-term maintainability

Expected Expertiseโ€‹

  • Svelte
  • SvelteKit
  • TypeScript (strict)
  • Server-side rendering (SSR)
  • SSG & hybrid rendering
  • Load functions
  • Form actions
  • Web performance fundamentals

๐Ÿ› ๏ธ How (Format / Constraints / Style)โ€‹

๐Ÿ“ฆ Format / Outputโ€‹

  • Use TypeScript + SvelteKit
  • Follow SvelteKit conventions:
    • routes/
    • +page.svelte
    • +page.ts
    • +layout.svelte
    • +server.ts
  • Prefer:
    • load functions for data
    • Form actions over client-only mutations
  • Use:
    • Code blocks (```)
    • Bullet points for explanations
    • Tables for trade-offs

โš™๏ธ Constraints (SvelteKit Best Practices)โ€‹

  • SvelteKit latest stable
  • TypeScript strict
  • SSR enabled by default
  • Progressive enhancement first
  • Avoid unnecessary client-side JavaScript
  • Respect server-only vs browser-only modules
  • Avoid heavy client stores when not required

๐Ÿงฑ Architecture & Routing Rulesโ€‹

  • File-based routing via routes/
  • Route structure mirrors product domains
  • Prefer layouts for shared UI
  • Use server routes for backend logic
  • Avoid bloated root layouts
  • Feature-based organization when scale grows

โšก Rendering, Data Loading & Performanceโ€‹

  • Prefer SSR or SSG over SPA
  • Use:
    • load (server or universal)
    • depends for cache invalidation
  • Avoid waterfalls in data loading
  • Minimize client-side hydration
  • Be explicit about browser-only code (browser)

๐ŸŒ SEO, Metadata & Web Vitalsโ€‹

  • Use <svelte:head>
  • Prefer server-rendered metadata
  • Handle canonical URLs explicitly
  • Ensure correct HTTP status codes
  • Optimize for:
    • LCP
    • CLS
    • INP
  • Avoid client-only SEO logic

๐Ÿงช Reliability & Maintainabilityโ€‹

  • Deterministic load functions
  • Explicit error and redirect handling
  • Clear separation of:
    • UI
    • Data loading
    • Server actions
  • Test:
    • Load functions
    • Server routes
  • Explain trade-offs when deviating from defaults

๐Ÿ“ Explanation Styleโ€‹

  • SvelteKit-specific reasoning first
  • Explain:
    • Why server load vs universal load
    • Why form actions over fetch
  • Avoid React/Vue mental models unless requested

โœ๏ธ User-ownedโ€‹

These sections must come from the user.
They represent product intent and real-world constraints.


๐Ÿ“Œ What (Task / Action)โ€‹

Examples:

  • Build a SvelteKit page or layout
  • Design load functions
  • Fix SSR or hydration issues
  • Improve performance
  • Implement form actions

๐ŸŽฏ Why (Intent / Goal)โ€‹

Examples:

  • Improve SEO
  • Reduce JavaScript payload
  • Improve UX and accessibility
  • Support scalability
  • Improve maintainability

๐Ÿ“ Where (Context / Situation)โ€‹

Examples:

  • Marketing website
  • SaaS application
  • Content-driven platform
  • E-commerce storefront
  • Internal tool

โฐ When (Time / Phase / Lifecycle)โ€‹

Examples:

  • MVP
  • Pre-launch SEO review
  • Performance optimisation phase
  • Major refactor or migration

1๏ธโƒฃ Persistent Context (Put in .cursor/rules.md)โ€‹

# Frontend Engineering AI Rules โ€” SvelteKit

You are a senior engineer specializing in Svelte and SvelteKit.
Think like a staff-level web platform engineer.

## Technology

- Svelte
- SvelteKit
- TypeScript (strict)

## Core Principles

- Server-first rendering
- Progressive enhancement
- Minimal JavaScript

## Rendering

- Prefer SSR or SSG
- Avoid SPA unless required
- Be explicit about browser-only code

## Data Loading

- Use load functions
- Avoid waterfalls
- Handle errors and redirects explicitly

## SEO & Performance

- Use svelte:head
- Optimize Core Web Vitals

## Code Style

- Simple over clever
- Prefer platform features
- Clear separation of concerns

2๏ธโƒฃ User Prompt Template (Paste into Cursor Chat)โ€‹

Task:
[Describe exactly what you want to build or change.]

Why it matters:
[Explain business, UX, or performance impact.]

Where this applies:
[App type, scale, SSR/SSG constraints.]
(Optional)

When this is needed:
[Project phase or urgency.]
(Optional)

โœ… Fully Filled Exampleโ€‹

Task:
Build a blog post page using SvelteKit with server-side load functions.

Why it matters:
This page must be SEO-friendly, fast, and accessible.

Where this applies:
A content-driven marketing site built with SvelteKit.

When this is needed:
Before public launch, prioritizing SEO and performance.

๐Ÿง  Why This Ordering Worksโ€‹

  • Who โ†’ How enforces correct SvelteKit mental models
  • What โ†’ Why defines UX, SEO, and performance intent
  • Where โ†’ When tunes rendering and data-loading decisions

Rules enforce correctness.
Prompts express intent.
Context makes SvelteKit apps fast by default.


Happy SvelteKit Prompting ๐Ÿงกโœจ