Skip to main content
rule

sveltekit-tailwindcss-typescript-cursorrules-promp — Cursor rule

Defines project conventions for SvelteKit 2, Tailwind CSS, and TypeScript in Cursor. It keeps code consistent by enforcing typed components and proper directory structure.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/sveltekit-tailwindcss-typescript-cursorrules-promp.mdc
Open on GitHub

What sveltekit-tailwindcss-typescript-cursorrules-promp does

This rule instructs Cursor to generate code suited for SvelteKit 2 and Svelte 4. The model relies on $: declarations for reactivity and standard writable stores accessed via $store. Markup styling is handled via Tailwind CSS utilities, favoring Svelte's class: directive over ternary expressions inside class strings.

File organization follows official framework recommendations. Components live inside src/lib/components/, while page routes use +page.svelte files under src/routes/. Server fetching relies on SvelteKit load functions, and state mutations use form actions.

It will conflict with Svelte 5 runes. The configuration targets Svelte 4, Node.js 18 or later, TypeScript 5.x, and Vite 5.x. Event functions require the handle prefix, and interactive elements must include aria-label and tabindex="0" attributes.

What it helps with

  • structure routes and layouts following SvelteKit conventions
  • apply Tailwind CSS utility classes without dedicated style tags
  • declare TypeScript interfaces for component props
  • add ARIA labels and keyboard listeners to interactive tags

Example prompts for the agent

  • Create an accessible button component in src/lib/components/Button.svelte with typed props and a handleClick function.
  • Set up a +page.svelte route under src/routes/dashboard that loads server data via a load function.
  • Define a writable store for user settings and display it using the reactive $ syntax.

How to install sveltekit-tailwindcss-typescript-cursorrules-promp

Manually: put the files in place

.cursor/rules/sveltekit-tailwindcss-typescript-cursorrules-promp.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 sveltekit-tailwindcss-typescript-cursorrules-promp

How to install sveltekit-tailwindcss-typescript-cursorrules-promp in Cursor?

Save the rule content into .cursor/rules/sveltekit-tailwindcss-typescript-cursorrules-promp.mdc in your project root.

What stack versions does this rule require?

The rule targets Node.js 18 or newer, SvelteKit 2.x with Svelte 4.x, TypeScript 5.x, Vite 5.x, and PNPM 8+.

How does the rule handle styling?

It enforces Tailwind CSS utility classes directly in the markup, recommending Svelte's class: directive for conditional states.

Source text

