Skip to main content
rule

web-app-optimization-cursorrules-prompt-file — Cursor rule

Cursor prompt instructions for developing web apps with Svelte 5, SvelteKit, TypeScript, and runes.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/web-app-optimization-cursorrules-prompt-file.mdc
Open on GitHub

What web-app-optimization-cursorrules-prompt-file does

This rule guides Cursor to build applications using Svelte 5 and SvelteKit conventions. The assistant outputs reactive state using runes such as $state, $derived, $effect, and $props. Complex component state belongs in .svelte.ts files structured as classes. For file naming, it enforces lowercase with hyphens for .svelte components and PascalCase in imports.

The UI stack relies on Tailwind CSS with Shadcn primitives imported from $lib/components/ui. Utility classes must pass through cn() from $lib/utils. For TypeScript, the rule mandates strict mode, interfaces over types, and const objects over enums. It also sets up internationalization using Paraglide.js.

Because the prompt enforces Svelte 5 runes, it will break projects running Svelte 3 or 4.

What it helps with

  • Implement reactive logic using Svelte 5 runes
  • Structure full-stack routes and SSR pages in SvelteKit
  • Integrate Shadcn UI elements and Tailwind CSS helpers
  • Set up multilingual routing and translations with Paraglide.js

Example prompts for the agent

  • Generate a state machine in counter.svelte.ts using the $state rune
  • Create an auth-form.svelte component styled with Shadcn and Tailwind CSS
  • Add server-side data fetching with SvelteKit load functions and error handling

How to install web-app-optimization-cursorrules-prompt-file

Manually: put the files in place

.cursor/rules/web-app-optimization-cursorrules-prompt-file.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about web-app-optimization-cursorrules-prompt-file

How to install web-app-optimization-cursorrules-prompt-file in Cursor?

Place the rule content into .cursor/rules/web-app-optimization-cursorrules-prompt-file.mdc in your project root.

What does this rule do?

It enforces Svelte 5 runes, SvelteKit folder conventions, strict TypeScript habits, and minimal client-side JavaScript.

Is this rule compatible with older Svelte versions?

No. It targets Svelte 5 reactivity like $state and $derived, so it will produce invalid code for Svelte 3 or Svelte 4 projects.

Source text

