rules_template

repository·main·Indexed 21 days ago

https://github.com/bhartendu-kumar/rules_template

A set of optimized instruction templates and directory structures for AI coding assistants including Cursor, CLINE, and RooCode. It implements Agile methodologies and token-efficient custom modes (Chat, Write, and MCP) to improve AI performance. The template provides a rule-based workflow consisting of requirements clarification, optimal planning, user validation, iterative implementation, and a persistent memory system using Core and Context files.

Tokens
9.8K
Snippets
21
Records
43
Agent score
77%

What's inside rules_template

  1. Manage project memory with Core and Context files

    main

    The memory files (located in clinerules/memory and cursor/rules/memory.mdc) create a persistent documentation system for the AI assistant and the project. This system is organized into Core Files (required) and Context Files (optional).

    Core Files (Required)

    • product_requirement_docs.md (docs/product_requirement_docs.md): The PRD or SOP. Defines project purpose, problems solved, core requirements, and goals. Acts as the source of truth for scope.
    • architecture.md (docs/architecture.md): System Architecture Document. Outlines design, component relationships, and dependencies.
    • technical.md (docs/technical.md): Technical Specifications. Details the dev environment, technologies, design patterns, and constraints.
    • tasks_plan.md (tasks/tasks_plan.md): Task Backlog. Tracks progress, current status, and known issues.
    • active_context.md (tasks/active_context.md): Current focus, active decisions, recent changes, and next steps.
    • error-documentation.mdc (.cursor/rules/error-documentation.mdc): Reusable fixes for known mistakes and resolutions.
    • lessons-learned.mdc (.cursor/rules/lessons-learned.mdc): A journal capturing patterns, preferences, and project intelligence.

    Context Files (Optional)

    • docs/literature/: Research directory. Can contain research papers (e.g., .tex files).
    • tasks/rfc/: Request for Comments (RFC) directory. Stores detailed specifications and discussions for specific functionalities.
  2. How the rule-based AI workflow works

    main

    The template operates on two pillars: Software Engineering Best Practices and Software Development Documentation. By using comprehensive documentation (PRDs, architecture plans, technical plans, and RFCs) as context, the AI assistant gains the necessary knowledge to follow structured workflows.

    The system relies on six crucial file types that shape AI behavior:

    1. rules: Houses generic rules and custom workflows.
    2. plan: Defines a chain of thinking workflow involving exhaustive searching, optimal planning, rigorous reasoning, and user validation.
    3. implement: Defines an implementation workflow based on separation of concerns, modular design, and incremental development. Testing is mandatory after significant implementations.
    4. debug: Defines rules for breaking out of loops or handling hard debugging, including web searching and reviewing previously solved errors.
    5. memory: Acts as the project's persistent context, containing PRDs, architecture plans, technical plans, and RFCs.
    6. directory-structure: A simple file defining the project layout to ensure modularity across code, tests, configs, and data.
  3. Follow the Plan/Implement/Debug workflow

    main

    The template uses rules files (located in clinerules/rules and cursor/rules/rules.mdc) to enforce a systematic five-phased workflow for any development task. This workflow ensures software engineering best practices are applied regardless of task granularity.

    The Five-Phased Workflow:

    1. Requirements and Clarifications: Start by making requirements precise and verbose. Ask as many clarifying questions as possible to anticipate bottlenecks and avoid redoing work later.
    2. Exhaustive Searching and Optimal Plan: Search all possible directions for a solution. Find the optimal approach (which may be an amalgamation of different methods) and reason rigorously about why it is the best choice.
    3. User Validation: Validate the proposed plan with the user. Clearly state all assumptions, design decisions, and the reasoning behind them.
    4. Implementation: Implement the plan iteratively. Take one functionality at a time, test it exhaustively across all cases, and then build the next piece to ensure a robust, incremental system.
    5. Further Suggestions: After implementation, suggest possible optimizations or additional features for security and functionality.
  4. Understand the project directory structure

    main

    The template uses a standardized directory structure to ensure all aspects of project development (code, tests, configuration, data, and rules) are handled modularly. This structure serves as the organizational foundation for both human developers and AI coding assistants.

    Key directories include:

    • .cursor/rules/: Custom rules for Cursor
    • .clinerules/: Custom rules for CLINE
    • docs/: Project documentation, architecture, and reference materials
    • tasks/: Task plans, active context, RFCs, and general to-do items
    • src/: Main source code
    • test/: Testing suite
    • utils/: Utility scripts or libraries
    • config/: Configuration files
    • data/: Data resources
    flowchart TD
        Root[Project Root]
        Root --> Docs[docs/]
        Root --> Tasks[tasks/]
        Root --> Cursor[.cursor/rules/]
        Root --> CLINE[.clinerules]    
        Root --> SourceCode[src/]
        Root --> Test[test/]
        Root --> Utils[utils/]
        Root --> Config[config/]
        Root --> Data[data/]
        Root --> Other[Other Directories]
  5. Organize projects using the modular directory structure

    main

    The directory-structure files (located in clinerules/directory-structure and cursor/rules/directory-structure.mdc) define a modular organization to ensure separation of concerns. This structure separates code, tests, configurations, data, and documentation.

    Recommended Directory Layout:

    • docs/: Documentation
    • tasks/: Task management and RFCs
    • .cursor/rules/: Cursor-specific rules
    • .clinerules: CLINE-specific rules
    • src/: Source code
    • test/: Tests
    • utils/: Utilities
    • config/: Configurations
    • data/: Data files
    flowchart TD
        Root[Project Root]
        Root --> Docs[docs/]
        Root --> Tasks[tasks/]
        Root --> Cursor[.cursor/rules/]
        Root --> CLINE[.clinerules]
        Root --> SourceCode[src/]
        Root --> Test[test/]
        Root --> Utils[utils/]
        Root --> Config[config/]
        Root --> Data[data/]
        Root --> Other[Other Directories]
  6. How Custom Modes work in this template

    main

    The template introduces three specialized modes designed to minimize token usage while maintaining high performance:

    1. Chat Mode: Acts like a traditional LLM (e.g., ChatGPT). It performs pure reasoning and conversation without the ability to read/write files or run commands. This is ideal for deep planning and conceptual discussion.
    2. Write Mode: A lean mode focused on execution. It provides the necessary tools for Read, Write, and Run Command operations.
    3. MCP Mode: A highly stripped-down system prompt specifically for executing Model Context Protocol (MCP) server tasks. It is intended to be used alongside other modes rather than as a standalone mode. It includes the switch_mode tool to allow transitioning back to other modes (like Chat) upon task completion.
  7. Advanced Setup: Create Custom Modes in RooCode

    main

    To save tokens and optimize performance in RooCode, create three custom modes. For each mode, go to Prompts (book icon), click + in the Modes section, and configure as follows:

    1. Chat Mode

    • Name: Chat
    • Slug: chat
    • Save Location: Global
    • Role Definition: Think Comprehensively in full depth.
    • Available Tools: NONE
    • Custom Instructions: Use the content from .roo/system-prompt-chat.

    2. Write Mode

    • Name: Write
    • Slug: write
    • Save Location: Global
    • Role Definition: Create and Edit files and directories. A dedicated mode for all Read/Write operations and running commands.
    • Available Tools: Read Files, Edit Files, Run Command
    • Custom Instructions: Use the content from .roo/system-prompt-write.

    3. MCP Mode

    • Name: MCP
    • Slug: mcp
    • Save Location: Global
    • Role Definition: Using MCP servers connected.
    • Available Tools: Use MCP
    • Custom Instructions: Use the content from .roo/system-prompt-mcp.
  8. Configure rules for Cursor, CLINE, or Windsurf

    main

    To use this template, place the specific rule files into the directory corresponding to your AI coding assistant. The template provides a uniform rule set across different platforms by using these specific file names.

    For Cursor

    Place files in .cursor/rules/ using the .mdc extension:

    • .cursor/rules/rules.mdc
    • .cursor/rules/plan.mdc
    • .cursor/rules/implement.mdc
    • .cursor/rules/debug.mdc
    • .cursor/rules/memory.mdc
    • .cursor/rules/directory-structure.mdc

    For CLINE

    Place files in .clinerules/:

    • .clinerules/rules
    • .clinerules/plan
    • .clinerules/implement
    • .clinerules/debug
    • .clinerules/memory
    • .clinerules/directory-structure

    For Windsurf

    Add the files directly into .windsurfrules.

    # Cursor setup example
    .cursor/rules/rules.mdc
    .cursor/rules/plan.mdc
    .cursor/rules/implement.mdc
    .cursor/rules/debug.mdc
    .cursor/rules/memory.mdc
    .cursor/rules/directory-structure.mdc
    
    # CLINE setup example
    .clinerules/rules
    .clinerules/plan
    .clinerules/implement
    .clinerules/debug
    .clinerules/memory
    .clinerules/directory-structure
  9. Advanced Setup: Create Custom Modes in Cursor

    main

    To optimize token usage in Cursor, add custom modes via the Modes section using the following configurations:

    1. Chat Mode

    • Name/Slug: Follow the UI prompts.
    • Advanced options (Custom Instructions):
    1. Ask for clarifications and in-depth follow-ups as much as possible.
    2. Break down the problem into key concepts and smaller sub-problems iteratively.
    3. Explore all directions possible.
    4. Very rigrous and deep Reasoning.
    5. Be very detailed and analytical.

    2. Write Mode

    • Advanced options (Custom Instructions):
    Create and Edit files and directories.

    3. MCP Mode

    • Advanced options (Custom Instructions):
    Run connected MCP servers. This is a dedicated mode for MCP and use other modes for read, write, run commands.
  10. Basic Setup for AI Coding Templates

    main

    To quickly set up this template for AI pair-coding, copy the following directories from the repository into your project root. You can stack these simultaneously to support multiple AI assistants:

    1. Cursor: Place the .cursor/rules/ directory in your project root.
    2. RooCode: Place the .roo/ directory in your project root.
    3. CLINE: Place the .clinerules/ directory in your project root.

    Important: Do NOT copy the .git file from this repository. The .cursor/rules/ directory contains the original files and should be preserved even if you are not using Cursor, as other tools use symbolic links to these files.

  11. Add a new mode to RooCode

    main

    To add a new operational mode to RooCode, follow these two steps:

    1. Update System Prompts: Locate the MODES section within the system prompt files in the .roo/ directory. Every file in this directory contains a MODES section where new modes should be defined.
    2. Configure Mode Switching: Update the Capabilities section of each system prompt. This section contains the mode-specific information required for the AI to recognize and switch between different modes.