frontend-svelte-architecture
Use when the user asks about Svelte 5, runes ($state, $derived, $effect, $props, $bindable), .svelte component structure, snippets, or migrating from Svelte 4…
by j4flmao★ 47 GitHub stars
Install frontend-svelte-architecture in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
Svelte Architecture
Purpose
Build applications with Svelte 5 runes — explicit reactivity via $state, $derived, $effect, compiled at build time, no virtual DOM, and minimal runtime.
Agent Protocol
Trigger
Exact user phrases: "Svelte architecture", "Svelte 5", "Svelte runes", "Svelte component", "Svelte reactivity", "Svelte store", "Svelte compiler", ".svelte file".
Input Context
Before activating, verify:
- package.json has svelte ^5 dependency.
- Whether the project uses SvelteKit or Svelte standalone.
- svelte.config.js has compilerOptions: { runes: true } if not default.
Output Artifact
No file output. Produces component code, rune usage, and lifecycle patterns as text.
Response Format
Code: show .svelte components with script, markup, optional style.
No preamble. No postamble. No explanations. No filler/hedging/transitions. Compress output — why use many token when few do trick.
Completion Criteria
- Components use Svelte 5 runes ($state, $derived, $effect, $props).
- Derived values use $derived, not $effect.
- $state provides deep reactivity for objects and arrays.
- State shared across components via $state class instances or context.
- Lifecycle hooks (onMount, onDestroy) tied to component tree.
- Legacy $: syntax replaced with runes in new code.
Max Response Length
Code: 15 lines per example.
Component Architecture / Decision Trees
Architecture Options
| Approach | Trade-off | When to Use |
|---|---|---|
| Single-file .svelte with all logic | Simple, colocated | Small components under 100 lines |
| .svelte.js module for shared state | Separates state from UI | Multiple components share state |
| SvelteKit + load functions | SSR data fetching built-in | Full-stack SvelteKit apps |
| Svelte standalone + adapter | Minimal, SPA-like | Existing non-SvelteKit projects |
| Snippets + render functions | Reusable template fragments | Complex list rendering patterns |
Decision Tree: State Sharing
Does state need to be shared across components?
├── No → $state() locally inside component
└── Yes → Is it component-tree scoped?
├── Yes → setContext() / getContext()
└── No → .svelte.js module with $state class
Decision Tree: Reactivity
Is the value derived from existing state?
├── No → $state()
└── Yes → $derived() or $derived.by()
Is there a side effect (localStorage, analytics)?
├── No → Use $derived
└── Yes → Use $effect with cleanup
Decision Tree: Template Syntax
What kind of logic in template?
├── Conditional display → {#if} {:else if} {:else} {/if}
├── List rendering → {#each items as item (key)} {/each}
├── Await promise → {#await promise} {:then value} {:catch error} {/await}
└── Reusable fragment → {#snippet name()} {@render name()}
Component Design Patterns
Basic Counter
<script>
let count = $state(0)
let doubled = $derived(count * 2)
function increment() { count++ }
function decrement() { count-- }
</script>
<div>
<p>Count: {count}</p>
<p>Doubled: {doubled}</p>
<button onclick={increment}>+</button>
<button onclick={decrement}>-</button>
</div>
Form with Validation
<script>
let email = $state('')
let password = $state('')
let errors = $state<Record<string, string>>({})
let isValid = $derived(email.includes('@') && password.length >= 8)
async function handleSubmit(e: Event) {
e.preventDefault()
const result = schema.safeParse({ email, password })
if (!result.success) { errors = result.error.flatten().fieldErrors; return }
await api.login(result.data)
}
</script>
<form onsubmit={handleSubmit}>
<input type="email" bind:value={email} aria-invalid={!!errors.email} />
{#if errors.email}<span class="error">{errors.email}</span>{/if}
<input type="password" bind:value={password} />
{#if errors.password}<span class="error">{errors.password}</span>{/if}
<button type="submit" disabled={!isValid}>Login</button>
</form>
Data Fetching with onMount
<script>
import { onMount } from 'svelte'
let users = $state<User[]>([])
let loading = $state(true)
let error = $state<string | null>(null)
onMount(async () => {
try {
const res = await fetch('/api/users')
if (!res.ok) throw new Error('Failed to load')
users = await res.json()
} catch (e) {
error = e instanceof Error ? e.message : 'Unknown error'
} finally {
loading = false
}
})
</script>
{#if loading}
<p>Loading...</p>
{:else if error}
<p class="error">{error}</p>
{:else}
{#each users as user (user.id)}
<p>{user.name}</p>
{/each}
{/if}
Snippet Pattern
{#snippet tableRow(item: { id: string; name: string; email: string })}
<tr>
<td>{item.name}</td>
<td>{item.email}</td>
</tr>
{/snippet}
<table>
{#each users as user}
{@render tableRow(user)}
{/each}
</table>
St
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
- references/svelte-5-runes-deep-dive.md
- references/svelte-5-runes.md
- references/svelte-components.md
- references/svelte-optimization.md
- references/svelte-performance-optimization.md
- references/svelte-reactivity.md
- references/svelte-runes.md
- references/svelte-testing.md
FAQ
What does the frontend-svelte-architecture skill do?
Use when the user asks about Svelte 5, runes ($state, $derived, $effect, $props, $bindable), .svelte component structure, snippets, or migrating from Svelte 4 stores and $: syntax. Produces Svelte 5 component and state architecture. Not for SvelteKit routing, load functions or form actions (use sveltekit).
How do I install the frontend-svelte-architecture skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the frontend-svelte-architecture skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
frontend-design
AnthropicGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
webapp-testing
AnthropicToolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
brand-guidelines
AnthropicApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
web-artifacts-builder
AnthropicSuite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…