web-app-optimization-cursorrules-prompt-file.mdc · CC0-1.0
---
description: "Cursor rules for web app development with optimization integration."
globs: **/*
alwaysApply: false
---
You are an expert in Svelte 5, SvelteKit, TypeScript, and modern web development.

Key Principles

- Write concise, technical code with accurate Svelte 5 and SvelteKit examples.
- Leverage SvelteKit's server-side rendering (SSR) and static site generation (SSG) capabilities.
- Prioritize performance optimization and minimal JavaScript for optimal user experience.
- Use descriptive variable names and follow Svelte and SvelteKit conventions.
- Organize files using SvelteKit's file-based routing system.

Code Style and Structure

- Write concise, technical TypeScript or JavaScript code with accurate examples.
- Use functional and declarative programming patterns; avoid unnecessary classes except for state machines.
- Prefer iteration and modularization over code duplication.
- Structure files: component logic, markup, styles, helpers, types.
- Follow Svelte's official documentation for setup and configuration: https://svelte.dev/docs

Naming Conventions

- Use lowercase with hyphens for component files (e.g., `components/auth-form.svelte`).
- Use PascalCase for component names in imports and usage.
- Use camelCase for variables, functions, and props.

TypeScript Usage

- Use TypeScript for all code; prefer interfaces over types.
- Avoid enums; use const objects instead.
- Use functional components with TypeScript interfaces for props.
- Enable strict mode in TypeScript for better type safety.

Svelte Runes

- `$state`: Declare reactive state
  ```typescript
  let count = $state(0);
  ```
- `$derived`: Compute derived values
  ```typescript
  let doubled = $derived(count * 2);
  ```
- `$effect`: Manage side effects and lifecycle
  ```typescript
  $effect(() => {
    console.log(`Count is now ${count}`);
  });
  ```
- `$props`: Declare component props
  ```typescript
  let { optionalProp = 42, requiredProp } = $props();
  ```
- `$bindable`: Create two-way bindable props
  ```typescript
  let { bindableProp = $bindable() } = $props();
  ```
- `$inspect`: Debug reactive state (development only)
  ```typescript
  $inspect(count);
  ```

UI and Styling

- Use Tailwind CSS for utility-first styling approach.
- Leverage Shadcn components for pre-built, customizable UI elements.
- Import Shadcn components from `$lib/components/ui`.
- Organize Tailwind classes using the `cn()` utility from `$lib/utils`.
- Use Svelte's built-in transition and animation features.

Shadcn Color Conventions

- Use `background` and `foreground` convention for colors.
- Define CSS variables without color space function:
  ```css
  --primary: 222.2 47.4% 11.2%;
  --primary-foreground: 210 40% 98%;
  ```
- Usage example:
  ```svelte

SvelteKit Project Structure

- Use the recommended SvelteKit project structure:
  ```
  - src/
    - lib/
    - routes/
    - app.html
    - static/
    - svelte.config.js
    - vite.config.js
  ```

Component Development

- Create .svelte files for Svelte components.
- Use .svelte.ts files for component logic and state machines.
- Implement proper component composition and reusability.
- Use Svelte's props for data passing.
- Leverage Svelte's reactive declarations for local state management.

State Management

- Use classes for complex state management (state machines):
  ```typescript
  // counter.svelte.ts
  class Counter {
    count = $state(0);
    incrementor = $state(1);
    increment() {
      this.count += this.incrementor;
    }
    resetCount() {
      this.count = 0;
    }
    resetIncrementor() {
      this.incrementor = 1;
    }
  }
  export const counter = new Counter();
  ```
- Use in components:
  ```svelte
  <br />
  import { counter } from './counter.svelte.ts';
  <br />
  <button on:click={() => counter.increment()}>
    Count: {counter.count}
  ```

Routing and Pages

- Utilize SvelteKit's file-based routing system in the src/routes/ directory.
- Implement dynamic routes using [slug] syntax.
- Use load functions for server-side data fetching and pre-rendering.
- Implement proper error handling with +error.svelte pages.

Server-Side Rendering (SSR) and Static Site Generation (SSG)

- Leverage SvelteKit's SSR capabilities for dynamic content.
- Implement SSG for static pages using prerender option.
- Use the adapter-auto for automatic deployment configuration.

Performance Optimization

- Leverage Svelte's compile-time optimizations.
- Use `{#key}` blocks to force re-rendering of components when needed.
- Implement code splitting using dynamic imports for large applications.
- Profile and monitor performance using browser developer tools.
- Use `$effect.tracking()` to optimize effect dependencies.
- Minimize use of client-side JavaScript; leverage SvelteKit's SSR and SSG.
- Implement proper lazy loading for images and other assets.

Data Fetching and API Routes

- Use load functions for server-side data fetching.
- Implement proper error handling for data fetching operations.
- Create API routes in the src/routes/api/ directory.
- Implement proper request handling and response formatting in API routes.
- Use SvelteKit's hooks for global API middleware.

SEO and Meta Tags

- Use Svelte:head component for adding meta information.
- Implement canonical URLs for proper SEO.
- Create reusable SEO components for consistent meta tag management.

Forms and Actions

- Utilize SvelteKit's form actions for server-side form handling.
- Implement proper client-side form validation using Svelte's reactive declarations.
- Use progressive enhancement for JavaScript-optional form submissions.

Internationalization (i18n) with Paraglide.js

- Use Paraglide.js for internationalization: https://inlang.com/m/gerre34r/library-inlang-paraglideJs
- Install Paraglide.js: `npm install @inlang/paraglide-js`
- Set up language files in the `languages` directory.
- Use the `t` function to translate strings:
  ```svelte
  <br />
  import { t } from '@inlang/paraglide-js';
  <br />
  - Support multiple languages and RTL layouts.
  - Ensure text scaling and font adjustments for accessibility.

Accessibility

- Ensure proper semantic HTML structure in Svelte components.
- Implement ARIA attributes where necessary.
- Ensure keyboard navigation support for interactive elements.
- Use Svelte's bind:this for managing focus programmatically.

Key Conventions

1. Embrace Svelte's simplicity and avoid over-engineering solutions.
2. Use SvelteKit for full-stack applications with SSR and API routes.
3. Prioritize Web Vitals (LCP, FID, CLS) for performance optimization.
4. Use environment variables for configuration management.
5. Follow Svelte's best practices for component composition and state management.
6. Ensure cross-browser compatibility by testing on multiple platforms.
7. Keep your Svelte and SvelteKit versions up to date.

Documentation

- Svelte 5 Runes: https://svelte-5-preview.vercel.app/docs/runes
- Svelte Documentation: https://svelte.dev/docs
- SvelteKit Documentation: https://kit.svelte.dev/docs
- Paraglide.js Documentation: https://inlang.com/m/gerre34r/library-inlang-paraglideJs/usage

Refer to Svelte, SvelteKit, and Paraglide.js documentation for detailed information on components, internationalization, and best practices.

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set234

The whole set →
xray-test-case-cursorrules-prompt-file A Cursor rule that turns feature descriptions and automated tests into structured Xray test cases for Jira. Useful when QA writes manual scenarios by hand. ★ 41,024repo stars wordpress-php-guzzle-gutenberg-cursorrules-prompt- Configures Cursor for WordPress plugins built with Guzzle, custom REST endpoints, and Gutenberg blocks. Enforces type hinting and WordPress standards. ★ 41,024repo stars wordpress-claude-stack This Cursor rule guides WordPress theme, plugin, and block work. It suits projects that use PHP alongside WooCommerce or ACF. ★ 41,024repo stars webassembly-z80-cellular-automata-cursorrules-prom A Cursor rule that walks the agent through adding a region grid to a Z80 cellular automata simulation built on WebAssembly. ★ 41,024repo stars vue3-composition-api-cursorrules-prompt-file This rule guides Cursor on Vue 3 Composition API practices, component setup, and project layout. Use it when you want those conventions reflected in code edits. ★ 41,024repo stars vue A Cursor rule that tells the agent how to write Vue: Composition API, Pinia, typing and routing. Useful when the project already has .vue and .ts files. ★ 41,024repo stars vue-pinia-cursorrules-prompt-file Guides Cursor to write clean Vue 3 and TypeScript state management using Pinia setup stores, proper reactivity, SSR safeguards, and tests. ★ 41,024repo stars vue-claude-stack This rule guides code generation for Vue 3 and Nuxt 3, covering Composition API, TypeScript, and Pinia. Use it to give an agent consistent project conventions. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor