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.
# .windsurfrules
# Copy and paste this entire file into your project root or
# Navigate to Settings > Set Workspace AI Rules > Edit Rules
# Core Configuration
CONFIGURATION = {
"version": "v5",
"project_type": "web_application",
"primary_language": "python",
"frontend_framework": "next.js",
"code_style": "clean_and_maintainable"
}
# Python Backend Best Practices
BACKEND_RULES = {
"frameworks": ["FastAPI", "Flask", "Django"],
"follow_pep8": True,
"use_type_hints": True,
"implement_error_handling": True,
"prefer_async_when_appropriate": True,
"create_modular_code": True,
"use_environment_variables": True,
"write_comprehensive_tests": True,
"use_uv_for_package_management": True,
"always_use_latest_library_versions": True,
"avoid_deprecated_libraries": True
}
# Next.js Frontend Practices
FRONTEND_RULES = {
"use_typescript": True,
"implement_react_hooks_properly": True,
"create_reusable_components": True,
"optimize_for_performance": True,
"follow_app_router_conventions": True,
"implement_responsive_design": True,
"use_tailwind_for_styling": True
}
# Coding Pattern Preferences
CODING_PATTERNS = {
"prefer_simple_solutions": True,
"avoid_code_duplication": True,
"consider_all_environments": ["dev", "test", "prod"],
"only_make_requested_changes": True,
"prioritize_existing_implementation": True,
"keep_codebase_clean": True,
"avoid_scripts_in_files": True,
"refactor_files_over_300_lines": True,
"mock_data_only_for_tests": True,
"no_fake_data_in_dev_or_prod": True,
"never_overwrite_env_without_confirmation": True,
"max_file_length": 300,
"database_type": "SQL",
"vector_search": "Qdrant",
"separate_databases_per_environment": True
}
# Coding Workflow Preferences
WORKFLOW_PREFERENCES = {
"focus_on_relevant_code": True,
"avoid_unrelated_changes": True,
"write_thorough_tests": True,
"avoid_unnecessary_architecture_changes": True,
"consider_code_impact": True,
"add_explanatory_comments": True,
"place_tests_in_test_directory": True
}
# Technical Stack
TECH_STACK = {
"backend": "Python",
"frontend": "Next.js",
"database": "SQL",
"vector_search": "Qdrant",
"testing_framework": "Python tests",
"package_manager": "uv",
"never_use_json_file_storage": True
}
# AI Assistant Behavior
AI_BEHAVIOR = {
"provide_complete_solutions": True,
"focus_on_working_code": True,
"follow_existing_patterns": True,
"suggest_best_practices": True,
"be_concise_unless_asked_for_details": True
}
# Things to Avoid
AVOID_THESE = {
"never_generate_incomplete_code": True,
"never_invent_nonexistent_functions": True,
"never_ignore_explicit_requirements": True,
"never_mix_framework_patterns": True,
"never_overcomplicate_simple_tasks": True
}
# Apply all rules
WINDSURF_CONFIG = {
"config": CONFIGURATION,
"backend": BACKEND_RULES,
"frontend": FRONTEND_RULES,
"coding_patterns": CODING_PATTERNS,
"workflow": WORKFLOW_PREFERENCES,
"tech_stack": TECH_STACK,
"ai_behavior": AI_BEHAVIOR,
"avoid": AVOID_THESE
}
VERIFICATION_RULE: Every time you choose to apply a rule from this file, explicitly state the rule in your output. You can abbreviate the rule description to a single word or phrase.
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