

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
1# SvelteKit with TypeScript — Cursor Rules23You are an expert Svelte developer building web applications with SvelteKit 2+ and TypeScript.45## Code Style67- Use TypeScript for all `.ts` and `.svelte` files. Enable strict mode in `tsconfig.json`.8- Use `$:` reactive declarations for derived values. Use `$effect` in Svelte 5 runes mode when applicable.9- Prefer `const` over `let`. Use `let` only for values that need reactivity in Svelte components.10- Use `camelCase` for variables and functions, `PascalCase` for components, `kebab-case` for file names and CSS classes.11- Use Prettier with the `prettier-plugin-svelte` plugin for formatting.12- Keep components under 200 lines. Extract reusable logic into separate components or utilities.13- Use `<script lang="ts">` in all Svelte components.14- Prefer semantic HTML elements over generic `<div>` wrappers.1516## SvelteKit Routing1718- Use file-based routing in `src/routes/`. Each folder is a route segment.19- Use `+page.svelte` for page components, `+layout.svelte` for layouts, `+error.svelte` for error pages.20- Use `+page.server.ts` for server-side load functions and form actions. Use `+page.ts` for universal load functions.21- Use route groups `(group)` to share layouts without affecting URL structure.22- Use `+server.ts` for API endpoints that return JSON or other non-HTML responses.23- Use `[param]` for dynamic routes, `[...rest]` for catch-all routes, `[[optional]]` for optional params.24- Prefer `+page.server.ts` load functions over `+page.ts` when data comes from the server or database.2526## Data Loading2728- Use `load` functions in `+page.server.ts` for server-side data fetching. Return typed data objects.29- Type load functions with generated types: `import type { PageServerLoad } from './$types'`.30- Use the `depends()` function to declare custom invalidation keys.31- Use `invalidate()` or `invalidateAll()` to refetch data after mutations.32- Access parent layout data with `await parent()` inside load functions.33- Handle errors in load functions by throwing `error(404, 'Not found')` from `@sveltejs/kit`.34- Use parallel data loading: return an object with multiple promises for concurrent fetching.3536## Form Actions3738- Use form actions in `+page.server.ts` for mutations. Define `actions` object with named actions.39- Use the `<form method="POST" action="?/create">` pattern for progressive enhancement.40- Use `use:enhance` directive for client-side form enhancement without full page reloads.41- Validate form data server-side with Zod or a similar library. Return validation errors with `fail(400, { errors })`.42- Access form data with `const data = await request.formData()` in action functions.43- Return success data from actions so the page can display confirmation messages.44- Use hidden form fields for IDs and other non-user-input data.4546## Component Patterns4748- Use Svelte stores (`writable`, `readable`, `derived`) for shared client state.49- Prefer props for parent-to-child communication. Use events (`createEventDispatcher`) for child-to-parent.50- Use slots for component composition. Named slots for complex layouts.51- Use `{#if}`, `{#each}`, `{#await}` blocks for conditional, list, and async rendering.52- Always include a `key` in `{#each key}` blocks to help Svelte identify items.53- Use `bind:` for two-way binding on form elements. Avoid binding on custom components when one-way data flow suffices.54- Use `use:action` for reusable DOM behavior (click outside, intersection observer, tooltips).5556## State Management5758- Use Svelte stores for global client state: `writable` for mutable state, `derived` for computed state.59- Keep stores in `src/lib/stores/`. Export typed stores with helper functions.60- Use `$store` auto-subscription syntax in components. Use `.subscribe()` in non-component code.61- Prefer server-side state (load functions) over client stores for data that comes from the server.62- Use context API (`setContext`/`getContext`) for component-tree-scoped state.63- For complex state, use a single store with an update function pattern rather than multiple stores.6465## Styling6667- Use scoped `<style>` blocks in Svelte components. Styles are automatically scoped to the component.68- Use CSS custom properties (variables) for theming. Define them in `app.css` or a layout.69- Use Tailwind CSS if configured. Use `@apply` sparingly in `<style>` blocks.70- Use `:global()` selector only when necessary to style elements outside the component scope.71- Use CSS Grid and Flexbox for layout. Avoid floats and position hacks.72- Define responsive breakpoints consistently. Use mobile-first approach.7374## Error Handling7576- Use `+error.svelte` pages for route-level error display.77- Throw `error(statusCode, message)` from `@sveltejs/kit` in load functions and form actions for expected errors.78- Use `handleError` hook in `hooks.server.ts` for unexpected errors. Log the error, return a safe message.79- Validate all user input server-side in form actions and API endpoints.80- Use try/catch in load functions for external API calls. Return fallback data or throw appropriate errors.81- Display user-friendly error messages. Never expose stack traces or internal details.8283## Hooks8485- Use `hooks.server.ts` for server-side request processing: auth, logging, error handling.86- Use the `handle` hook for middleware-like behavior (auth checks, redirects, setting locals).87- Use `handleFetch` to modify or intercept fetch requests made during SSR.88- Use `handleError` to process unexpected errors before they reach the user.89- Access `event.locals` for request-scoped data (authenticated user, request ID).9091## Testing9293- Use Vitest for unit tests and Playwright for end-to-end tests.94- Test components with `@testing-library/svelte`.95- Test load functions by calling them directly with mock event objects.96- Test form actions by calling them with mock request objects.97- Place unit tests alongside components: `UserCard.test.ts` next to `UserCard.svelte`.98- Place e2e tests in a top-level `tests/` directory.99100## File Structure101102```103src/104 lib/105 components/106 ui/ — Reusable UI components (Button, Modal, Card)107 features/ — Feature-specific components108 stores/109 auth.ts — Authentication store110 theme.ts — Theme store111 server/112 db.ts — Database client113 auth.ts — Auth utilities (server-only)114 utils/115 format.ts — Formatting helpers116 validate.ts — Validation schemas117 types/118 index.ts — Shared TypeScript types119 routes/120 +layout.svelte121 +layout.server.ts122 +page.svelte123 +error.svelte124 (auth)/125 login/+page.svelte126 register/+page.svelte127 (app)/128 +layout.svelte129 dashboard/+page.svelte130 settings/+page.svelte131 api/132 users/+server.ts133 hooks.server.ts134 app.css135 app.d.ts136static/137 favicon.png138tests/139 e2e/140```141142## Security143144- Validate all input in server-side load functions and form actions.145- Use `event.locals` for passing authenticated user data — never trust client-side state for auth.146- Set CSRF protection (SvelteKit handles this for form actions by default).147- Sanitize user-generated HTML before rendering. Avoid `{@html}` unless content is trusted or sanitized.148- Use environment variables for secrets. Access them with `$env/static/private` or `$env/dynamic/private`.149- Never expose server-only environment variables to the client. `$env/static/public` and `$env/dynamic/public` only.150- Set appropriate security headers in `hooks.server.ts` or `svelte.config.js`.151152## Performance153154- Use streaming with `+page.server.ts` by returning promises in the load function. SvelteKit streams the response.155- Prerender static pages with `export const prerender = true` in `+page.ts` or `+page.server.ts`.156- Use `$app/navigation` `preloadData` and `preloadCode` for link prefetching.157- Minimize client-side JavaScript: SvelteKit only ships JS for interactive parts.158- Use image optimization with `@sveltejs/enhanced-img` or a CDN.159- Lazy load heavy components with `{#await import('./HeavyComponent.svelte')}`.160- Use `Cache-Control` headers for static assets and API responses.161
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| survivorforge/cursor-rulesrules/ai-ml-python/.cursorrules · 17 | .cursorrules | teststylearchdeployment+2 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/api-microservices/.cursorrules · 17 | .cursorrules | buildteststylearch+5 | 92/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/database-sql/.cursorrules · 17 | .cursorrules | styletypessecuritydatabase+3 | 65/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/devops-docker/.cursorrules · 17 | .cursorrules | setupbuildteststyle+4 | 93/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/devops-infrastructure/.cursorrules · 17 | .cursorrules | buildteststylesecurity+3 | 93/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/django-rest/.cursorrules · 17 | .cursorrules | buildteststylearch+5 | 84/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/docker-devops/.cursorrules · 17 | .cursorrules | setupteststylearch+6 | 85/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/flutter-dart/.cursorrules · 17 | .cursorrules | teststylearchtypes+5 | 89/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/go-gin/.cursorrules · 17 | .cursorrules | testlint-formatstylearch+5 | 84/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/langchain-ai/.cursorrules · 17 | .cursorrules | testlint-formatstylearch+4 | 84/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/mobile-react-native/.cursorrules · 17 | .cursorrules | teststylearchtypes+7 | 89/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/nextjs-14-app-router/.cursorrules · 17 | .cursorrules | teststyletypestesting-strategy+3 | 71/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/nextjs-app-router/.cursorrules · 17 | .cursorrules | teststylearchtypes+5 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/nextjs-typescript/.cursorrules · 17 | .cursorrules | teststylearchtypes+5 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/nextjs/.cursorrules · 17 | .cursorrules | teststylearchtypes+5 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/nodejs-express-typescript/.cursorrules · 17 | .cursorrules | setupteststylearch+7 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/nodejs-express/.cursorrules · 17 | .cursorrules | testlint-formatstylearch+7 | 92/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/performance-optimization/.cursorrules · 17 | .cursorrules | styledatabaseapiperformance+2 | 65/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/python-django/.cursorrules · 17 | .cursorrules | testlint-formatstylearch+6 | 99/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/python-fastapi/.cursorrules · 17 | .cursorrules | testlint-formatstylearch+6 | 99/100 | 13 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/survivorforge-cursor-rules-rules-sveltekit-cursorrules)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.