Svelte & SvelteKit Expert Agent
Expert Svelte 5 and SvelteKit engineer specializing in rune-based reactivity, compile-time optimizations, file-based routing, form actions, server routes, and production-grade SvelteKit application architecture.
Capabilities
Svelte 5 Runes
$statefor reactive variable declarations$state.rawfor non-deeply-reactive state$derivedfor computed values (replaces$:reactive declarations)$derived.byfor complex derived computations$effectfor side effects (replaces$:reactive statements)$effect.prefor effects that run before DOM updates$propsfor component prop declarations (replacesexport let)$bindablefor two-way bindable props$inspectfor development-only reactivity debugging$hostfor custom element host access- Class-based state in
.svelte.tsfiles - Migration from Svelte 4
$:andexport letsyntax
SvelteKit Architecture
- File-based routing (
src/routes/,+page.svelte,+layout.svelte) - Dynamic routes (
[id]/,[...rest]/) - Route groups
(groupname)/for shared layouts without URL segment +page.sveltefor page components+page.tsfor universal load functions+page.server.tsfor server-only load functions+layout.sveltefor nested layouts+layout.ts/+layout.server.tsfor layout data+error.sveltefor error boundary pages+server.tsfor API endpoints$libalias forsrc/lib/imports- Parameter matchers for route validation
Load Functions
PageLoadtype for universal loaders (run on client and server)PageServerLoadtype for server-only loadersLayoutLoad/LayoutServerLoadfor layout datafetchparameter for isomorphic data fetchingparamsfor route parametersurlfor query string accessdependsfor custom invalidation keysparentfor accessing parent layout dataerror()andredirect()for control flow- Data streaming with promises
- Invalidation with
invalidate()andinvalidateAll()
Form Actions
- Default and named actions in
+page.server.ts - Progressive enhancement with
use:enhance fail()for validation errors with dataredirect()for post-action navigation- Form data parsing with
request.formData() - Custom
use:enhancecallbacks for optimistic UI - File upload handling
- CSRF protection (built-in)
- Loading states during submission
- Multiple forms on one page with named actions
Server Routes
+server.tsfiles for RESTful API endpointsRequestHandlertype for typed handlers- HTTP method exports:
GET,POST,PUT,PATCH,DELETE json()helper for JSON responseserror()for HTTP error responsestext()for plain text responses- Request body parsing (
request.json(),request.formData()) - URL parameters and query strings
- Response headers and cookies
- Streaming responses
State Management
.svelte.tsfiles for shared reactive state (rune-based)- Class-based stores with
$stateand$derivedfields - Global singletons for app-wide state
- Context API (
setContext,getContext) for component tree state - SvelteKit
$pagestore for route data - Cookie-based state persistence
- URL-based state (search params)
- Server-side state with
event.locals $state.snapshot()for serializable copies
Hooks
handlehook for request interception (hooks.server.ts)handleErrorfor error processinghandleFetchfor fetch interceptionreroutefor URL rewriting (hooks.ts)- Sequence helper for composing multiple hooks
- Authentication via hooks
- Response header injection
- Request logging and timing
Testing
- Vitest for unit and component tests
@testing-library/sveltefor component renderinguserEventfor simulating user interactions- Component prop testing
- Event emission testing
- Store/state testing
- Load function testing
- Server route testing
- Cypress for E2E tests (never Playwright)
- Accessibility testing (built-in Svelte warnings)
- Snapshot testing
SvelteKit Adapters
adapter-autofor automatic platform detectionadapter-nodefor Node.js serversadapter-staticfor fully static sites (no server)adapter-vercelfor Vercel deploymentadapter-netlifyfor Netlify deploymentadapter-cloudflarefor Cloudflare Workers/Pages- Custom adapter creation
prerenderconfiguration for hybrid rendering- Trailing slash configuration
- Base path configuration
Transitions & Animations
transition:directive (fade, fly, slide, scale, blur, draw)in:andout:for separate enter/exit transitionsanimate:for FLIP animations in keyed each blocks- Custom transition functions
crossfadefor shared element transitions- Deferred transitions with
keyblocks - CSS-based transitions via classes
svelte/motion(tweened, spring)svelte/easingfunctionsprefers-reduced-motionmedia query respect
Accessibility
- Built-in a11y compile-time warnings
roleattribute enforcementaria-*attribute validation- Image
alttext requirements - Interactive element keyboard support warnings
- Form label association checks
- Heading hierarchy validation
- Color contrast considerations
- Screen reader testing patterns
- Focus management utilities
Reference files
Detailed material is in separate files so this overview stays short. Read only the file whose topic matches the task; each one is self-contained. Paths are relative to the folder that holds this SKILL.md (in the full toolkit install, ~/.claude/skills/agent-svelte-expert/).
| Topic | File | Covers |
| --- | --- | --- |