Cursor rules for AI that actually work

Simple, practical, and composable Cursor 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 Cursor rules starter kit by selecting compatible backend and frontend frameworks.
nextjs.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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.mdc
                                                    # 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

Cursor Rules provide a powerful way to give consistent, reusable instructions to Cursor's AI features, like the Agent and Cmd-K. 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 Cursor Rules?

Cursor Rules are essentially saved prompts or guidelines that are automatically included when the 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 at the start of every interaction, rules ensure the AI's behavior is consistent and aligned with your project requirements or personal preferences.

Why use Cursor Rules?

Employing Cursor 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.
  • Automate Workflows: Define multi-step processes or templates that the AI can use for common tasks, like creating new components or writing tests.
  • 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

Cursor supports different types of rules to cater to various needs:

Project Rules

These are the most common and powerful type of rules, designed for specific codebases.

  • Storage: They live in the .cursor/rules/ directory within your project and should be version-controlled (e.g., with Git). This means they are shared with your team.
  • Format: Project Rules are written in MDC (.mdc), a Markdown-like format that supports YAML frontmatter for metadata (like a description or globs) and Markdown for the rule content itself.
    ---
    description: Ensures all new React components use functional syntax and TypeScript.
    globs:
      - "src/components/**/*.tsx"
    alwaysApply: false
    ---
    All React components should be functional components.
    Use TypeScript for props and state.
    
  • File Referencing: Rules can reference files within your project (e.g., @service-template.ts) to include their content as part of the rule's context.
  • Invocation Types:
    • Always: The rule is always included in the AI's context for every request within the project.
    • Auto Attached: The rule is automatically included if you are interacting with files that match the glob patterns defined in its metadata.
    • Agent Requested: The AI can choose to ask if it should apply this rule if it deems it relevant (the rule must have a description).
    • Manual: The rule is only applied if you explicitly invoke it by typing its name (e.g., @my-custom-rule) in the Chat or Cmd-K prompt.
  • Nested Rules: You can create .cursor/rules/ subdirectories deeper in your project structure (e.g., project/backend/.cursor/rules/) to organize rules that are specific to certain parts of your application.

User Rules

User rules are global to your Cursor installation and apply to all your projects.

  • Storage: Defined in Cursor Settings > Rules.
  • Format: Plain text only (no MDC or metadata).
  • Use Cases: Ideal for personal preferences like response language, tone, or general coding style hints you always want the AI to follow.
    Please always reply in a concise style.
    Prefer arrow functions for JavaScript callbacks.
    

.cursorrules (Legacy)

This is an older, deprecated way of defining rules in a single .cursorrules file at the project root. While still supported, it's recommended to migrate to the more flexible Project Rules (.cursor/rules/*.mdc) format.

Using Cursor Rules effectively

To get the most out of Cursor Rules:

  1. Creating Rules:

    • Use the Command Palette (Cmd+Shift+P or Ctrl+Shift+P) and search for "New Cursor Rule".
    • Manually create .mdc files in your project's .cursor/rules/ directory.
    • Ask the AI to generate a rule from a conversation: "Turn this conversation into a Cursor Rule" or use the /Generate Cursor Rules command in chat.
  2. Applying Rules:

    • Manual Invocation: For rules designed for on-demand use, type @ followed by the rule's filename (without the .mdc extension) in the AI chat or Cmd-K input. For example, if your rule is my-rule.mdc, type @my-rule.
    • Automatic Application: Rules with globs (for Auto Attached type) or alwaysApply: true (for Always type) will be applied automatically by Cursor when their conditions are met. You'll often see an indicator if rules are being applied.
    • Agent Interaction: For Agent Requested rules, the AI might suggest using a rule if it's relevant to your current task.
  3. Discovering Rules: You can usually see which rules are active or available in the context section of Cursor's AI interface.

The core idea is that rules provide the AI with crucial context before it generates a response, leading to more accurate, relevant, and helpful interactions.

Best practices for writing rules

To create effective Cursor Rules:

  • Be Specific and Concise: Rules should be focused on a particular task or guideline. Aim for clarity and keep them reasonably short (e.g., under a few hundred lines if possible).
  • Make Them Actionable: Provide clear instructions that the AI can follow.
  • Use Examples: If a rule involves a specific code structure or format, include a small, clear example within the rule content or by referencing a template file.
  • Iterate and Refine: Start with simple rules and build upon them. If a rule isn't working as expected, refine its wording or scope.
  • Organize with Descriptions: For Agent Requested or Manual rules, a good description in the MDC frontmatter helps you (and the AI) understand what it does and when to use it.
  • Compose Rules: Break down complex sets of instructions into smaller, reusable rules.
  • Version Control: Always commit your .cursor/rules/ directory to your repository to share them with your team and keep a history.

By thoughtfully crafting and utilizing Cursor Rules, you can significantly enhance the AI's 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