sveltekit-structure

Organize SvelteKit routing, layouts, error handling, and SSR file naming.

6|Updated Jul 7, 2017
One-click install
npx skills add https://github.com/Seeker1911/dotfiles --skill sveltekit-structure-seeker1911
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sveltekit-structure
Source: https://github.com/Seeker1911/dotfiles/tree/main/agents/skills/sveltekit-structure
Command: npx skills add https://github.com/Seeker1911/dotfiles --skill sveltekit-structure-seeker1911

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Structuring a SvelteKit application effectively, including routing, nested layouts, error handling, and understanding Server-Side Rendering (SSR) and hydration, can be challenging for new and experienced developers alike. This Skill provides clear, actionable guidance on best practices, helping you build scalable and maintainable applications.

Core Features & Use Cases

  • Routing & File Naming: Master SvelteKit's file-system-based routing, including +page.svelte, +layout.svelte, +server.ts, and dynamic parameters, to create intuitive URLs.
  • Layout Patterns: Implement nested layouts and use route groups (group) to organize application sections and apply different UI structures or authentication boundaries.
  • Robust Error Handling: Understand how to place and utilize +error.svelte files to create effective error boundaries and handle various HTTP status codes gracefully.
  • Use Case: When you're setting up a new SvelteKit project, refactoring an existing one, or troubleshooting routing and layout issues, this Skill helps you apply the correct structural patterns for scalability and maintainability.

Quick Start

Show me how to create a nested layout structure in SvelteKit where a root layout applies to all pages, and a dashboard-specific layout applies only to routes under /dashboard.

Frequently Asked Questions about sveltekit-structure

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure routing in SvelteKit with +page and +layout files?

SvelteKit uses file-system-based routing where +page.svelte files define route content and +layout.svelte files wrap multiple routes with shared UI. Place +page.svelte in a directory to create a route, and +layout.svelte at any level to apply a layout to that directory and its children. Nested directories create nested routes with cascading layouts.

What's the best way to implement nested layouts in SvelteKit?

Create +layout.svelte files at different directory levels in your routes folder. A root +layout.svelte applies to all pages; child layouts apply only to their directory and descendants. Use `<slot />` in each layout to render child content, enabling shared headers, navigation, or authentication boundaries across specific route groups.

How do I handle errors and create error boundaries in SvelteKit?

Place +error.svelte files at any route level to create error boundaries. Errors thrown in that route or its children are caught and rendered by the nearest +error.svelte. Use multiple +error.svelte files at different hierarchy levels to handle errors contextually and display appropriate messages for different HTTP status codes.

What's the difference between +page.svelte and +server.ts in SvelteKit?

+page.svelte files render UI components on the client and server during hydration and SSR. +server.ts files handle API endpoints and server-only logic, returning JSON or other data without rendering HTML. Use +server.ts for data loading, form handling, and backend operations; use +page.svelte for UI rendering.

How do route groups and folder organization affect SvelteKit layout structure?

Route groups use parentheses syntax—e.g., (auth) or (dashboard)—to organize routes without affecting URL paths. Group directories can have their own +layout.svelte files to apply layouts only to routes within that group. This lets you organize authentication boundaries, different UI structures, or logical sections without changing your public URL structure.

When should I use dynamic parameters and +server.ts for server-side rendering in SvelteKit?

Use dynamic parameters (like [id].svelte) to create parameterized routes that render different content per URL. Use +server.ts to fetch or process data server-side during SSR, reducing client-side hydration work. Combine them to build scalable apps where the server renders HTML with data pre-fetched, and the client hydrates efficiently.