agentleFS
musaJawad004musaJawad004/heron/.claude/skills/svelte5-init/SKILL.md

svelte5-init

Skill1 starsChanged 3 months agoMITView on GitHub

Scaffolds a new Svelte 5 or SvelteKit application with Tailwind CSS v4, TypeScript, and deployment adapter configuration. Use when the user wants to create, initialize, or start a new Svelte 5 project, SvelteKit app, or asks about project setup with Tailwind. Supports deployment targets like Cloudflare, Vercel, Netlify, Node, and static sites.

  • Installs packages

The file

Show its rules and text

We split this skill into the rules it gives an agent

31 rules. About 0 are common, 7 are distinctive, and 24 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 24

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before starting, ask the user (if not already specified):

    line 12
  2. Very specific:

    If the user does not specify a deployment target, use auto.

    line 24
  3. Very specific:

    Use the official sv CLI to create the project:

    line 35
  4. Distinctive:

    If the user wants a library instead of an app, use the "library" template.

    line 46
  5. Very specific:

    If sv create is not available or fails, fall back to:

    line 48
  6. Very specific:

    No action needed. @sveltejs/adapter-auto is installed by default and auto-detects the platform (Cloudflare, Vercel, Netlify, Azure, AWS, …

    line 60
  7. Very specific:

    Update src/app.d.ts to type platform bindings:

    line 100
  8. Very specific:

    Create a Dockerfile if the user wants containerized deployment:

    line 254
  9. Very specific:

    Important: All pages must be prerenderable.

    line 309
  10. Distinctive:

    If Tailwind was not added during scaffolding, install it manually:

    line 349
  11. Very specific:

    Create or update src/app.css:

    line 367
  12. Very specific:

    Update tsconfig.json to ensure strict mode:

    line 386
  13. Very specific:

    Create src/app.d.ts with proper type declarations (skip if already created in Step 2 for Cloudflare):

    line 401
  14. Very specific:

    Create src/app.html if not present:

    line 426
  15. Very specific:

    Create src/error.html as a static fallback:

    line 478
  16. Very specific:

    Add scripts to package.json:

    line 561
  17. Distinctive:

    Verify: open the browser, confirm the page renders with Tailwind styles and the counter works.

    line 580
  18. Very specific:

    Use $props() for component inputs, never export let

    line 614
  19. Very specific:

    Use $state, $derived, $effect runes (not $: reactive declarations)

    line 615
  20. Very specific:

    Use {#snippet} + {@render} instead of <slot>

    line 616
  21. Very specific:

    Use onclick={handler} instead of on:click={handler}

    line 617
  22. Very specific:

    Use callback props instead of createEventDispatcher

    line 619
  23. Very specific:

    Use reactive classes in .svelte.ts for shared state (not stores)

    line 620
  24. Very specific:

    Keep src/routes/ thin: data passing and composition only

    line 624
  25. Very specific:

    Use $lib imports instead of deep relative paths

    line 626
  26. Very specific:

    Keep server-only code in $lib/server/

    line 627
  27. Very specific:

    Use $env/static/private for secrets, $env/static/public for client config

    line 628
  28. Distinctive:

    Use TypeScript with explicit types for props and exported functions

    line 631
  29. Distinctive:

    Use Tailwind v4 utility classes for styling

    line 632
  30. Very specific:

    Every page has a unique <title> (accessibility + SEO)

    line 634
  31. Distinctive:

    Test server actions first (they are pure functions), then components, then E2E

    line 635

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Svelte 5 + SvelteKit Project Initialization

Scaffold a production-ready Svelte 5 / SvelteKit project with Tailwind CSS v4, TypeScript strict mode, and modern conventions.

User parameters

Before starting, ask the user (if not already specified):

  1. Project name: directory name for the project
  2. Deployment target: where the app will run. Options:
    • auto (default) - auto-detects platform at build time
    • cloudflare - Cloudflare Workers / Pages
    • vercel - Vercel serverless / edge
    • netlify - Netlify functions / edge
    • node - Self-hosted Node.js server
    • static - Static site generation (SSG)
    • spa - Single-page application (client-only)

If the user does not specify a deployment target, use auto.

Prerequisites

  • Node.js 18.13+ (22+ recommended)
  • pnpm (preferred) or npm

Workflow

Step 1: Scaffold the project

Use the official sv CLI to create the project:

npx sv create <project-name>

When prompted, select:

  • Template: SvelteKit minimal (or skeleton if available)
  • Type checking: TypeScript
  • Add-ons: Select Tailwind CSS, prettier, eslint

If the user wants a library instead of an app, use the "library" template.

If sv create is not available or fails, fall back to:

npx create-svelte@latest <project-name>

Step 2: Install and configure the deployment adapter

Based on the user's chosen deployment target, install the appropriate adapter.

auto (default)

No action needed. @sveltejs/adapter-auto is installed by default and auto-detects the platform (Cloudflare, Vercel, Netlify, Azure, AWS, Google Cloud).

cloudflare

pnpm add -D @sveltejs/adapter-cloudflare

svelte.config.js:

import adapter from '@sveltejs/adapter-cloudflare';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: vitePreprocess(),
  kit: {
    adapter: adapter()
  }
};

export default config;

Create wrangler.jsonc:

{
  "name": "<project-name>",
  "main": ".svelte-kit/cloudflare/_worker.js",
  "compatibility_flags": ["nodejs_als"],
  "compatibility_date": "2025-01-01",
  "assets": {
    "binding": "ASSETS",
    "directory": ".svelte-kit/cloudflare"
  }
}

Update src/app.d.ts to type platform bindings:

declare global {
  namespace App {
    interface Error {
      message: string;
      code?: string;
    }
    interface Locals {}
    interface PageData {}
    interface PageState {}
    interface Platform {
      env: {
        // Add your KV, D1, R2 bindings here, e.g.:
        // MY_KV: KVNamespace;
      };
      ctx: ExecutionContext;
      caches: CacheStorage;
      cf: IncomingRequestCfProperties;
    }
  }
}

export {};

Add to .gitignore:

.wrangler

Important: Cloudflare Workers cannot use Node.js fs. Use read() from $app/server to read static files, or prerender routes that need file access.

vercel

pnpm add -D @sveltejs/adapter-vercel

svelte.config.js:

import adapter from '@sveltejs/adapter-vercel';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: vitePreprocess(),
  kit: {
    adapter: adapter()
  }
};

