# Cursor Rules Generator — AI Coding Config Builder > Generate optimized .cursorrules files for any tech stack. Automate Cursor IDE configuration with project-specific AI coding instructions and best practices. ## Install Save in your project root: ## Quick Use Create a `.cursorrules` file in your project root: ``` You are an expert in TypeScript, Next.js 14, React, and Tailwind CSS. ## Code Style - Use functional components with TypeScript interfaces - Prefer named exports over default exports - Use Tailwind CSS for styling, avoid inline styles ## Conventions - File naming: kebab-case for files, PascalCase for components - Use server components by default, add "use client" only when needed - Handle errors with try/catch and return appropriate error responses ## Project Structure - /app - Next.js app router pages - /components - Reusable UI components - /lib - Utility functions and API clients - /types - TypeScript type definitions ``` ## What are Cursor Rules? Cursor Rules (`.cursorrules` or `.cursor/rules`) are configuration files that tell the Cursor AI coding assistant how to behave in your project. They define coding conventions, tech stack preferences, file structure, and best practices. Well-crafted rules dramatically improve AI code generation quality by giving Cursor project-specific context. **Answer-Ready**: Cursor Rules are project config files that customize AI code generation in Cursor IDE. Define tech stack, conventions, and patterns. Reduces AI hallucination and improves code consistency. Essential for team standardization. Community-maintained rule collections available. **Best for**: Developers using Cursor IDE for AI-assisted coding. **Works with**: Cursor IDE, any programming language or framework. **Setup time**: Under 5 minutes. ## Rule Categories ### 1. Tech Stack Rules ``` You are an expert in Python, FastAPI, SQLAlchemy, and Pydantic. - Use Pydantic v2 model_validator instead of v1 validator - Use async def for all route handlers - Use SQLAlchemy 2.0 style queries with select() ``` ### 2. Architecture Rules ``` ## Architecture - Follow clean architecture: controllers -> services -> repositories - Never import from controllers in services - All database access goes through repository layer - Use dependency injection for services ``` ### 3. Testing Rules ``` ## Testing - Write tests for all new functions - Use pytest with fixtures, not unittest - Mock external services, never hit real APIs in tests - Name test files: test_.py ``` ### 4. Security Rules ``` ## Security - Never hardcode API keys or secrets - Always validate and sanitize user input - Use parameterized queries, never string interpolation for SQL - Set CORS origins explicitly, never use wildcard in production ``` ## Popular Rule Templates | Stack | Key Rules | |-------|-----------| | Next.js + TypeScript | Server components default, app router, Tailwind | | Python + FastAPI | Async handlers, Pydantic v2, SQLAlchemy 2.0 | | React Native + Expo | Expo Router, NativeWind, typed navigation | | Go + Gin | Error handling patterns, middleware conventions | | Rust + Axum | Ownership patterns, error types, async runtime | ## Best Practices 1. **Be specific**: "Use `date-fns` for dates" beats "use a date library" 2. **Show examples**: Include code snippets for complex patterns 3. **Set boundaries**: Tell Cursor what NOT to do 4. **Keep updated**: Rules should evolve with your codebase 5. **Team alignment**: Share rules via version control ## FAQ **Q: Where do I put the file?** A: Project root as `.cursorrules` or in `.cursor/rules` directory for multiple rule files. **Q: Do rules work with Claude Code too?** A: Claude Code uses `CLAUDE.md` files instead, but the concept is identical — project-specific AI instructions in a config file. **Q: How long should rules be?** A: 200-500 lines is the sweet spot. Too short lacks context, too long dilutes important rules. ## Source & Thanks > Community-maintained collections: > > [PatrickJS/awesome-cursorrules](https://github.com/PatrickJS/awesome-cursorrules) — 16k+ stars > [cursor.directory](https://cursor.directory) — Searchable rule database ## 快速使用 在项目根目录创建 `.cursorrules` 文件,定义技术栈和编码规范。 ## 什么是 Cursor Rules? Cursor Rules 是 Cursor IDE 的项目配置文件,告诉 AI 如何在你的项目中生成代码。定义技术栈、编码规范和最佳实践。 **一句话总结**:Cursor IDE 项目级 AI 配置,定义技术栈和编码规范,减少 AI 幻觉提升代码一致性,社区提供大量模板。 **适合人群**:使用 Cursor IDE 的开发者和团队。 ## 规则类型 ### 1. 技术栈规则 指定语言、框架和版本偏好。 ### 2. 架构规则 定义分层架构和依赖方向。 ### 3. 测试规则 测试框架、命名和覆盖率要求。 ## 常见问题 **Q: Claude Code 也有类似功能?** A: Claude Code 用 `CLAUDE.md`,概念相同。 **Q: 规则多长合适?** A: 200-500 行最佳。 ## 来源与致谢 > [PatrickJS/awesome-cursorrules](https://github.com/PatrickJS/awesome-cursorrules) — 16k+ stars --- Source: https://tokrepo.com/en/workflows/3b69856d-9cde-4c21-9b2e-094ebd2da7d9 Author: Skill Factory