| title | Creating Cursor Rules | ||||
|---|---|---|---|---|---|
| tags |
|
||||
| icon | lucide/mouse-pointer-2 |
Step-by-step guide for creating new Cursor rules for the Tux project.
- Choose Domain - Select appropriate domain directory
- Copy Template - Use
.cursor/templates/rule-template.mdc - Fill Content - Add project-specific patterns
- Validate - Ensure file meets standards
- Test - Verify rule applies correctly
Select the domain that best fits your rule:
core/- Core project rules (tech stack, dependencies)database/- Database patterns (models, migrations, controllers)modules/- Discord bot modules (cogs, commands, events)testing/- Testing patterns (pytest, fixtures, markers)docs/- Documentation rules (Zensical, writing standards)security/- Security patterns (secrets, validation)error-handling/- Error handling (logging, Sentry)ui/- UI components (Discord Components V2)meta/- System documentation (specifications)
- Navigate to appropriate domain directory
- Create new
.mdcfile with kebab-case name - Example:
database/models.mdc
Copy and customize frontmatter:
---
description: Brief description (60-120 chars) with domain keywords
globs: src/tux/database/**/*.py # Optional, comma-separated for file-scoped
alwaysApply: false # true for always-apply rules
---Metadata Guidelines:
- description: Include domain keywords, be specific
- globs: Use comma-separated file patterns for file-scoped rules (no quotes, no brackets)
- alwaysApply: Only true for project-wide standards
Follow this structure:
- Title (H1) - Clear, descriptive
- Overview - Purpose and scope
- Patterns - ✅ GOOD / ❌ BAD examples
- Best Practices - Key guidelines
- Anti-Patterns - What to avoid
- Examples - Detailed examples (optional)
- See Also - Cross-references
Include working code examples:
# ✅ GOOD: Show correct pattern
from tux.database.models import BaseModel
class MyModel(BaseModel, table=True):
"""Model description."""
id: int = Field(primary_key=True)# ❌ BAD: Show anti-pattern
class MyModel: # Missing BaseModel
id: int # Missing Field definitionLink to related rules:
## See Also
- @database/migrations.mdc - Migration patterns
- @database/controllers.mdc - Controller patterns
- @AGENTS.md - General coding standardsCheck:
- File under 500 lines
- Includes code examples
- Includes anti-patterns
- Has proper metadata
- Cross-references complete
- Project-specific (not generic)
-
Domain:
database/ -
File:
database/models.mdc -
Metadata:
description: SQLModel database model patterns for Tux globs: src/tux/database/models/**/*.py alwaysApply: false
-
Content: Add patterns, examples, anti-patterns
-
Cross-references: Link to migrations, controllers rules
---
description: Patterns for specific file type
globs: src/tux/modules/**/*.py
alwaysApply: false
------
description: Project-wide standard
alwaysApply: true
------
description: Domain-specific patterns with keywords
alwaysApply: false
---- Be Specific - Tailor to Tux project, not generic
- Include Examples - Show working code
- Show Anti-Patterns - What NOT to do
- Cross-Reference - Link to related rules
- Keep Focused - One domain/concern per rule
- Stay Current - Update when patterns change
---
description: Brief description (60-120 chars) with domain keywords
globs: optional/file/pattern, another/pattern
alwaysApply: false
---
# Rule Title
## Overview
Brief description of the rule's purpose and scope.
## Patterns
✅ **GOOD:** Example of correct pattern
```python
# Code example❌ BAD: Example of anti-pattern
# Code example- Practice 1
- Practice 2
- ❌ Anti-pattern 1
- ❌ Anti-pattern 2
- @related-rule.mdc
- @AGENTS.md
- Rules: kebab-case, descriptive (e.g.,
database-models.mdc) - Location:
.cursor/rules/{domain}/ - Format:
.mdcfiles with YAML frontmatter
- Project-specific: Tailored to Tux, not generic
- Examples: Include working code examples
- Anti-patterns: Show what NOT to do
- Cross-references: Link to related rules/commands
- Clear, actionable content
- Consistent formatting
- File under 500 lines
- Proper metadata format
Run validation before committing:
uv run ai validate-rulesThis checks:
- Frontmatter format
- Description length (60-120 chars)
- Content requirements (examples, anti-patterns)
- Globs format (comma-separated, no quotes/brackets)
- File structure
- Keep content current with code changes
- Update examples when patterns change
- Add new anti-patterns as discovered
- Update cross-references when structure changes
- Review rules during code reviews
- Update when project patterns change
- Remove obsolete rules
- Consolidate duplicate content
- Rule Template
- Creating Cursor Commands - Guide for creating commands
- @meta/cursor-rules.mdc - Rules specification