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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
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.
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.
Employing Cursor Rules in your workflow offers several benefits:
Cursor supports different types of rules to cater to various needs:
These are the most common and powerful type of rules, designed for specific codebases.
.cursor/rules/
directory within your project and should be version-controlled (e.g., with Git). This means they are shared with your team..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.
@service-template.ts
) to include their content as part of the rule's context.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..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 are global to your Cursor installation and apply to all your projects.
Please always reply in a concise style.
Prefer arrow functions for JavaScript callbacks.
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.
To get the most out of Cursor Rules:
Creating Rules:
Cmd+Shift+P
or Ctrl+Shift+P
) and search for "New Cursor Rule"..mdc
files in your project's .cursor/rules/
directory./Generate Cursor Rules
command in chat.Applying Rules:
@
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
.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 Requested
rules, the AI might suggest using a rule if it's relevant to your current task.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.
To create effective Cursor Rules:
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..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.