export default config;

Per-route configuration is available via config export:

// src/routes/api/heavy/+server.ts
export const config = {
  runtime: 'nodejs22.x', // or 'edge'
  regions: ['iad1'],
  maxDuration: 15
};

For ISR (Incremental Static Regeneration):

// src/routes/blog/[slug]/+page.server.ts
export const config = {
  isr: {
    expiration: 60 // seconds
  }
};

netlify

pnpm add -D @sveltejs/adapter-netlify

svelte.config.js:

import adapter from '@sveltejs/adapter-netlify';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: vitePreprocess(),
  kit: {
    adapter: adapter({
      edge: false,
      split: false
    })
  }
};

export default config;

Create netlify.toml:

[build]
  command = "npm run build"
  publish = "build"

Set edge: true for Netlify Edge Functions (Deno-based, lower latency). Note: edge and split cannot both be true.

node

pnpm add -D @sveltejs/adapter-node

svelte.config.js:

import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: vitePreprocess(),
  kit: {
    adapter: adapter({
      out: 'build',
      precompress: true
    })
  }
};

export default config;

Run in production:

ORIGIN=https://my.site node build

For reverse proxy setups, use header-based origin detection:

PROTOCOL_HEADER=x-forwarded-proto HOST_HEADER=x-forwarded-host node build

Create a Dockerfile if the user wants containerized deployment:

FROM node:22-slim AS build
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile
COPY . .
RUN pnpm build

FROM node:22-slim
WORKDIR /app
COPY --from=build /app/build ./build
COPY --from=build /app/package.json .
ENV NODE_ENV=production
ENV PORT=3000
EXPOSE 3000
CMD ["node", "build"]

static

pnpm add -D @sveltejs/adapter-static

svelte.config.js:

import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: vitePreprocess(),
  kit: {
    adapter: adapter({
      pages: 'build',
      assets: 'build',
      precompress: true,
      strict: true
    })
  }
};

export default config;

Enable prerendering in root layout:

// src/routes/+layout.ts
export const prerender = true;

Important: All pages must be prerenderable. No form actions, no url.searchParams in load functions, no dynamic user-specific content.

spa

Uses @sveltejs/adapter-static with a fallback page:

pnpm add -D @sveltejs/adapter-static

svelte.config.js:

import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: vitePreprocess(),
  kit: {
    adapter: adapter({
      fallback: '200.html'
    })
  }
};

export default config;

Disable SSR in root layout:

// src/routes/+layout.ts
export const ssr = false;

Warning: SPA mode hurts SEO and performance (no server rendering, multiple round trips before content shows). Prefer hybrid rendering (prerender static pages + SSR dynamic pages) when possible.

Step 3: Install Tailwind CSS v4

If Tailwind was not added during scaffolding, install it manually:

pnpm add -D tailwindcss @tailwindcss/vite

Configure the Vite plugin in vite.config.ts:

import { sveltekit } from '@sveltejs/kit/vite';
import tailwindcss from '@tailwindcss/vite';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [tailwindcss(), sveltekit()]
});

Create or update src/app.css:

@import 'tailwindcss';

Import in src/routes/+layout.svelte:

<script lang="ts">
  import '../app.css';
  let { children } = $props();
</script>

{@render children()}

Step 4: Configure TypeScript strict mode

Update tsconfig.json to ensure strict mode:

{
  "extends": "./.svelte-kit/tsconfig.json",
  "compilerOptions": {
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "exactOptionalPropertyTypes": false
  }
}

