Cursor Rules Best Practices: Write .cursorrules to Make AI Truly Understand Your Project
Write a high-quality .cursorrules file from scratch to significantly improve AI code quality
Cursor Rules Best Practices: Write .cursorrules
Why is .cursorrules so important?
Without .cursorrules, Cursor is like a new colleague every time—unfamiliar with code style, libraries, and naming conventions.
With good .cursorrules, it becomes a veteran who understands the entire project background.
Measured results: After adding .cursorrules, the number of times AI-generated code needs modification dropped by 65%.
Where to place the file?
Place it in the project root directory, named .cursorrules (starts with a dot, hidden file).
You can also configure it globally in Cursor Settings → Rules for AI.
Basic structure of a Rules file (5 sections)
markdown
Project Overview
[1-3 sentences: what the project is, main features, target users]Tech Stack
[List all major dependencies with version numbers]Code Standards
[Naming conventions, file structure, comment requirements]Common Patterns
[Examples of code patterns used repeatedly in the project]Prohibitions
[Explicitly tell AI what not to do]
Complete Example: Next.js Project
markdown
Project Overview
AI Agent navigation website, helping developers discover and compare AI tools.Tech Stack
Next.js 16 (App Router, no Pages Router)
TypeScript 5.7 (strict mode)
Tailwind CSS v4
shadcn/ui (New York style)
TanStack Query v5
Supabase + Zod Code Standards
Components: functional, named exports (no export default)
Naming: components PascalCase, variables camelCase, constants SCREAMING_SNAKE
CSS: Tailwind only, use cn() to merge class names
Props interface naming: {ComponentName}Props
Server components preferred, add 'use client' only when interaction needed Common Patterns
API calls via /features/xxx/api/service.ts, no direct fetch
URL state with nuqs, global UI state with Zustand
Forms use useAppForm, not useState
Icons: import { Icons } from '@/components/icons' Prohibitions
No any types
No business logic in component files
Do not modify shadcn components under src/components/ui/
No CSS Modules
Other Tech Stack Rules Snippets
React + TypeScript
markdown
Functional components + Hooks, no class components
useEffect must have cleanup
List rendering keys use stable IDs, not index
Custom Hooks start with use
Python FastAPI
markdown
All route functions must have type annotations
Request/response use Pydantic BaseModel
Database operations in crud.py, routes only call crud
Errors use HTTPException, do not raise other exceptions
Vue 3
markdown
Composition API (setup), no Options API
ref for primitives, reactive for objects