
sveltekit-overview
SvelteKit 概览、创建项目、项目类型、项目结构、Web 标准、Routing 技能。当用户创建新 SvelteKit 应用、选择渲染模式(SSR/SSG/SPA/MPA)、理解 +page.svelte/+page.server.js/+layout/+server.js/+error 文件约定、需要使用 Web Fetch/FormData/Stream/URL 等 Web API 时使用。
- Installs
- 66
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/full-stack-skills/svelte-skills --skill sveltekit-overview- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads sveltekit-overview automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
SvelteKit Overview
SvelteKit is the official application framework for Svelte. It provides routing, build pipeline, server runtime, and deployment adapters so that you can ship web apps (SSR, SSG, SPA, MPA, mobile, desktop, embedded) from a single SvelteKit codebase.
When to Use This Skill
Use this skill when you need to:
- Bootstrap a new SvelteKit project with
npx sv create. - Choose between rendering modes (SSR, SSG, SPA, MPA, hybrid).
- Understand the standard project layout (
src/routes,src/lib,static,svelte.config.js). - Decide between
+page.sveltevs+page.jsvs+page.server.jsvs+server.js. - Use Web platform APIs (
fetch,Request,Response,Headers,FormData,ReadableStream,URL,URLSearchParams,crypto) inside SvelteKit handlers. - Type route files with the
$typesmodule (PageLoad,PageServerLoad,LayoutLoad,LayoutServerLoad,RequestHandler,PageProps,LayoutProps). - Build API endpoints with
+server.js(GET / POST / PUT / PATCH / DELETE / OPTIONS / fallback). - Configure layouts, error boundaries (
+error.svelte), and nested routing.
Critical: SvelteKit vs Svelte (When to Use Which)
Svelte is the UI component layer. SvelteKit is the application framework that wraps it.
| Need | Use |
|---|---|
| Render a single component, embed into an existing site | Svelte only |
| Build a full app with routing, data loading, SSR, adapters | SvelteKit |
| SSG / SSR / SPA / MPA / serverless | SvelteKit |
| Use Svelte 5 runes inside a page | Svelte inside SvelteKit |
Rule of thumb: if you have more than one "page", a backend, or want SEO, use SvelteKit.
# Pure Svelte (no routing, no SSR)
npm create vite@latest my-app -- --template svelte
# Full SvelteKit app (routing + SSR + adapters)
npx sv create my-app
Critical: Creating a Project (npx sv create)
# Minimal
npx sv create my-app
cd my-app
npm install
npm run dev # http://localhost:5173
Useful flags (see the sv CLI docs):
# Non-interactive with explicit choices
npx sv create my-app \
--template minimal --types ts --no-add-ons --install npm
# Pick a template
npx sv create my-app --template demo # demo | minimal | library
# Add common add-ons later
npx sv add prettier eslint vitest playwright tailwindcss
The CLI scaffolds: package.json, svelte.config.js, vite.config.js, tsconfig.json, src/app.html, src/routes/+page.svelte, and (depending on options) hooks.client.js, hooks.server.js, service-worker.js.
Critical: Project Types Decision Matrix
Rendering settings are configured per-adapter and per-page (export const prerender = true, export const ssr = false, export const csr = false). Mix-and-match is the norm.
| Project type | Adapter | Config | Use when |
|---|---|---|---|
| Default (SSR + CSR) | any | none | Most apps. SSR first paint, CSR after navigation. |
| Static site generation (SSG) | adapter-static | prerender = true (root or per-page) | Docs, blogs, marketing. |
| Single-page app (SPA) | adapter-static with fallback | ssr = false | App shell + JSON backend, no SEO. |
| Multi-page app (MPA) | any | <body data-sveltekit-reload> + csr = false | Low-JS, server-driven pages. |
| Separate backend | adapter-node or serverless | skip server files | Backend is Go/Rust/Java/PHP. |
| Serverless | adapter-vercel / adapter-netlify / adapter-cloudflare | none | Vercel / Netlify / Cloudflare deploy. |
| Your own server / VPS | adapter-node | none | Self-hosted Node server. |
| Container (Docker/LXC) | adapter-node | none | Inside a container image. |
| Library | @sveltejs/package add-on | choose "library" template | Publish Svelte components as a package. |
| Offline / PWA | any | src/service-worker.js | Offline-capable apps. |
| Mobile | adapter-static | bundleStrategy: 'single' | Wrap with Tauri or Capacitor. |
| Desktop | adapter-static | bundleStrategy: 'single' | Wrap with Tauri / Wails / Electron. |
| Browser extension | adapter-static or community adapter | manifest + extension config | Chrome / Firefox extension. |
| Embedded device | any | bundleStrategy: 'single' | TV / microcontroller (few concurrent requests). |
Critical: Project Structure
my-project/
├ src/
│ ├ lib/
│ │ ├ server/ # server-only lib (use $lib/server alias)
│ │ └ [your libs] # client-safe libs (use $lib alias)
│ ├ params/ # param matchers
│ ├ routes/ # filesystem router (one folder per route)
│ ├ app.html # HTML template (placeholders: %sveltekit.head% etc.)
│ ├ error.html # static fallback error page
│ ├ hooks.client.js
│ ├ hooks.server.js
│ ├ service-worker.js
│ └ instrumentation.server.js
├ static/ # served verbatim (robots.txt, favicon.ico)
├ tests/ # Playwright tests (if added)
├ package.json
├ svelte.config.js
├ tsconfig.json
└ vite.config.js
Key rules:
$lib→src/lib(importable from anywhere).$lib/server→src/lib/server(server-only — SvelteKit blocks client imports).src/routesdefines the URL tree. Each folder is a route;+page.sveltemakes it a page.- Anything not under
src/routesorsrc/app.htmlis optional. - Prefer
importfor assets (Vite hashes them) overstatic/.
Critical: svelte.config.js
The minimum configuration: an empty object. svelte.config.js exports a SvelteConfig object that configures kit, preprocess, compilerOptions, etc.
// svelte.config.js
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
alias: {
$components: 'src/lib/components',
$utils: 'src/lib/utils'
}
}
};
export default config;
See examples/svelte-config.md for 8+ common configurations.
Critical: Web Standards (Fetch / FormData / Streams / URL / Web Crypto)
SvelteKit "uses the platform". The browser-native APIs are available in load functions, +server.js handlers, and hooks. SvelteKit polyfills them on Node-based adapters.
| API | Where it shows up in SvelteKit |
|---|---|
fetch | load, hooks, +server.js, both server and client |
Request | event.request in hooks and +server.js |
Response | return value of +server.js handlers and fetch() |
Headers | event.request.headers, Response.headers |
FormData | form submissions: await event.request.formData() |
ReadableStream | response bodies (streaming, SSE) |
URL | event.url, page.url, beforeNavigate/afterNavigate |
URLSearchParams | url.searchParams.get('foo') |
crypto | crypto.randomUUID(), CSPRNG, hashing |
Special note: inside load functions and +server.js, fetch accepts relative URLs and preserves credentials automatically. Outside those, pass cookies/headers explicitly.
Critical: Routing (+page, +layout, +server, +error, $types)
The filesystem is the router. Route files start with +.
| File | Purpose |
|---|---|
+page.svelte | The page UI. |
+page.js | Universal load function (server + client). |
+page.server.js | Server-only load and form actions. |
+layout.svelte | Wraps pages and nested layouts. |
+layout.js / +layout.server.js | Data load for layouts. |
+server.js | API endpoint (exports HTTP verb handlers). |
+error.svelte | Per-route error boundary. |
*.js (other) | Ignored — colocate components or utils. |
Three rules to memorize:
- All route files can run on the server.
- All route files run on the client EXCEPT
+server.js. +layoutand+errorapply to the directory and ALL subdirectories.
+page triad
<!-- src/routes/blog/[slug]/+page.svelte -->
<script>
/** @type {import('./$types').PageProps} */
let { data } = $props();
</script>
<h1>{data.title}</h1>
// src/routes/blog/[slug]/+page.js -- universal load
/** @type {import('./$types').PageLoad} */
export function load({ params }) {
return { title: params.slug };
}
// src/routes/blog/[slug]/+page.server.js -- server-only
import { error } from '@sveltejs/kit';
/** @type {import('./$types').PageServerLoad} */
export async function load({ params }) {
const post = await db.posts.find(params.slug);
if (!post) error(404, 'not found');
return { post };
}
+layout triad
Layouts wrap pages. The root +layout.svelte MUST render children:
<!-- src/routes/+layout.svelte -->
<script>
let { children } = $props();
</script>
<nav><a href="/">Home</a></nav>
{@render children()}
+server.js (API endpoint)
// src/routes/api/random-number/+server.js
import { json, error } from '@sveltejs/kit';
/** @type {import('./$types').RequestHandler} */
export function GET({ url }) {
const min = Number(url.searchParams.get('min') ?? 0);
const max = Number(url.searchParams.get('max') ?? 1);
if (max <= min) error(400, 'invalid range');
return json({ value: min + Math.random() * (max - min) });
}
Handlers: GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, plus a special fallback that catches everything else.
+error.svelte
<!-- src/routes/blog/[slug]/+error.svelte -->
<script>
import { page } from '$app/state';
</script>
<h1>{page.status} — {page.error.message}</h1>
SvelteKit walks UP the tree to find the closest +error.svelte. If none, the static src/error.html is used.
$types
SvelteKit auto-generates ./$types.d.ts for every route file. Use them for type safety:
| Type | Used in |
|---|---|
PageLoad | +page.js |
PageServerLoad | +page.server.js |
LayoutLoad | +layout.js |
LayoutServerLoad | +layout.server.js |
RequestHandler | +server.js |
PageProps | +page.svelte ({ data, params, form }) |
LayoutProps | +layout.svelte ({ data, children }) |
PageData, LayoutData, ActionData | older / narrower typing |
With VS Code + Svelte extension, types are inferred — you can skip the explicit annotations.
Quick Fixes
- Cannot find module '$lib' —
svelte.config.jsships with the$libalias by default; check that yoursvelte.config.jsextends the right config and that you rannpm run devat least once. - +page.server.js data not showing — confirm the file is named EXACTLY
+page.server.js(with the+). +layoutnot nesting — the layout must{@render children()}somewhere in its template.- 404 on dynamic param —
[slug]folder names create params;[...rest]is a "rest" param (greedy). - Hydration mismatch warning — usually caused by
Date.now()/Math.random()rendering different values on server vs client. Move them toonMountor+page.server.js. Cannot import $lib/server into client code— files undersrc/lib/serverare server-only. Move shared code tosrc/lib.- Service worker not updating — bump the version in
src/service-worker.js(it's a build-time cache buster). - Body extension warning in dev — your
app.htmlshould put%sveltekit.body%inside a<div>, not directly in<body>. Cannot read properties of undefined (reading 'request')— the handler is missingeventdestructuring or you forgot to declareexport async function POST(event)/GET({ request, url }).- Types complain in JSDoc — ensure your
tsconfig.jsonextends./.svelte-kit/tsconfig.json.
Gotchas
+page.jsruns on BOTH server and client. Don't put secrets or DB calls there — use+page.server.js.- Data returned from
+page.server.jsis serialized withdevalue; functions / class instances /Map/Setneed explicit conversion. +server.jsfiles are NOT wrapped by+layout.svelte. They emit raw responses. Usehandlehook for cross-cutting concerns.+error.svelteis NOT used for errors thrown in+server.jsorhandlehook. Usesrc/error.htmlfor that fallback.csr = falseremoves ALL JavaScript on the page — including the client router. Links become full reloads.prerender = trueat the root layout prerenders ALL routes. Override per-page withprerender = false.<a href="/foo">uses the client router. Use<a href="/foo" data-sveltekit-reload>to force a server navigation.URLSearchParams.get()returnsnull(notundefined) when the key is missing.event.urlin+server.jsis a full URL; on the clientpage.urlis also full; relative URLs work inload's special fetch.- Dynamic segments match across
/boundaries ONLY if you use rest params[...rest]. - Browser extensions injecting elements into
<body>directly can break hydration — keep%sveltekit.body%inside a<div>.
FAQ
Q: Do I need TypeScript?
No. npx sv create can scaffold a JS-only project. JSDoc types still work and provide type safety.
Q: Can I use Svelte 5 runes in SvelteKit?
Yes. SvelteKit 2.20+ supports Svelte 5. Use $state, $derived, $props, $effect as usual.
Q: How do I call my own backend from a +page.server.js?
Use fetch (the SvelteKit special one inside load preserves cookies and accepts relative URLs). Outside load, pass cookie/authorization headers explicitly.
Q: Can +page.js and +page.server.js coexist?
No. Use one or the other for the same route. Prefer +page.server.js for sensitive data.
Q: Where do I put API keys?
Server-only env vars in $env/static/private (inlined at build time) or $env/dynamic/private (read at runtime). Never expose private env to client code.
Q: What's the difference between error(404) and throw error(404)?
error() returns a special object — DON'T throw it. Just call error(404, 'msg') and SvelteKit handles the rest.
Q: How do I get query params in a page?
$page.url.searchParams.get('foo') (Svelte 4 store) or page.url.searchParams.get('foo') (Svelte 5 via $app/state).
Q: Can I make a static-only site?
Yes — install adapter-static and set prerender = true in the root layout (or per-page). Build output is plain HTML.
Q: How does SvelteKit differ from Next.js / Nuxt?
File-based router, SSR-then-CSR default, no built-in API style — you write +server.js for endpoints. Adapters are official and well-maintained.
Examples & References
Examples
| File | Description |
|---|---|
| examples/README.md | Index of all examples |
| examples/project-creation.md | npx sv create, --template, --types, --add, --install |
| examples/project-types.md | Each project type with adapter + config snippet |
| examples/project-structure.md | src/, routes, static, package.json, svelte.config.js |
| examples/svelte-config.md | Common svelte.config.js setups (preprocess, kit, alias) |
| examples/web-standards.md | fetch with credentials, Request, Response, FormData, streams, URL |
| examples/routing-pages.md | +page.svelte, +page.js, +page.server.js, params, layouts |
| examples/routing-server.md | +server.js GET/POST/PUT/DELETE, content negotiation, fallback |
References
| File | Description |
|---|---|
| references/README.md | Index of all references |
| references/project-types-reference.md | Full decision matrix for all project types |
| references/project-structure-reference.md | Every file in the standard project layout |
| references/web-standards-reference.md | Fetch / Request / Response / FormData / Streams / URL / Web Crypto in SvelteKit |
| references/routing-reference.md | +page, +layout, +server, +error, $types reference |
FAQ
What does the sveltekit-overview skill do?
SvelteKit 概览、创建项目、项目类型、项目结构、Web 标准、Routing 技能。当用户创建新 SvelteKit 应用、选择渲染模式(SSR/SSG/SPA/MPA)、理解 +page.svelte/+page.server.js/+layout/+server.js/+error 文件约定、需要使用 Web Fetch/FormData/Stream/URL 等 Web API 时使用。
How do I install sveltekit-overview?
Run npx skills add https://github.com/full-stack-skills/svelte-skills --skill sveltekit-overview in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/sveltekit-overview/ (personal) or .claude/skills/sveltekit-overview/ (project).
Which AI agents can use sveltekit-overview?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is sveltekit-overview safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains sveltekit-overview?
It is published by full-stack-skills in full-stack-skills/svelte-skills. It has 66 recorded installs.
More from full-stack-skills/svelte-skills
svelte-runes
full-stack-skills/svelte-skills
Svelte 5 Runes 响应式系统技能。当用户需要使用 $state/$derived/$effect/$props/$bindable/$inspect/$host 等符文,或理解 Svelte 5 显式响应式与 Svelte 4 隐式响应式的区别时使用。
svelte-template-syntax
full-stack-skills/svelte-skills
Svelte 5 模板语法技能。当用户需要使用 {if}/{each}/{await}/{snippet} 等块级语法、{@render}/@{html} 等模板标签、bind:、use:/transition:/in:/out:/animate:、style:/class/class:、{@attach} 等指令,或理解属性、事件、文本表达式等基础模板语法时使用。
svelte-legacy-apis
full-stack-skills/svelte-skills
Svelte 5 Legacy API 技能。当用户需要维护或迁移 Svelte 4 代码,理解 Reactive let/$:/export let/Slots/createEventDispatcher/$$props 等已废弃但仍可用的 Legacy API 时使用。
svelte-lifecycle
full-stack-skills/svelte-skills
Svelte 5 生命周期、Stores、Context、Testing 技能。当用户需要在 Svelte 5 中使用 onMount/onDestroy/tick 生命周期钩子、使用 writable/derived stores 管理状态、使用 createContext 共享组件树状态、编写 Vitest/Storybook/Playwright 测试时使用。
svelte-reference
full-stack-skills/svelte-skills
Svelte 5 API 参考技能。当用户需要查阅 svelte/action、svelte/store、svelte/transition、svelte/animate、svelte/easing、svelte/compiler、svelte/events 的具体 API,或需要查看编译器错误/警告代码时使用。
svelte-runtime
full-stack-skills/svelte-skills
Svelte 5 运行时技能。当用户需要使用 Stores、Context、生命周期钩子(onMount/onDestroy/tick)、命令式组件 API(mount/unmount/render/hydrate)、Hydratable Data、Best Practices 或 Vitest 测试时使用。
Popular frontend & design skills
setup-matt-pocock-skills
mattpocock/skills
Configure this repo for the engineering skills: set up its issue tracker, triage label vocabulary, and domain doc layout. Run once before first use of the other engineering skills.
frontend-design
anthropics/skills
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.
hyperframes-animation
heygen-com/hyperframes
All animation knowledge for HyperFrames — atomic motion rules, multi-phase scene blueprints, scene transitions, broader motion-design techniques, AND the seven runtime adapters (GSAP default, plus Lottie, Three.js, Anime.js, CSS keyframes, Web Animations API, TypeGPU). Use for any motion or animation task: pick 2-4 rules and compose, or load a blueprint, or look up runtime-specific API (e.g. GSAP eases / Lottie player / Three.js mixer). Also covers auditing an existing composition's choreography (animation map) and 24 named text-animation effects. HyperFrames-native: single paused timeline, seek-safe, deterministic.
prototype
mattpocock/skills
Build a throwaway prototype to answer a design question. Use when the user wants to sanity-check whether a state model or logic feels right, or explore what a UI should look like.
hyperframes-core
heygen-com/hyperframes
The HyperFrames composition contract — build one renderable project. Use for composition structure, the data- timing attributes, class="clip", tracks, sub-compositions, variables, framework-owned media playback, deterministic-render rules, and validation. Read before writing composition HTML.
vercel-react-best-practices
vercel-labs/agent-skills
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.