Instructions for building high-quality Svelte 5 and SvelteKit applications with modern runes-based reactivity, TypeScript, and performance optimization.
Project Context
Svelte 5.x with runes system ($state, $derived, $effect, $props, $bindable)
SvelteKit for full-stack applications with file-based routing
TypeScript for type safety and better developer experience
Component-scoped styling with CSS custom properties
Progressive enhancement and performance-first approach
Modern build tooling (Vite) with optimizations
Core Concepts
Architecture
Use Svelte 5 runes system for all reactivity instead of legacy stores
Organize components by feature or domain for scalability
Separate presentation components from logic-heavy components
Extract reusable logic into composable functions
Implement proper component composition with slots and snippets
Use SvelteKit's file-based routing with proper load functions
Component Design
Follow single responsibility principle for components
Use <script lang="ts"> with runes syntax as default
Keep components small and focused on one concern
Implement proper prop validation with TypeScript annotations
Use {#snippet} blocks for reusable template logic within components
Use slots for component composition and content projection
Pass children snippet for flexible parent-child composition
Design components to be testable and reusable
Reactivity and State
Svelte 5 Runes System
Use $state() for reactive local state management
Implement $derived() for computed values and expensive calculations
Use $derived.by() for complex computations beyond simple expressions
Use $effect() sparingly - prefer $derived or function bindings for state sync
Implement $effect.pre() for running code before DOM updates
Use untrack() to prevent infinite loops when reading/writing same state in effects
Define component props with $props() and destructuring with TypeScript annotations
Use $bindable() for two-way data binding between components
Migrate from legacy stores to runes for better performance
Override derived values directly for optimistic UI patterns (Svelte 5.25+)
State Management
Use $state() for local component state
Implement type-safe context with createContext() helper over raw setContext/getContext
Use context API for sharing reactive state down component trees
Avoid global $state modules for SSR - use context to prevent cross-request data leaks
Use SvelteKit stores for global application state when needed
Keep state normalized for complex data structures
Prefer $derived() over $effect() for computed values
Implement proper state persistence for client-side data
Effect Best Practices
Avoid using $effect() to synchronize state - use $derived() instead
Do use $effect() for side effects: analytics, logging, DOM manipulation
Do return cleanup functions from effects for proper teardown
Use $effect.pre() when code must run before DOM updates (e.g., scroll position)
Use $effect.root() for manually controlled effects outside component lifecycle
Use untrack() to read state without creating dependencies in effects
Remember: async code in effects doesn't track dependencies after await
SvelteKit Patterns
Routing and Layouts
Use +page.svelte for page components with proper SEO
Implement +layout.svelte for shared layouts and navigation
Handle routing with SvelteKit's file-based system
Data Loading and Mutations
Use +page.server.ts for server-side data loading and API calls
Implement form actions in +page.server.ts for data mutations
Use +server.ts for API endpoints and server-side logic
Use SvelteKit's load functions for server-side and universal data fetching
Implement proper loading, error, and success states
Handle streaming data with promises in server load functions
Use invalidate() and invalidateAll() for cache management
Implement optimistic updates for better user experience
Handle offline scenarios and network errors gracefully
Forms and Validation
Use SvelteKit's form actions for server-side form handling
Implement progressive enhancement with use:enhance
Use bind:value for controlled form inputs
Validate data both client-side and server-side
Handle file uploads and complex form scenarios
Implement proper accessibility with labels and ARIA attributes
UI and Styling
Styling
Use component-scoped styles with <style> blocks
Implement CSS custom properties for theming and design systems
Use class: directive for conditional styling
Follow BEM or utility-first CSS conventions
Implement responsive design with mobile-first approach
Use :global() sparingly for truly global styles
Transitions and Animations
Use transition: directive for enter/exit animations (fade, slide, scale, fly)
Use in: and out: for separate enter/exit transitions
Implement animate: directive with flip for smooth list reordering
Create custom transitions for branded motion design
Use |local modifier to trigger transitions only on direct changes
Combine transitions with keyed {#each} blocks for list animations
TypeScript and Tooling
TypeScript Integration
Enable strict mode in tsconfig.json for maximum type safety
Annotate props with TypeScript: let { name }: { name: string } = $props()
Type event handlers, refs, and SvelteKit's generated types
Use generic types for reusable components
Leverage $types.ts files generated by SvelteKit
Implement proper type checking with svelte-check
Use type inference where possible to reduce boilerplate
Development Tools
Use ESLint with eslint-plugin-svelte and Prettier for code consistency
Use Svelte DevTools for debugging and performance analysis
Keep dependencies up to date and audit for security vulnerabilities
Document complex components and logic with JSDoc
Follow Svelte's naming conventions (PascalCase for components, camelCase for functions)
Production Readiness
Performance Optimization
Use keyed {#each} blocks for efficient list rendering
Implement lazy loading with dynamic imports and <svelte:component>
Use $derived() for expensive computations to avoid unnecessary recalculations
Use $derived.by() for complex derived values that require multiple statements
Avoid $effect() for derived state - it's less efficient than $derived()
Leverage SvelteKit's automatic code splitting and preloading
Optimize bundle size with tree shaking and proper imports
Profile with Svelte DevTools to identify performance bottlenecks
Use $effect.tracking() in abstractions to conditionally create reactive listeners
Error Handling
Implement +error.svelte pages for route-level error boundaries
Use try/catch blocks in load functions and form actions
Provide meaningful error messages and fallback UI
Log errors appropriately for debugging and monitoring
Handle validation errors in forms with proper user feedback
Use SvelteKit's error() and redirect() helpers for proper responses
Track pending promises with $effect.pending() for loading states
Testing
Write unit tests for components using Vitest and Testing Library
Test component behavior, not implementation details
Use Playwright for end-to-end testing of user workflows
Mock SvelteKit's load functions and stores appropriately
Test form actions and API endpoints thoroughly
Implement accessibility testing with axe-core
Security
Sanitize user inputs to prevent XSS attacks
Use @html directive carefully and validate HTML content
Implement proper CSRF protection with SvelteKit
Validate and sanitize data in load functions and form actions
Use HTTPS for all external API calls and production deployments
Store sensitive data securely with proper session management
Accessibility
Use semantic HTML elements and proper heading hierarchy
Implement keyboard navigation for all interactive elements
Provide proper ARIA labels and descriptions
Ensure color contrast meets WCAG guidelines
Test with screen readers and accessibility tools
Implement focus management for dynamic content
Deployment
Use environment variables for configuration across different deployment stages
Implement proper SEO with SvelteKit's meta tags and structured data
Deploy with appropriate SvelteKit adapter based on hosting platform
Implementation Process
Initialize SvelteKit project with TypeScript and desired adapters
Set up project structure with proper folder organization
Define TypeScript interfaces and component props
Implement core components with Svelte 5 runes
Add routing, layouts, and navigation with SvelteKit
Implement data loading and form handling
Add styling system with custom properties and responsive design
Implement error handling and loading states
Add comprehensive testing coverage
Optimize performance and bundle size
Ensure accessibility compliance
Deploy with appropriate SvelteKit adapter
Common Patterns
Renderless components with slots for flexible UI composition
Custom actions (use: directives) for cross-cutting concerns and DOM manipulation
{#snippet} blocks for reusable template logic within components
Type-safe context with createContext() for component tree state sharing
Progressive enhancement for forms and interactive features with use:enhance
Server-side rendering with client-side hydration for optimal performance
Function bindings (bind:value={() => value, setValue}) for two-way binding
Avoid $effect() for state synchronization - use $derived() or callbacks instead
1---2name: svelte3description: Svelte 5 and SvelteKit Development Instructions4---5# Svelte 5 and SvelteKit Development Instructions67Instructions for building high-quality Svelte 5 and SvelteKit applications with modern runes-based reactivity, TypeScript, and performance optimization.89## Project Context10- Svelte 5.x with runes system ($state, $derived, $effect, $props, $bindable)11- SvelteKit for full-stack applications with file-based routing12- TypeScript for type safety and better developer experience13- Component-scoped styling with CSS custom properties14- Progressive enhancement and performance-first approach15- Modern build tooling (Vite) with optimizations1617## Core Concepts1819### Architecture20- Use Svelte 5 runes system for all reactivity instead of legacy stores21- Organize components by feature or domain for scalability22- Separate presentation components from logic-heavy components23- Extract reusable logic into composable functions24- Implement proper component composition with slots and snippets25- Use SvelteKit's file-based routing with proper load functions2627### Component Design28- Follow single responsibility principle for components29- Use `<script lang="ts">` with runes syntax as default30- Keep components small and focused on one concern31- Implement proper prop validation with TypeScript annotations32- Use `{#snippet}` blocks for reusable template logic within components33- Use slots for component composition and content projection34- Pass `children` snippet for flexible parent-child composition35- Design components to be testable and reusable3637## Reactivity and State3839### Svelte 5 Runes System40- Use `$state()` for reactive local state management41- Implement `$derived()` for computed values and expensive calculations42- Use `$derived.by()` for complex computations beyond simple expressions43- Use `$effect()` sparingly - prefer `$derived` or function bindings for state sync44- Implement `$effect.pre()` for running code before DOM updates45- Use `untrack()` to prevent infinite loops when reading/writing same state in effects46- Define component props with `$props()` and destructuring with TypeScript annotations47- Use `$bindable()` for two-way data binding between components48- Migrate from legacy stores to runes for better performance49- Override derived values directly for optimistic UI patterns (Svelte 5.25+)5051### State Management52- Use `$state()` for local component state53- Implement type-safe context with `createContext()` helper over raw `setContext`/`getContext`54- Use context API for sharing reactive state down component trees55- Avoid global `$state` modules for SSR - use context to prevent cross-request data leaks56- Use SvelteKit stores for global application state when needed57- Keep state normalized for complex data structures58- Prefer `$derived()` over `$effect()` for computed values59- Implement proper state persistence for client-side data6061### Effect Best Practices62- **Avoid** using `$effect()` to synchronize state - use `$derived()` instead63- **Do** use `$effect()` for side effects: analytics, logging, DOM manipulation64- **Do** return cleanup functions from effects for proper teardown65- Use `$effect.pre()` when code must run before DOM updates (e.g., scroll position)66- Use `$effect.root()` for manually controlled effects outside component lifecycle67- Use `untrack()` to read state without creating dependencies in effects68- Remember: async code in effects doesn't track dependencies after `await`6970## SvelteKit Patterns7172### Routing and Layouts73- Use `+page.svelte` for page components with proper SEO74- Implement `+layout.svelte` for shared layouts and navigation75- Handle routing with SvelteKit's file-based system7677### Data Loading and Mutations78- Use `+page.server.ts` for server-side data loading and API calls79- Implement form actions in `+page.server.ts` for data mutations80- Use `+server.ts` for API endpoints and server-side logic81- Use SvelteKit's load functions for server-side and universal data fetching82- Implement proper loading, error, and success states83- Handle streaming data with promises in server load functions84- Use `invalidate()` and `invalidateAll()` for cache management85- Implement optimistic updates for better user experience86- Handle offline scenarios and network errors gracefully8788### Forms and Validation89- Use SvelteKit's form actions for server-side form handling90- Implement progressive enhancement with `use:enhance`91- Use `bind:value` for controlled form inputs92- Validate data both client-side and server-side93- Handle file uploads and complex form scenarios94- Implement proper accessibility with labels and ARIA attributes9596## UI and Styling9798### Styling99- Use component-scoped styles with `<style>` blocks100- Implement CSS custom properties for theming and design systems101- Use `class:` directive for conditional styling102- Follow BEM or utility-first CSS conventions103- Implement responsive design with mobile-first approach104- Use `:global()` sparingly for truly global styles105106### Transitions and Animations107- Use `transition:` directive for enter/exit animations (fade, slide, scale, fly)108- Use `in:` and `out:` for separate enter/exit transitions109- Implement `animate:` directive with `flip` for smooth list reordering110- Create custom transitions for branded motion design111- Use `|local` modifier to trigger transitions only on direct changes112- Combine transitions with keyed `{#each}` blocks for list animations113114## TypeScript and Tooling115116### TypeScript Integration117- Enable strict mode in `tsconfig.json` for maximum type safety118- Annotate props with TypeScript: `let { name }: { name: string } = $props()`119- Type event handlers, refs, and SvelteKit's generated types120- Use generic types for reusable components121- Leverage `$types.ts` files generated by SvelteKit122- Implement proper type checking with `svelte-check`123- Use type inference where possible to reduce boilerplate124125### Development Tools126- Use ESLint with eslint-plugin-svelte and Prettier for code consistency127- Use Svelte DevTools for debugging and performance analysis128- Keep dependencies up to date and audit for security vulnerabilities129- Document complex components and logic with JSDoc130- Follow Svelte's naming conventions (PascalCase for components, camelCase for functions)131132## Production Readiness133134### Performance Optimization135- Use keyed `{#each}` blocks for efficient list rendering136- Implement lazy loading with dynamic imports and `<svelte:component>`137- Use `$derived()` for expensive computations to avoid unnecessary recalculations138- Use `$derived.by()` for complex derived values that require multiple statements139- Avoid `$effect()` for derived state - it's less efficient than `$derived()`140- Leverage SvelteKit's automatic code splitting and preloading141- Optimize bundle size with tree shaking and proper imports142- Profile with Svelte DevTools to identify performance bottlenecks143- Use `$effect.tracking()` in abstractions to conditionally create reactive listeners144145### Error Handling146- Implement `+error.svelte` pages for route-level error boundaries147- Use try/catch blocks in load functions and form actions148- Provide meaningful error messages and fallback UI149- Log errors appropriately for debugging and monitoring150- Handle validation errors in forms with proper user feedback151- Use SvelteKit's `error()` and `redirect()` helpers for proper responses152- Track pending promises with `$effect.pending()` for loading states153154### Testing155- Write unit tests for components using Vitest and Testing Library156- Test component behavior, not implementation details157- Use Playwright for end-to-end testing of user workflows158- Mock SvelteKit's load functions and stores appropriately159- Test form actions and API endpoints thoroughly160- Implement accessibility testing with axe-core161162### Security163- Sanitize user inputs to prevent XSS attacks164- Use `@html` directive carefully and validate HTML content165- Implement proper CSRF protection with SvelteKit166- Validate and sanitize data in load functions and form actions167- Use HTTPS for all external API calls and production deployments168- Store sensitive data securely with proper session management169170### Accessibility171- Use semantic HTML elements and proper heading hierarchy172- Implement keyboard navigation for all interactive elements173- Provide proper ARIA labels and descriptions174- Ensure color contrast meets WCAG guidelines175- Test with screen readers and accessibility tools176- Implement focus management for dynamic content177178### Deployment179- Use environment variables for configuration across different deployment stages180- Implement proper SEO with SvelteKit's meta tags and structured data181- Deploy with appropriate SvelteKit adapter based on hosting platform182183## Implementation Process1841. Initialize SvelteKit project with TypeScript and desired adapters1852. Set up project structure with proper folder organization1863. Define TypeScript interfaces and component props1874. Implement core components with Svelte 5 runes1885. Add routing, layouts, and navigation with SvelteKit1896. Implement data loading and form handling1907. Add styling system with custom properties and responsive design1918. Implement error handling and loading states1929. Add comprehensive testing coverage19310. Optimize performance and bundle size19411. Ensure accessibility compliance19512. Deploy with appropriate SvelteKit adapter196197## Common Patterns198- Renderless components with slots for flexible UI composition199- Custom actions (`use:` directives) for cross-cutting concerns and DOM manipulation200- `{#snippet}` blocks for reusable template logic within components201- Type-safe context with `createContext()` for component tree state sharing202- Progressive enhancement for forms and interactive features with `use:enhance`203- Server-side rendering with client-side hydration for optimal performance204- Function bindings (`bind:value={() => value, setValue}`) for two-way binding205- Avoid `$effect()` for state synchronization - use `$derived()` or callbacks instead
Run npx skillmds@latest add pingqlin/svelte in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Svelte 5 and SvelteKit Development Instructions It is listed under Web & Frontend on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
pingqLIN (@pingqlin) published this skill. Their other Agent Skills are listed on their SkillMD profile.