Step 5: Set up the app type declarations

Create src/app.d.ts with proper type declarations (skip if already created in Step 2 for Cloudflare):

declare global {
  namespace App {
    interface Error {
      message: string;
      code?: string;
    }
    interface Locals {
      // Add per-request state here (e.g., user session)
    }
    interface PageData {
      // Add shared page data here
    }
    interface PageState {
      // Add shallow routing state here
    }
    interface Platform {}
  }
}

export {};

Create src/app.html if not present:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="icon" href="%sveltekit.assets%/favicon.png" />
    %sveltekit.head%
  </head>
  <body data-sveltekit-preload-data="hover">
    <div style="display: contents">%sveltekit.body%</div>
  </body>
</html>

Step 6: Create the root layout

src/routes/+layout.svelte:

<script lang="ts">
  import '../app.css';

  let { children } = $props();
</script>

<svelte:head>
  <meta name="description" content="App description" />
</svelte:head>

{@render children()}

Step 7: Create the root error page

src/routes/+error.svelte:

<script lang="ts">
  import { page } from '$app/state';
</script>

<svelte:head>
  <title>Error {page.status}</title>
</svelte:head>

<h1>{page.status}</h1>
<p>{page.error?.message}</p>

Create src/error.html as a static fallback:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>%sveltekit.status%</title>
  </head>
  <body>
    <h1>%sveltekit.status%</h1>
    <p>%sveltekit.error.message%</p>
  </body>
</html>

Step 8: Create a sample home page

src/routes/+page.svelte:

<script lang="ts">
  let count = $state(0);
</script>

<svelte:head>
  <title>Home</title>
</svelte:head>

<h1 class="text-3xl font-bold">Welcome</h1>
<button class="rounded bg-blue-500 px-4 py-2 text-white" onclick={() => count++}>
  Clicks: {count}
</button>

Step 9: Set up testing

Install Vitest and Playwright:

pnpm add -D vitest @testing-library/svelte @testing-library/jest-dom jsdom playwright @playwright/test
npx playwright install

Create vitest.config.ts:

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';

export default defineConfig({
  plugins: [sveltekit()],
  test: {
    include: ['src/**/*.{test,spec}.{js,ts}'],
    environment: 'jsdom',
    setupFiles: ['./vitest-setup.ts']
  }
});

Create vitest-setup.ts:

import '@testing-library/jest-dom/vitest';

Create playwright.config.ts:

import type { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  webServer: {
    command: 'pnpm build && pnpm preview',
    port: 4173
  },
  testDir: 'tests',
  testMatch: /(.+\.)?(test|spec)\.[jt]s/
};

export default config;

Add scripts to package.json:

{
  "scripts": {
    "test": "vitest",
    "test:unit": "vitest run",
    "test:e2e": "playwright test"
  }
}

Step 10: Install dependencies and verify

pnpm install
pnpm dev

Verify: open the browser, confirm the page renders with Tailwind styles and the counter works.

Project structure summary

src/
  app.css               # Tailwind import
  app.d.ts              # Type declarations
  app.html              # Root HTML template
  error.html            # Static error fallback
  lib/
    domains/            # Business domain modules
      auth/             # Auth components, state, services
      ...
    shared/             # Generic UI components (Button, Modal, etc.)
    server/             # Server-only utilities
    utils/              # Pure utility functions
  routes/
    +layout.svelte      # Root layout
    +error.svelte       # Root error boundary
    +page.svelte        # Home page
tests/                  # E2E tests (Playwright)
svelte.config.js        # SvelteKit config with adapter
vite.config.ts          # Vite config with Tailwind plugin
vitest.config.ts        # Vitest config
playwright.config.ts    # Playwright config
wrangler.jsonc          # Only for Cloudflare target
netlify.toml            # Only for Netlify target
Dockerfile              # Only for Node target (if containerized)

Conventions to follow

Svelte 5 syntax (mandatory)

  • Use $props() for component inputs, never export let
  • Use $state, $derived, $effect runes (not $: reactive declarations)
  • Use {#snippet} + {@render} instead of <slot>
  • Use onclick={handler} instead of on:click={handler}
  • Use {@attach fn} instead of use:action
  • Use callback props instead of createEventDispatcher
  • Use reactive classes in .svelte.ts for shared state (not stores)

Architecture

  • Organize code by domain ($lib/domains/), not by technical layer
  • Keep src/routes/ thin: data passing and composition only
  • Business logic in .svelte.ts files, not in components
  • Use $lib imports instead of deep relative paths
  • Keep server-only code in $lib/server/
  • Use $env/static/private for secrets, $env/static/public for client config

Quality

  • Use TypeScript with explicit types for props and exported functions
  • Use Tailwind v4 utility classes for styling
  • Semantic HTML elements (<button>, <nav>, <main>, not <div onclick>)
  • Every page has a unique <title> (accessibility + SEO)
  • Test server actions first (they are pure functions), then components, then E2E

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.