Windsurf rules for AI that actually work

Simple, practical, and composable Windsurf project rules to help you build better apps without wasting valuable context tokens.
Suggest a new rule

Search

Sort by

Filter by type
Backend
Frontend
Fullstack
Mobile
Database
Integration
Filter by language
CSS
Dart
JavaScript
PHP
Python
Ruby
Swift
TypeScript

Options

Show snippets

Snippets are specialized rules that extend or work with a parent rule.

They focus on specific use cases, provide practical examples, and can be adapted for your projects.

Try our new Rules Builder
Build your own custom Windsurf rules starter kit by selecting compatible backend and frontend frameworks.
nextjs.md
                                                    # Next.js rules

- Use the App Router structure with `page.tsx` files in route directories.
- Client components must be explicitly marked with `'use client'` at the top of the file.
- Use kebab-case for directory names (e.g., `components/auth-form`) and PascalCase for component files.
- Prefer named...
                                                

This rule explains Next.js conventions and best practices for fullstack development.

Next.js
react.md
                                                    # React rules

- Use functional components with hooks instead of class components
- Use custom hooks for reusable logic
- Use the Context API for state management when needed
- Use proper prop validation with PropTypes
- Use React.memo for performance optimization when necessary
- Use fragments to a...
                                                

This rule explains React component patterns, hooks usage, and best practices.

React
tailwind.md
                                                    # Tailwind CSS rules

- Use responsive prefixes for mobile-first design:

```html
<div class="w-full md:w-1/2 lg:w-1/3">
  <!-- Full width on mobile, half on medium, one-third on large screens -->
</div>
```

- Use state variants for interactive elements:

```html
<button class="bg-blue-500 hover:bg...
                                                

This rule explains Tailwind CSS conventions, utility classes, and best practices for modern UI development.

Tailwind CSS
2 rules
laravel.md
                                                    # Laravel rules

- Use `php artisan make:{option}` to create models, migrations, controllers, etc.
- `app\Console\Kernel.php` does not exist in Laravel 11+. If the file is not present, use the the [app.php](mdc:bootstrap/app.php) file for related configurations.
- In Laravel 11+ commands created in...
                                                

This rule explains Laravel conventions and best practices for backend development.

Laravel
3 rules
expressjs.md
                                                    # Express.js rules

- Use proper middleware order: body parsers, custom middleware, routes, error handlers
- Organize routes using Express Router for modular code structure
- Use async/await with proper error handling and try/catch blocks
- Create a centralized error handler middleware as the last m...
                                                

This rule explains Express.js conventions and best practices for Node.js backend development.

Express.js
ruby-on-rails.md
                                                    # Ruby on Rails rules

- Use Rails generators to create models, controllers, and migrations.
- Follow Rails naming conventions (singular for models, plural for controllers).
- Use ActiveRecord methods instead of raw SQL queries when possible.
- Avoid N+1 queries by using eager loading with `includes...
                                                

This rule explains Ruby on Rails conventions and best practices for backend development.

Ruby on Rails
3 rules
fastapi.md
                                                    # FastAPI rules

- Use type hints for all function parameters and return values
- Use Pydantic models for request and response validation
- Use appropriate HTTP methods with path operation decorators (@app.get, @app.post, etc.)
- Use dependency injection for shared logic like database connections an...
                                                

This rule explains FastAPI conventions and best practices for high-performance Python APIs.

FastAPI
swiftui.md
                                                    # SwiftUI rules

- Use structs for views and keep them small and focused
- Use @State for simple view-local state
- Use @ObservableObject with @Published for shared state
- Use @Binding to pass mutable state to child views
- Create custom ViewModifiers for reusable styling
- Use environment objects...
                                                

This rule explains SwiftUI patterns and best practices for iOS, macOS, watchOS, and tvOS development.

SwiftUI
react-native.md
                                                    # React Native rules

- Use functional components with hooks
- Follow a consistent folder structure (components, screens, navigation, services, hooks, utils)
- Use React Navigation for screen navigation
- Use StyleSheet for styling instead of inline styles
- Use FlatList for rendering lists instead...
                                                

This rule explains React Native component patterns and mobile-specific considerations.

React Native
postgresql.md
                                                    # PostgresSQL rules

## General

- Use lowercase for SQL reserved words to maintain consistency and readability.
- Employ consistent, descriptive identifiers for tables, columns, and other database objects.
- Use white space and indentation to enhance the readability of your code.
- Store dates in I...
                                                

This rule explains PostgreSQL database design patterns and advanced features usage.