sveltekit-tailwindcss-typescript-cursorrules-promp.mdc · CC0-1.0
---
description: "Cursor rules for SvelteKit development with Tailwind CSS and TypeScript integration."
globs: **/*
alwaysApply: false
---
Modible Project Standards

Version Numbers

Node.js: 18.x or later
SvelteKit: 2.x (which uses Svelte 4.x)
TypeScript: 5.x
Vite: 5.x
PNPM: 8.x or later


Remember the following important mindset when providing code:

Simplicity
Readability
Performance
Maintainability
Testability
Reusability

Adhere to the following guidelines in your code:

Utilize early returns for code readability.
Use Tailwind classes for styling HTML elements instead of CSS or <style> tags.
Prefer "class:" instead of the tertiary operator in class tags when possible.
Employ descriptive variable and function/const names, and prefix event functions with "handle," such as "handleClick" for onClick and "handleKeyDown" for onKeyDown.
Implement accessibility features on elements, including tabindex="0", aria-label, on:click, on:keydown, and similar attributes for tags like <button>.
Use consts instead of functions, and define a type if possible.

Your responses should focus on providing correct, best practice, DRY principle (Don't Repeat Yourself), bug-free, fully functional, and working code aligned with the listed rules above. Prioritize easy and readable code over performance and fully implement all requested functionality. Ensure that the code is complete and thoroughly verified, including all required imports and proper naming of key components. Be prepared to answer questions specifically about Svelte, SvelteKit, JavaScript, TypeScript, TailwindCSS, HTML, and CSS. Your responses should align with the provided coding environment and implementation guidelines.

Preferred Syntax and Patterns

Svelte Components

Use .svelte extension for Svelte components
Use TypeScript syntax in <script> tags:
svelteCopy
<script lang="ts">
  // TypeScript code here
</script>

State Management

Use Svelte stores for global state:
typescriptCopy
import { writable } from 'svelte/store';
export const myStore = writable(initialValue);

Access store values in components with the $ prefix:
svelteCopy
<p>{$myStore}</p>

Reactivity

Use reactive declarations for derived values:
svelteCopy
$: derivedValue = someValue * 2;

Use reactive statements for side effects:
svelteCopy
$: { 
  console.log(someValue); 
  updateSomething(someValue);
}

Typing

Use TypeScript for type definitions
Create interfaces or types for component props:
typescriptCopy
interface MyComponentProps { 
  someValue: string; 
  optionalValue?: number;
}

Imports

Use aliased imports where applicable (as defined in svelte.config.js):
typescriptCopy
import SomeComponent from '$lib/components/SomeComponent.svelte';
import { someUtil } from '$lib/utils';

Async Operations

Prefer async/await syntax over .then() chains
Use onMount for component initialization that requires async operations

Styling

Use Tailwind CSS for styling
Utilize Tailwind's utility classes directly in the markup
For complex components, consider using Tailwind's @apply directive in a scoped <style> block
Use dynamic classes with template literals when necessary:
svelteCopy
<div class={`bg-blue-500 p-4 ${isActive ? 'opacity-100' : 'opacity-50'}`}></div>

File Structure

Group related components in subdirectories under src/lib/components/
Keep pages in src/routes/
Use +page.svelte for page components and +layout.svelte for layouts
Place reusable utility functions in src/lib/utils/
Store types and interfaces in src/lib/types/

Component Design

Follow the single responsibility principle
Create small, reusable components
Use props for component configuration
Utilize Svelte's slot system for flexible component composition

Data Fetching

Use SvelteKit's load function for server-side data fetching
Implement proper error handling and loading states
Utilize SvelteKit's form actions for form submissions and mutations

Performance Optimization

Lazy load components and modules when possible
Use Svelte's transition API for smooth UI animations
Implement proper caching strategies for API requests

Testing

Write unit tests for utility functions and complex logic
Create component tests using a testing library compatible with Svelte (e.g., Svelte Testing Library)
Implement end-to-end tests for critical user flows

Accessibility

Ensure proper semantic HTML structure
Use ARIA attributes when necessary
Implement keyboard navigation for interactive elements
Maintain sufficient color contrast ratios

Code Quality

Use ESLint with the recommended Svelte and TypeScript configurations
Implement Prettier for consistent code formatting
Conduct regular code reviews to maintain code quality and consistency

Documentation

Maintain up-to-date README files for the project and major components
Use JSDoc comments for functions and complex logic
Keep inline comments concise and meaningful

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

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set210

tailwind-shadcn-ui-integration-cursorrules-prompt- This Cursor rule guides Tailwind and shadcn/ui work, asking the assistant to outline a plan before writing readable TypeScript and Next.js code. ★ 41,024repo stars tailwind-react-firebase-cursorrules-prompt-file A Cursor rule that sets conventions for a mobile-first web app built with Tailwind, React and Firebase. ★ 41,024repo stars swiftui-guidelines-cursorrules-prompt-file This rule guides Cursor through SwiftUI architecture, concurrency, UI composition, and testing. Add it when you want those conventions reflected in code suggestions. ★ 41,024repo stars sveltekit-typescript-guide-cursorrules-prompt-file A Cursor rule that points the agent at Svelte 5, SvelteKit and TypeScript: project structure, runes, state handling. ★ 41,024repo stars sveltekit-restful-api-tailwind-css-cursorrules-pro This rule gives Cursor project guidance for SvelteKit, REST APIs, Tailwind CSS, testing, and file management. Use it to keep those practices in view while working on a project. ★ 41,024repo stars svelte A Cursor rule that steers the agent toward Svelte conventions: component structure, reactivity, stores, SvelteKit routing and tests. Useful when the agent writes or edits Svelte code. ★ 41,024repo stars svelte-5-vs-svelte-4-cursorrules-prompt-file Guides Cursor to write Svelte 5 code instead of Svelte 4, adopting runes like $state and $derived, native event attributes, and snippets. ★ 41,024repo stars solidjs-typescript-cursorrules-prompt-file This rule guides Cursor through Solid.js and TypeScript conventions, from typed reactive state to component props. Use it when you want those practices reflected in code suggestions. ★ 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