How to Set Up Windsurf Rules for Your Project (Complete Guide)
Windsurf has revolutionized how developers interact with AI coding assistants, but its power lies in proper configuration. A well-structured Windsurf rules file transforms this AI tool from a generic code generator into a specialized teammate that understands your project's architecture, coding standards, and business requirements.
This comprehensive guide will walk you through everything you need to know about setting up Windsurf rules that deliver consistent, high-quality results tailored to your specific development workflow.
What Are Windsurf Rules?
Windsurf rules are configuration files that define how the AI assistant should behave within your project. Think of them as detailed instructions that tell Windsurf about your codebase, preferred patterns, architectural decisions, and coding standards.
Unlike generic AI assistants that provide one-size-fits-all solutions, Windsurf with properly configured rules becomes context-aware. It understands your project structure, respects your established patterns, and generates code that feels like it was written by someone already familiar with your codebase.
Key Benefits of Properly Configured Windsurf Rules
- Consistency: All generated code follows your established patterns and conventions
- Context Awareness: Windsurf understands your project structure and dependencies
- Quality Assurance: Built-in constraints prevent common mistakes and anti-patterns
- Productivity: Less time reviewing and refactoring AI-generated code
- Team Alignment: Shared rules ensure consistent output across team members
Understanding the Windsurf Rules File Structure
Windsurf rules are typically stored in a .windsurfrules file in your project root. The file uses a structured format that covers different aspects of your development workflow:
# Project Context
project_name: "E-commerce Platform"
project_type: "react-typescript-app"
framework_version: "React 18 with TypeScript 5"
# Architecture Guidelines
architecture_pattern: "feature-based"
state_management: "zustand"
styling_approach: "tailwind-css"
# Code Standards
naming_conventions:
- "camelCase for variables and functions"
- "PascalCase for components and interfaces"
- "kebab-case for file names"
# Quality Requirements
test_requirements:
- "Include unit tests for all utility functions"
- "Include integration tests for API calls"
- "Mock external dependencies in tests"
# Constraints
avoid_patterns:
- "Class components (use functional components only)"
- "Any dependencies from React 16 era"
- "Inline styles (use Tailwind classes)"
Essential Windsurf Rules Components
1. Project Context Definition
Start by clearly defining what your project is and its technical foundation. This helps Windsurf understand the environment it's working within.
# Project Context
project_name: "TaskFlow - Project Management SaaS"
project_type: "full-stack-web-application"
tech_stack:
frontend: "React 18 + TypeScript + Vite"
backend: "Node.js + Express + PostgreSQL"
styling: "Tailwind CSS + Headless UI"
state: "Zustand for client state, React Query for server state"
testing: "Vitest + React Testing Library"
deployment: "Vercel (frontend) + Railway (backend)"
# Business Context
domain: "B2B project management and team collaboration"
target_users: "development teams and project managers"
key_features: ["task tracking", "team collaboration", "time tracking", "reporting"]
2. Architecture and Design Patterns
Define the architectural patterns and design principles your project follows. This ensures Windsurf generates code that fits seamlessly into your existing structure.
# Architecture Guidelines
folder_structure: |
src/
components/ # Reusable UI components
ui/ # Basic UI elements (Button, Input, etc.)
forms/ # Form-specific components
layout/ # Layout components (Header, Sidebar, etc.)
features/ # Feature-based modules
auth/ # Authentication feature
projects/ # Projects feature
tasks/ # Tasks feature
hooks/ # Custom React hooks
services/ # API services and external integrations
utils/ # Utility functions
types/ # TypeScript type definitions
component_patterns:
- "Use composition over inheritance"
- "Prefer compound components for complex UI"
- "Co-locate related files (component + test + styles)"
- "Use custom hooks for complex state logic"
api_patterns:
- "Use React Query for all server state"
- "Implement optimistic updates for user actions"
- "Include loading and error states for all async operations"
3. Code Style and Conventions
Establish clear coding standards that Windsurf should follow when generating code.
# Code Standards
naming_conventions:
variables: "camelCase (userId, taskList)"
functions: "camelCase with verb prefix (getUserById, createTask)"
components: "PascalCase (TaskCard, UserProfile)"
files: "kebab-case for components, camelCase for utilities"
constants: "SCREAMING_SNAKE_CASE (API_ENDPOINTS, MAX_RETRY_COUNT)"
interfaces: "PascalCase with 'I' prefix (IUser, ITask)"
types: "PascalCase (UserRole, TaskStatus)"
function_patterns:
- "Use arrow functions for React components"
- "Use function declarations for utility functions"
- "Always include return type annotations for functions"
- "Use async/await over Promise chains"
import_organization:
- "React and React-related imports first"
- "Third-party library imports second"
- "Local imports last"
- "Group related imports together"
- "Use named imports over default imports when possible"
4. Framework-Specific Guidelines
Include specific guidelines for the frameworks and libraries your project uses.
# React-Specific Guidelines
component_structure: |
1. Imports (React, libraries, local)
2. Type definitions (Props interface)
3. Component definition with TypeScript
4. Default export
hooks_usage:
- "Use useState for simple component state"
- "Use useReducer for complex state with multiple actions"
- "Use useCallback for expensive functions passed as props"
- "Use useMemo for expensive calculations"
- "Create custom hooks for reusable stateful logic"
typescript_patterns:
- "Use interfaces for object shapes"
- "Use union types for enums and status values"
- "Use generics for reusable components and functions"
- "Prefer strict type checking over 'any'"
- "Use utility types (Pick, Omit, Partial) appropriately"
5. Testing Requirements
Define testing expectations so Windsurf can generate appropriate tests alongside code.
# Testing Guidelines
test_coverage_expectations:
- "All utility functions must have unit tests"
- "All custom hooks must have tests"
- "All API functions must have integration tests"
- "Complex components should have render tests"
test_patterns:
- "Use describe blocks to group related tests"
- "Use descriptive test names that explain the scenario"
- "Test both happy path and error scenarios"
- "Mock external dependencies and APIs"
- "Use screen queries for DOM testing"
test_file_naming:
- "Component tests: ComponentName.test.tsx"
- "Hook tests: useHookName.test.ts"
- "Utility tests: utilityName.test.ts"
Framework-Specific Windsurf Rules Examples
React + TypeScript Project Rules
# React TypeScript Windsurf Rules
project_context:
name: "React TypeScript SPA"
framework: "React 18 + TypeScript 5"
build_tool: "Vite"
styling: "Tailwind CSS"
component_guidelines:
- "Use functional components with TypeScript"
- "Define Props interface for every component"
- "Use React.FC only when component has children"
- "Implement proper error boundaries for feature modules"
state_management:
local_state: "useState for simple state, useReducer for complex"
global_state: "Zustand with TypeScript"
server_state: "React Query with proper TypeScript generics"
code_organization:
- "Group exports at the bottom of files"
- "Use index.ts files for clean imports"
- "Keep components under 200 lines"
- "Extract complex logic into custom hooks"
performance_guidelines:
- "Use React.memo for expensive components"
- "Implement lazy loading for route components"
- "Use useCallback for event handlers in optimized components"
- "Use useMemo for expensive calculations"
error_handling:
- "Implement error boundaries at feature level"
- "Use React Query's error handling for API calls"
- "Provide user-friendly error messages"
- "Log errors to monitoring service"
Vue.js Project Rules
# Vue 3 Composition API Windsurf Rules
project_context:
name: "Vue 3 Application"
framework: "Vue 3 + TypeScript"
build_tool: "Vite"
styling: "Tailwind CSS"
component_guidelines:
- "Use Composition API with
Related