Sveltekit data flow

From spences10/skills · View interactive version

Sveltekit data flow is an AI agent skill from the GitHub repository spences10/skills. SvelteKit data flow guidance. Use when working with load functions, form actions, server/client boundaries, serialization, or invalidation.

How to use this skill

Skill file

SvelteKit Data Flow

Quick Start

Environment variables: Prefer explicit env vars (src/env.ts + $app/env/private|public) when the experimental flag is enabled.

Which file? Server-only (DB/secrets): +page.server.ts |

Universal (runs both): +page.ts | API: +server.ts

Load decision: Need server resources? → server load | Need client

APIs? → universal load

Form actions: Always +page.server.ts. Return fail() for

errors, throw redirect() to navigate, throw error() for failures.

Example

// +page.server.ts
import { fail, redirect } from '@sveltejs/kit';

export const load = async ({ locals }) => {
	const user = await db.users.get(locals.userId);
	return { user }; // Must be JSON-serializable
};

export const actions = {
	default: async ({ request }) => {
		const data = await request.formData();
		const email = data.get('email');

		if (!email) return fail(400, { email, missing: true });

		await updateEmail(email);
		throw redirect(303, '/success');
	},
};

Reference Files

universal

patterns

serialize

fail/redirect/error

invalidateAll() after client-side auth

typed, validated env vars

Notes

throw redirect()/error()

<!--

PROGRESSIVE DISCLOSURE GUIDELINES:

LLM WORKFLOW (when editing this file):

  1. Write/edit SKILL.md
  2. Format (if formatter available)
  3. Run: npx skills add . --list
  4. If the skill is not discovered, check SKILL.md frontmatter formatting
  5. Validate again to confirm

-->

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.