Skip to content

Vishal-ml-ds/ai-coding-rules

Repository files navigation

ai-coding-rules

Production-grade coding rules for AI-assisted development. Works with Claude Code, Cursor, Gemini Code Assist, and Cline.

License: MIT PRs Welcome


Why This Exists

AI coding assistants are powerful — but without rules, they write inconsistent, insecure, hard-to-maintain code. These rules are battle-tested standards that make any AI assistant write production-quality code from the first prompt.

6 rule sets. 4 AI tools. One git clone.


How It Works

graph LR
    A[ai-coding-rules] --> B[rules/]
    B --> C[Claude Code]
    B --> D[Cursor]
    B --> E[Gemini]
    B --> F[Cline]

    C --> G[.claude/rules/*.md]
    D --> H[.cursor/rules/*.mdc]
    E --> I[.gemini/rules/*.md]
    F --> J[.clinerules]

    style A fill:#6366f1,stroke:#4f46e5,color:#fff
    style C fill:#f97316,stroke:#ea580c,color:#fff
    style D fill:#06b6d4,stroke:#0891b2,color:#fff
    style E fill:#4285f4,stroke:#1a73e8,color:#fff
    style F fill:#10b981,stroke:#059669,color:#fff
Loading

Quick Start

Claude Code

# Copy rules to your global config (applies to ALL projects)
cp -r claude/rules/ ~/.claude/rules/

# Or copy to a specific project
cp -r claude/rules/ your-project/.claude/rules/

Cursor

# Copy rules to your project
cp -r cursor/rules/ your-project/.cursor/rules/

Gemini Code Assist

# Copy rules to your project
cp -r gemini/rules/ your-project/.gemini/rules/

Cline

# Copy the single rules file to your project root
cp cline/.clinerules your-project/.clinerules

What's Inside

ai-coding-rules/
├── rules/                    # Source rules (tool-agnostic)
│   ├── coding-style.md
│   ├── python-backend.md
│   ├── typescript-frontend.md
│   ├── security.md
│   ├── testing.md
│   └── context-management.md
│
├── claude/rules/             # Claude Code format
├── cursor/rules/             # Cursor format (.mdc)
├── gemini/rules/             # Gemini format
└── cline/.clinerules         # Cline format (single file)

The Rules

mindmap
  root((AI Coding<br/>Rules))
    Code Quality
      Functions max 50 lines
      Files max 800 lines
      No magic numbers
      Immutability first
      Descriptive naming
    Security
      No hardcoded secrets
      Parameterized queries
      Input validation
      XSS/CSRF protection
      Rate limiting
    Testing
      80% coverage
      TDD workflow
      AAA pattern
      Mock externals
      E2E with semantic selectors
    Python Backend
      FastAPI patterns
      Pydantic v2
      Async by default
      Structured logging
      Type hints everywhere
    TypeScript Frontend
      Strict mode
      Small components
      Tailwind CSS
      Zod validation
      Error boundaries
    Context Management
      Model selection
      Smart compaction
      Cost reduction
      State persistence
Loading

Rule Details

# Rule What It Enforces Applies To
1 Coding Style Function size, naming, immutability, error handling All languages
2 Python Backend FastAPI patterns, Pydantic, async, structured logging **/*.py
3 TypeScript Frontend React/Next.js, Tailwind, Zod, accessibility **/*.ts, **/*.tsx
4 Security Secrets, injection, XSS, CSRF, auth, rate limiting All files
5 Testing TDD, coverage, AAA pattern, mocking, E2E selectors All test files
6 Context Management Model selection, compaction strategy, cost reduction AI workflow

How Rules Load in Each Tool

graph TD
    subgraph Claude Code
        CC1[~/.claude/rules/] -->|Global| CC2[Always loaded]
        CC3[project/.claude/rules/] -->|Project| CC2
        CC4[CLAUDE.md] -->|Project root| CC2
    end

    subgraph Cursor
        CU1[.cursor/rules/*.mdc] -->|Frontmatter controls| CU2[Conditional loading]
        CU2 -->|alwaysApply: true| CU3[Every conversation]
        CU2 -->|globs: *.py| CU4[When matching files open]
    end

    subgraph Gemini
        GE1[.gemini/rules/*.md] -->|Project| GE2[Always loaded]
        GE3[GEMINI.md] -->|Project root| GE2
    end

    subgraph Cline
        CL1[.clinerules] -->|Project root| CL2[Always loaded]
    end

    style CC2 fill:#f97316,color:#fff
    style CU3 fill:#06b6d4,color:#fff
    style CU4 fill:#06b6d4,color:#fff
    style GE2 fill:#4285f4,color:#fff
    style CL2 fill:#10b981,color:#fff
Loading

Tool Format Comparison

Feature Claude Code Cursor Gemini Cline
Format .md .mdc (YAML frontmatter) .md Single .clinerules file
Location .claude/rules/ .cursor/rules/ .gemini/rules/ Project root
Global rules ~/.claude/rules/ No No No
File targeting paths: frontmatter globs: frontmatter No No
Multiple files Yes Yes Yes Single file
Project root file CLAUDE.md .cursorrules GEMINI.md .clinerules

Customizing

Pick only the rules you need

Don't want Python rules? Skip python-backend.md. Only doing frontend? Just copy coding-style.md, typescript-frontend.md, security.md, and testing.md.

Add your own rules

Create a new .md file in the format matching your tool. Follow the existing pattern:

# Rule Name

- Rule 1 — one line, clear, actionable.
- Rule 2 — no ambiguity.
- Rule 3 — the AI can follow this without asking.

For Cursor, wrap it in .mdc format:

---
description: What this rule enforces
alwaysApply: true
---

# Rule Name
...

Philosophy

graph TD
    A[Without Rules] -->|AI generates| B[Inconsistent code]
    B --> C[Security holes]
    B --> D[No tests]
    B --> E[Magic numbers]
    B --> F[God functions]

    G[With Rules] -->|AI generates| H[Production code]
    H --> I[Secure by default]
    H --> J[Tested & typed]
    H --> K[Clean architecture]
    H --> L[Maintainable]

    style A fill:#ef4444,color:#fff
    style G fill:#22c55e,color:#fff
    style B fill:#fca5a5,color:#000
    style H fill:#86efac,color:#000
Loading

Rules aren't restrictions — they're force multipliers. An AI assistant with good rules writes better code than most developers without them. These rules encode production engineering standards so that every AI-generated line meets the bar.


Contributing

See CONTRIBUTING.md for guidelines on adding new rules or improving existing ones.

Have a rule that makes your AI write better code? Open a PR.


Credits

  • Rules battle-tested across multiple production projects
  • Inspired by real-world engineering standards and OWASP guidelines

License

MIT — use these rules in any project, commercial or personal.

About

Production-grade coding rules for AI-assisted development. Works with Claude Code, Cursor, Gemini, and Cline.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors