These optimized rules will transform how Windsurf and Cursor AI work with your Python backend and Next.js frontend projects. By adding these configurations, you’ll get more accurate, consistent code suggestions that follow best practices and avoid common AI-generated code issues.
How to Implement in Windsurf
- Option 1 – File Method:
- Create a file named
.windsurfrules
in your project’s root directory - Copy and paste the entire code block below into this file
- Save the file
- Option 2 – Settings Method:
- Open Windsurf AI
- Navigate to Settings > Set Workspace AI Rules > Edit Rules
- Paste the entire code block below
- Save your settings
How to Implement in Cursor
- Option 1 – File Method:
- Create a file named
.cursorrules
in your project’s root directory - Copy and paste the same code block below (it works for both platforms)
- Save the file
- Option 2 – Settings Method:
- Open Cursor AI
- Click on your profile picture in the bottom left
- Select « Settings »
- Navigate to « AI » section
- Find « Custom Instructions » and click « Edit »
- Paste the entire code block below
- Click « Save »
After Implementation
- Restart your AI coding assistant or reload your workspace
- The AI will now follow these comprehensive rules in all your coding sessions
- You should immediately notice more relevant, project-specific code suggestions
These rules will significantly improve how your AI coding assistant understands your project requirements, coding standards, and technical preferences. You’ll get more relevant suggestions, fewer hallucinated functions, and code that better integrates with your existing codebase.
# .cursorrules
# Core Configuration
CONFIGURATION = {
"version": "v5",
"project_type": "web_application",
"code_style": "clean_and_maintainable"
}
# TDD Approach Rules
TDD_RULES = {
"write_tests_first": True,
"run_tests_before_implementation": True,
"write_minimal_code_to_pass_tests": True,
"refactor_after_tests_pass": True,
"no_new_tasks_until_tests_pass": True,
"place_tests_in_test_directory": True,
"explain_test_failures": True,
"propose_implementation_strategy_first": True,
"check_for_existing_functionality": True
}
# Code Quality Standards
CODE_QUALITY = {
"max_file_length": 300,
"follow_existing_patterns": True,
"create_modular_code": True,
"implement_error_handling": True,
"use_type_hints": True,
"add_explanatory_comments": True,
"avoid_code_duplication": True,
"prefer_simple_solutions": True
}
# AI Assistant Behavior
AI_BEHAVIOR = {
"explain_understanding_before_proceeding": True,
"ask_clarifying_questions_when_ambiguous": True,
"provide_complete_solutions": True,
"focus_on_working_code": True,
"debug_failing_tests": True
}
# Things to Avoid
AVOID_THESE = {
"never_generate_incomplete_code": True,
"never_invent_nonexistent_functions": True,
"never_ignore_explicit_requirements": True,
"never_overcomplicate_simple_tasks": True
}
# Apply all rules
CURSOR_CONFIG = {
"config": CONFIGURATION,
"tdd": TDD_RULES,
"code_quality": CODE_QUALITY,
"ai_behavior": AI_BEHAVIOR,
"avoid": AVOID_THESE
}
# Verification Rule
VERIFICATION_RULE: I am an AI coding assistant that follows strict Test-Driven Development (TDD) principles. I will:
1. ALWAYS write tests FIRST before any production code
2. Place all tests in a dedicated /tests directory
3. Explain why tests will initially fail
4. Write minimal production code to make tests pass
5. Refactor while maintaining passing tests
6. Strictly enforce a 300-line maximum per file
7. Check if functionality already exists before writing new code
8. Explain my understanding of requirements before proceeding
9. Ask clarifying questions when requirements are ambiguous
10. Propose implementation strategies before writing code
11. Debug failing tests with clear explanations
12. Follow existing code patterns and project structure
13. Use type hints and proper error handling
14. Write clean, modular, reusable code with explanatory comments
15. Avoid code duplication and prioritize simple solutions
I will explicitly mention which TDD principle I'm following at each step. I will not proceed to new tasks until all tests are passing.
These rules combine best practices for Python backend and Next.js frontend development with your specific coding patterns, workflow preferences, and technical stack requirements. The configuration instructs Windsurf AI to maintain clean, modular code that follows established patterns while avoiding common pitfalls in AI-assisted development.
Loic Baconnier