sveltekit
Skill49 starsChanged 6 months agoMITView on GitHub
Mental-model reset for SvelteKit apps. Use when writing or reviewing routes, layouts, load functions, form actions, remote functions, hooks, auth, cookies, endpoints, redirects, errors, SSR, progressive enhancement, or app-level data flow. Triggers on SvelteKit, +page, +layout, +server, +page.server.ts, +layout.server.ts, hooks.server.ts, load, actions, fail(), redirect(), error(), cookies, locals, route groups, protected routes, sessions, form actions, enhance, remote functions, command(), query(), form(), getRequestEvent(), SSR, hydration, and serialization. Use svelte5 for component-level runes, snippets, accessibility, actions, transitions, and component API review.
6 other projects use a version of this.
Adopted by
Most recently taken up by
- G1Joshi/Agent-Skillstheir own version, first seen Oct 13, 2026
- Mindrally/skillstheir own version, first seen Oct 8, 2026
- epicenter-md/epicentertheir own version, first seen Oct 8, 2026
- EpicenterHQ/epicentertheir own version, first seen Oct 8, 2026
- authdog/agent-skillstheir own version, first seen Sep 18, 2026
- Adhamxon/claude-code-skillstheir own version, first seen Jul 30, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- epicenter-md/epicenter★ 4.8ksame name
- EpicenterHQ/epicenter★ 4.8ksame name
- Mindrally/skills★ 275same name
- G1Joshi/Agent-Skills★ 15same name
- Adhamxon/claude-code-skills★ 2same name
- authdog/agent-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository26 other files it gives its agents.
- AGENTS.mdAGENTS.md
- coding-standardsSkill
- coolify-composeSkill
- crafting-effective-readmesSkill
- diataxisSkill
- english-pleaseSkill
- feature-planning-artifactsSkill
- frontend-design-principlesSkill
- grug-brained-devSkill
- html-artifactsSkill
- improveSkill
- improving-promptsSkill
- jjSkill
- reducing-entropySkill
- researching-codebasesSkill
- roadmapSkill
- roadmap-to-improve-plansSkill
- rustSkill
- salsaSkill
- skill-authoringSkill
- strategic-roadmapSkill
- svelte5Skill
- writing-cli-skillsSkill
- writing-error-messagesSkill
- writing-plansSkill
- writingSkill
The file
We split this skill into the rules it gives an agent
8 rules. 0 are common, 3 are distinctive, and 5 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 21
Use this skill for app-level SvelteKit decisions.
- Very specific: line 45
5. Universal load is for universal work: Use +page.ts only when the code can safely run in both browser and server.
- Very specific: line 61
8. Form actions are the default mutation boundary: If a user submits form-shaped data, prefer a native form plus +page.server.ts action …
- Distinctive: line 76
12. Cookies and locals are request state: Treat them as per-request server data.
- Very specific: line 78
13. API endpoints are their own security boundary: Check method, auth, authorization, input validation, and response shape inside each …
- Very specific: line 84
15. Choose the remote primitive by intent: Use query for repeated reads, command for imperative mutations, and form for form-shaped …
- Distinctive: line 90
17. Hydration mismatches are design feedback: If server and client render different initial markup, fix the data boundary or defer …
- Very specific: line 108
Add use:enhance last — for pending state, focus, and invalidation only.
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Think in SvelteKit
SvelteKit is not just Svelte with folders. It is an application boundary system: route files define ownership of data, server code stays on the server, form submissions progressively enhance, and redirects/errors are part of control flow.
The core failure mode: writing SvelteKit like a client-side SPA with incidental server helpers. Fetching server-owned data from components. Hiding auth in hooks and assuming layouts protect endpoints. Returning class instances from load. Calling redirect() without throwing. Building JavaScript-only forms when native forms plus actions would work. These work until SSR, progressive enhancement, caching, or security boundaries matter.
Use this skill for app-level SvelteKit decisions. Use svelte5 for component internals: runes, snippets, component props, DOM events, accessibility, transitions, and component state.
How SvelteKit Thinks
Routes own application boundaries
1. File names are behavior. +page.svelte, +layout.server.ts, +page.server.ts, and +server.ts are not organization trivia; they decide where code runs and who can call it. See references/file-naming.md.
2. Route groups organize policy, not URLs. (app) and (auth) are for layout/auth/data boundaries without changing paths. Put protected routes under a protected layout; keep login/signup outside that group. See references/layout-patterns.md.
3. Layouts protect pages, not endpoints. A protected +layout.server.ts gates child pages. It does not protect sibling or child +server.ts endpoints; every endpoint must enforce auth itself. See references/auth.md.
Data flow should reveal ownership
4. Server-owned data loads on the server. Database queries, secrets, private APIs, and session-derived data belong in +page.server.ts / +layout.server.ts, not in component onMount or browser fetches. See references/load-functions.md.
// ❌ component fetches server-owned data after mount
onMount(async () => { user = await (await fetch('/api/me')).json(); });
// ✅ +page.server.ts — server owns it, page receives data
export const load = async ({ locals }) => ({ user: await locals.getUser() });5. Universal load is for universal work. Use +page.ts only when the code can safely run in both browser and server. If it needs secrets or trusted auth, it is not universal.
6. Load returns data, not behavior. Return serializable data from server load. Do not return class instances, functions, database handles, or rich objects that depend on identity. See references/serialization.md.
7. Redirects and errors are thrown control flow. In SvelteKit 2, redirect() and error() return objects; throw them. Bare calls are bugs. See references/errors-and-redirects.md.
// ❌ bare call — execution continues, the redirect never happens
if (!locals.user) redirect(303, '/login');
// ✅ throw it
if (!locals.user) throw redirect(303, '/login');Forms are server-first
8. Form actions are the default mutation boundary. If a user submits form-shaped data, prefer a native form plus +page.server.ts action before inventing a client-only mutation path. See references/form-actions.md.
9. Progressive enhancement is enhancement. The form should work without JavaScript; use:enhance improves pending states, focus, invalidation, and UX. It should not be the only way the mutation works.
10. Validation lives at the boundary. Validate on the server, return field-shaped errors with fail, and let the component display them. If the project uses shadcn-svelte or bits-ui, render those errors through Field.* components rather than ad hoc wrappers. See references/forms-validation.md.
// +page.server.ts action — validate server-side, return field-shaped errors
if (!email) return fail(400, { errors: { email: 'Email is required' } });Auth is explicit and boring
11. Hooks populate context; routes enforce policy. hooks.server.ts should parse sessions and populate locals. Layout/server loads and endpoints decide what is allowed. Do not silently skip auth if infrastructure is missing. See references/auth.md.
12. Cookies and locals are request state. Treat them as per-request server data. Do not mirror them into global module state or trust client copies for authorization.
13. API endpoints are their own security boundary. Check method, auth, authorization, input validation, and response shape inside each +server.ts. A page layout is irrelevant to direct HTTP calls.
Remote functions are still server boundaries
14. Remote functions do not remove validation. command, query, and form still cross a client/server boundary. Validate arguments, check auth, and return serializable data. Remote functions are version/feature-flag dependent; confirm the project has opted in before recommending them. See references/remote-functions.md.
15. Choose the remote primitive by intent. Use query for repeated reads, command for imperative mutations, and form for form-shaped submissions. Do not use remote functions to bypass SvelteKit's normal page/form model without a reason.
SSR is the default environment
16. Browser APIs are conditional. window, document, localStorage, media APIs, and DOM measurement do not exist during SSR. Use component effects, browser, or client-only boundaries deliberately. See references/ssr-hydration.md.
17. Hydration mismatches are design feedback. If server and client render different initial markup, fix the data boundary or defer browser-only rendering intentionally. Do not paper over mismatches with random client checks.
Working Through a Change
Work outside-in — settle each boundary before the next:
- Runtime & route boundary. Identify which
+files exist and where each runs (server / universal / endpoint). → Confirm secrets and DB access never reach+page.tsor components. - Data ownership. Server-owned data in
+*.server.ts;loadreturns serializable data. → Confirm no class instances or functions crossload. - Mutations. Form-shaped data goes through a native form +
+page.server.tsaction. → Confirm it works with JavaScript disabled beforeuse:enhanceis added. - Auth. Hooks populate
locals; every page load and every+server.tsenforces policy and fails closed. → Test a direct HTTP call to each endpoint, not just the page. - SSR. Browser APIs gated; initial markup matches. → Render with JS off and confirm no hydration mismatch.
- Order findings: security/correctness first (auth, serialization, thrown control flow), then progressive-enhancement gaps, then ergonomics.
Form action flow
- Native
<form method="POST">with real inputs and labels. +page.server.tsactionsvalidates server-side;return fail(400, { errors })on bad input,throw redirect(...)on success.- Component renders
form?.errors(throughField.*if the project uses shadcn-svelte / bits-ui). - Add
use:enhancelast — for pending state, focus, and invalidation only. - Check: submit with JavaScript disabled; the mutation still works.
Protecting routes
- Protected routes under a group with a protected
+layout.server.ts; login/signup stay outside it. hooks.server.tsparses the session intolocals.- The protected
+layout.server.tsdoesthrow redirect(...)for unauthenticated users. - Each
+server.tsunder protection re-checks auth itself. - Check: a direct request to a protected endpoint with no session is rejected.
Common Mistakes (Agent Failure Modes)
- Fetching server-owned data in
onMount→ use serverload. - Using
$effectto push query/page state into navigation → update the URL in the control's event handler or form submission; derive display values fromdatawhen needed. - Using universal load for secrets → move to
+page.server.tsor+layout.server.ts. - Returning classes/functions from load → return serializable plain data.
- Calling
redirect()/error()withoutthrow→ throw them. - Protecting endpoints via layouts → check auth in every
+server.ts. - Doing auth policy in hooks only → hooks populate
locals; routes enforce. - Silently skipping auth when DB/session infrastructure is missing → fail closed.
- Putting login inside the protected route group → keep auth pages outside protected layouts.
- Building JS-only forms → use native forms + actions + progressive enhancement.
- Trusting client validation → validate on the server boundary.
- Rendering shadcn-svelte validation with raw wrappers → use
Field.Field,Field.Label, andField.Errorin the component. - Using remote functions without auth/validation → treat them as server endpoints.
- Using browser APIs during SSR → gate with effects/browser-only logic.
- Using svelte5 component advice for app data flow → load the SvelteKit reference.
Quick Reference
| Smell | SvelteKit default move | Reference |
| Route file choice unclear | Pick by runtime and boundary | file-naming |
| Protected page group | +layout.server.ts auth check | auth |
| Protected endpoint | auth check inside +server.ts | auth |
| DB/secrets in browser code | server load/action/endpoint | load-functions |
Query/page control updates via $effect | event handler or form submission | load-functions |
| Form-shaped mutation | form action | form-actions |
| Field validation errors | fail(400, { errors }) | forms-validation |
Bare redirect() or error() | throw redirect(...) / throw error(...) | errors-and-redirects |
| Rich object returned from load | serializable plain data | serialization |
| Client-only API in SSR | effect/browser guard | ssr-hydration |
| Repeated server read from client | query() if remote functions fit | remote-functions |
| Imperative server mutation from client | command() with validation/auth | remote-functions |
| Component API/runes issue | use svelte5 | svelte5 |
Reference Index
File Naming · Layout Patterns · Load Functions · Form Actions · Forms Validation · Auth · Errors/Redirects · Serialization · SSR/Hydration · Remote Functions · Better Auth · Cloudflare
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
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.