PostgreSQL
5 rules
django.md
                                                    # Django rules

- Use `python manage.py startapp` to create new apps within your project
- Keep models in `models.py` and register them in `admin.py` for admin interface
- Use Django's ORM instead of raw SQL queries
- Avoid N+1 queries with `select_related` and `prefetch_related`:

```python
# Good...
                                                

This rule explains Django conventions and best practices for backend development.

Django
2 rules
flutter.md
                                                    # Flutter rules

- Use StatelessWidget for UI components without internal state.
- Use StatefulWidget for components that need to maintain state:

```dart
class Counter extends StatefulWidget {
  @override
  _CounterState createState() => _CounterState();
}

class _CounterState extends State<Counter...
                                                

This rule explains Flutter widget patterns and best practices for cross-platform mobile development.

Flutter
vuejs.md
                                                    # Vue.js rules

- Use the Composition API with `<script setup>` for better type inference and organization
- Define props with type definitions and defaults
- Use emits for component events
- Use v-model for two-way binding
- Use computed properties for derived state
- Use watchers for side effects...
                                                

This rule explains Vue.js component patterns, composition API usage, and best practices.

Vue.js
flask.md
                                                    # Flask rules

- Use Blueprints to organize routes by feature or resource
- Use Flask-SQLAlchemy for database models and ORM
- Use application factories for flexible application initialization
- Use Flask extensions for common functionality (Flask-Login, Flask-WTF, etc.)
- Store configuration in env...
                                                

This rule explains Flask conventions and best practices for lightweight Python web applications.

Flask
mysql.md
                                                    # MySQL rules

- Use appropriate data types to optimize storage and performance (e.g., INT for IDs, VARCHAR with appropriate length)
- Create indexes for columns used in WHERE, JOIN, and ORDER BY clauses
- Use foreign keys to maintain referential integrity
- Use EXPLAIN to analyze and optimize queri...
                                                

This rule explains MySQL database design patterns and query optimization techniques.

MySQL
sveltekit.md
                                                    # SvelteKit rules

## File Structure
- Follow the file-based routing structure with `+page.svelte` for pages and `+layout.svelte` for layouts
- Use `+page.server.js` for server-only code including data loading and form actions
- Use `+server.js` files for API endpoints
- Place reusable components in...
                                                

This rule explains SvelteKit conventions and best practices for fullstack development.

SvelteKit
jinja.md
                                                    # Jinja rules

- Use template inheritance:

```html
{# base.html #}
<!DOCTYPE html>
<html>
<head>
  <title>{% block title %}Default Title{% endblock %}</title>
</head>
<body>
  {% block content %}{% endblock %}
</body>
</html>
```

- Use include for components:

```html
{% include "components/user_c...
                                                

This rule explains Jinja template syntax and best practices for Python web applications.

Jinja
sqlite.md
                                                    # SQLite rules

- Use appropriate data types for columns (INTEGER, TEXT, REAL, BLOB, NULL)
- Create indexes for frequently queried columns
- Enable foreign key support with `PRAGMA foreign_keys = ON`
- Use transactions for multiple operations
- Use prepared statements to prevent SQL injection
- Use...
                                                

This rule explains SQLite database design patterns and performance considerations.

SQLite
memory.md
                                                    # AI Memory Rule

This rule defines how the AI should manage and utilize its "memory" regarding this specific project, including user preferences, learned facts, and project-specific conventions.

## Purpose

The AI's memory helps maintain consistency and adapt to specific project needs or user pref...
                                                

This rule defines how the AI agent should manage and utilize memory improve coding consistency.

Memory
task-lists.md
                                                    # Task List Management

Guidelines for creating and managing task lists in Markdown files to track project progress

## Task List Creation

1. Create task lists in a markdown file (in the project root):
   - Use `TASKS.md` or a descriptive name relevant to the feature (e.g., `ASSISTANT_CHAT.md`)...
                                                

This rule explains how to create and manage task lists to track project progress.

Task List
rule-analytics.md
                                                    # Cursor Rules Analytics

Each time you use a Cursor rule, update the analytics tracking file.

File location:
```
PROJECT_ROOT/.cursor/analytics.md
```

## Format

The analytics file contains a count of how many times each rule has been used:

```
rule-name.mdc: 5
another-rule.mdc: 2
```

Add new r...
                                                

This rule explains how to create and update an analytics.md file to track how often .mdc rules is being used.

Cursor Rules Analytics
vitest-testing.md
                                                    # Testing Guidelines

## Testing Framework
- `vitest` is used for testing
- Tests are colocated next to the tested file
  - Example: `dir/format.ts` and `dir/format.test.ts`

## Common Mocks

### Server-Only Mock
```ts
vi.mock("server-only", () => ({}));
```

### Prisma Mock
```ts
import { beforeEac...
                                                

This rule explains the guidelines for writing Vitest tests for Next.js applications.

Vitest Testing
create-rules.md
                                                    # Cursor Rules Location

How to add new cursor rules to the project

1. Always place rule files in PROJECT_ROOT/.cursor/rules/:
    ```
    .cursor/rules/
    ├── your-rule-name.mdc
    ├── another-rule.mdc
    └── ...
    ```

2. Follow the naming convention:
    - Use kebab-case for filenames...
                                                

This rule explains how to create new .mdc project rule files for the Cursor agent.

Create Rules

Windsurf Rules provide a powerful way to give consistent, reusable instructions to Cascade's AI features. They help the AI understand your project's context, adhere to specific coding styles, and automate workflows, making it a more effective coding partner.

What are Windsurf Rules?

Windsurf Rules are essentially saved prompts or guidelines that are automatically included when Cascade's AI processes your requests. Think of them as a way to give the AI persistent memory and instructions tailored to your needs. By providing this context, rules ensure the AI's behavior is consistent and aligned with your project requirements or personal preferences. Rules can be defined at either the global level (applying across all workspaces) or at the workspace level.

Why use Windsurf Rules?

Employing Windsurf Rules in your workflow offers several benefits:

  • Encode Domain-Specific Knowledge: Teach the AI about the unique aspects of your codebase, its architecture, or specific libraries you use.
  • Standardize Styles: Ensure the AI generates code that follows your project's formatting and architectural patterns.
  • Improve Consistency: Reduce the need to repeat instructions by having them persistently available to the AI.
  • Save Time: Get more relevant and accurate AI suggestions faster by providing clear, upfront context.

Types of rules and storage

Windsurf supports different scopes for rules:

Global Rules

  • Storage: Defined in global_rules.md.
  • Scope: These rules are applied across all your workspaces.

Workspace Rules

  • Storage: Located in the .windsurf/rules directory within your workspace. These rules are typically tied to specific file patterns (globs) or natural language descriptions.
  • Scope: These rules are specific to the workspace they are defined in.

Important Note on Character Limits:

  • Individual rule files are limited to 6000 characters each. Content beyond this limit will be truncated.
  • The total combined characters for global and local rules must not exceed 12,000. If this limit is exceeded, global rules take priority, followed by workspace rules, with any excess truncated.

Activation modes

At the rule level, you can define how a rule should be activated for Cascade. There are 4 modes:

  • Manual: This rule can be manually activated by @mentioning it in Cascade's input box.
  • Always On: This rule will always be applied.
  • Model Decision: Based on a natural language description of the rule you define, the AI model decides whether to apply the rule.
  • Glob: Based on a glob pattern that you define (e.g., *.js, src/**/*.ts), this rule will be applied to all files that match the pattern.

Using Windsurf Rules effectively

To get started with Windsurf Rules:

  1. Creating Rules:
    • Click on the Customizations icon in the top right slider menu in Cascade.
    • Navigate to the Rules panel.
    • Click the + Global or + Workspace button to create new rules at the desired level.
  2. Example Templates: You can find example rule templates curated by the Windsurf team at https://windsurf.com/editor/directory to help you get started.

Best practices for writing rules

To help Cascade follow your rules effectively, follow these best practices:

  • Be Specific and Concise: Keep rules simple, concise, and specific. Rules that are too long or vague may confuse Cascade.
  • Avoid Generic Rules: There's no need to add generic rules (e.g., "write good code"), as these are already baked into Cascade's training data.
  • Use Clear Formatting: Format your rules using bullet points, numbered lists, and markdown. These are easier for Cascade to follow compared to a long paragraph. For example:
    # Coding Guidelines
    My project's programming language is python
    Use early returns when possible
    Always add documentation when creating new functions and classes
    
  • Group with XML Tags (Optional): XML tags can be an effective way to communicate and group similar rules together. For example:
    <coding_guidelines>
    My project's programming language is python
    Use early returns when possible
    Always add documentation when creating new functions and classes
    </coding_guidelines>
    

By thoughtfully crafting and utilizing Windsurf Rules, you can significantly enhance Cascade's AI capabilities and tailor its assistance to your specific development needs.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later