Skip to content

Latest commit

 

History

History
1150 lines (952 loc) · 31.4 KB

File metadata and controls

1150 lines (952 loc) · 31.4 KB

Real-World Examples

Overview

This guide provides practical, real-world examples of rulesync configurations for different types of projects and team structures. Each example includes complete configurations, setup instructions, and lessons learned.

Example 1: React TypeScript Startup

Project Context

  • Team Size: 3-5 developers
  • Tech Stack: React 18, TypeScript, Vite, Tailwind CSS
  • AI Tools: Cursor, Claude Code, GitHub Copilot
  • Focus: Rapid development with consistent quality

Configuration Structure

.rulesync/
├── overview.md              # Project overview and principles
├── react-standards.md       # React-specific guidelines
├── typescript-rules.md      # TypeScript coding standards
├── testing-guidelines.md    # Testing requirements
└── commands/
    ├── component.md         # Generate React components
    ├── test.md              # Generate test files
    └── deploy.md            # Deployment checklist

Root Rule (overview.md)

---
root: true
targets: ["*"]
description: "Modern React application development principles"
globs: ["src/**/*", "components/**/*"]
---

# SaaS Dashboard Application

A modern, responsive SaaS dashboard built with React 18 and TypeScript.

## Mission
Create a fast, accessible, and maintainable dashboard that scales with our business needs.

## Tech Stack
- **Frontend**: React 18 + TypeScript + Vite
- **Styling**: Tailwind CSS + Headless UI
- **State**: React Query + Zustand
- **Testing**: Vitest + Testing Library
- **Build**: Vite + SWC

## Core Principles
1. **Type Safety**: Strict TypeScript, no `any` types
2. **Performance**: Lazy loading, code splitting, optimized bundles
3. **Accessibility**: WCAG 2.1 AA compliance
4. **Testing**: >80% coverage, test-driven development
5. **User Experience**: Mobile-first, progressive enhancement

## Architecture Patterns
- **Atomic Design**: Components organized by complexity
- **Custom Hooks**: Reusable business logic
- **Error Boundaries**: Graceful error handling
- **Suspense**: Loading states with React 18 features

React Standards (react-standards.md)

---
targets: ["cursor", "claudecode", "copilot"]
description: "React component development standards"
globs: ["src/**/*.tsx", "src/**/*.jsx", "components/**/*"]
cursorRuleType: "specificFiles"
---

# React Component Standards

## Component Structure
```typescript
interface ButtonProps {
  children: ReactNode;
  variant?: 'primary' | 'secondary' | 'danger';
  size?: 'sm' | 'md' | 'lg';
  disabled?: boolean;
  loading?: boolean;
  onClick?: () => void;
}

const Button: FC<ButtonProps> = ({
  children,
  variant = 'primary',
  size = 'md',
  disabled = false,
  loading = false,
  onClick,
}) => {
  const baseClasses = 'font-medium rounded-md focus:outline-none focus:ring-2';
  const variantClasses = {
    primary: 'bg-blue-600 text-white hover:bg-blue-700',
    secondary: 'bg-gray-200 text-gray-900 hover:bg-gray-300',
    danger: 'bg-red-600 text-white hover:bg-red-700',
  };
  
  return (
    <button
      className={cn(baseClasses, variantClasses[variant], sizeClasses[size])}
      disabled={disabled || loading}
      onClick={onClick}
      type="button"
    >
      {loading ? <Spinner size="sm" /> : children}
    </button>
  );
};

export default Button;

Hooks Best Practices

// Custom hook for API data fetching
const useUserData = (userId: string) => {
  return useQuery({
    queryKey: ['user', userId],
    queryFn: () => fetchUser(userId),
    enabled: !!userId,
    staleTime: 5 * 60 * 1000, // 5 minutes
  });
};

// Custom hook for form state
const useContactForm = () => {
  const [state, setState] = useState<ContactFormState>({
    name: '',
    email: '',
    message: '',
  });

  const handleSubmit = async (data: ContactFormState) => {
    // Form submission logic
  };

  return { state, setState, handleSubmit };
};

File Organization

  • Components: One component per file, PascalCase naming
  • Hooks: One hook per file, camelCase with 'use' prefix
  • Types: Co-located with components or in shared types file
  • Utils: Pure functions in utils directory
  • Tests: Co-located with components (.test.tsx)

Performance Guidelines

  • Use React.memo() for expensive components
  • Implement useMemo() for expensive calculations
  • Use useCallback() for event handlers in optimized components
  • Lazy load routes and heavy components
  • Optimize images with proper sizing and formats

### Custom Component Command (commands/component.md)
```yaml
---
targets: ["claudecode", "geminicli"]
description: "Generate a new React component with TypeScript"
---

# Generate React Component

Create a new React component following our project standards.

## Component to create: $ARGUMENTS

Please generate:

1. **Main Component File** (`ComponentName.tsx`):
   ```typescript
   interface ComponentNameProps {
     // Define props based on component purpose
   }
   
   const ComponentName: FC<ComponentNameProps> = ({ /* props */ }) => {
     // Implementation
     return <div>{/* JSX */}</div>;
   };
   
   export default ComponentName;
  1. Test File (ComponentName.test.tsx):

    import { render, screen } from '@testing-library/react';
    import ComponentName from './ComponentName';
    
    describe('ComponentName', () => {
      it('renders correctly', () => {
        render(<ComponentName />);
        // Add meaningful tests
      });
    });
  2. Storybook Story (ComponentName.stories.tsx):

    import type { Meta, StoryObj } from '@storybook/react';
    import ComponentName from './ComponentName';
    
    const meta: Meta<typeof ComponentName> = {
      title: 'Components/ComponentName',
      component: ComponentName,
    };
    
    export default meta;
    export const Default: StoryObj<typeof ComponentName> = {};

Requirements:

  • Use TypeScript interfaces for props
  • Include accessibility attributes (ARIA labels, roles)
  • Follow Tailwind CSS patterns for styling
  • Include error states and loading states if applicable
  • Add JSDoc comments for complex props
  • Ensure responsive design (mobile-first)

### Results and Lessons Learned
**Metrics After 3 Months**:
- **Development Speed**: 40% faster component creation
- **Code Consistency**: 95% adherence to TypeScript standards
- **Bug Reduction**: 30% fewer prop-related bugs
- **Onboarding Time**: New developers productive in 2 days vs 1 week

**Key Lessons**:
- Component command saved significant time on boilerplate
- Specific glob patterns improved Cursor rule targeting
- Type-focused rules dramatically improved code quality
- Testing guidelines increased coverage from 45% to 85%

## Example 2: Enterprise Node.js API

### Project Context
- **Team Size**: 12-15 developers across 3 teams
- **Tech Stack**: Node.js, Express, PostgreSQL, Docker
- **AI Tools**: Claude Code, Cursor, Windsurf, GitHub Copilot
- **Focus**: Security, scalability, maintainability

### Configuration Structure

.rulesync/ ├── overview.md # Enterprise API overview ├── security-standards.md # Security requirements ├── api-design-patterns.md # REST API standards ├── database-guidelines.md # Database best practices ├── testing-requirements.md # Comprehensive testing standards ├── monitoring-logging.md # Observability requirements ├── deployment-procedures.md # DevOps and deployment └── commands/ ├── endpoint.md # Generate API endpoints ├── migration.md # Database migrations ├── test-suite.md # Generate test suites └── security-check.md # Security validation


### Security Standards (security-standards.md)
```yaml
---
targets: ["*"]
description: "Enterprise-grade security requirements"
globs: ["src/**/*", "routes/**/*", "middleware/**/*"]
---

# Security Standards

## Input Validation
```javascript
// Use Joi or Zod for all input validation
const createUserSchema = z.object({
  email: z.string().email().max(255),
  password: z.string().min(8).max(128),
  role: z.enum(['user', 'admin']).default('user'),
});

// Validate in middleware
const validateRequest = (schema) => (req, res, next) => {
  try {
    req.validatedData = schema.parse(req.body);
    next();
  } catch (error) {
    return res.status(400).json({ 
      error: 'Validation failed',
      details: error.errors 
    });
  }
};

Authentication & Authorization

// JWT token validation
const authenticateToken = async (req, res, next) => {
  const authHeader = req.headers['authorization'];
  const token = authHeader && authHeader.split(' ')[1];

  if (!token) {
    return res.status(401).json({ error: 'Access token required' });
  }

  try {
    const decoded = jwt.verify(token, process.env.JWT_SECRET);
    req.user = await User.findById(decoded.userId);
    next();
  } catch (error) {
    return res.status(403).json({ error: 'Invalid token' });
  }
};

// Role-based authorization
const requireRole = (roles) => (req, res, next) => {
  if (!req.user || !roles.includes(req.user.role)) {
    return res.status(403).json({ error: 'Insufficient permissions' });
  }
  next();
};

Database Security

  • Parameterized Queries: Always use parameterized queries or ORM
  • Connection Security: Use SSL/TLS for database connections
  • Credential Management: Store credentials in secure vault
  • Access Control: Implement least-privilege database access
  • Audit Logging: Log all data access and modifications

API Security Headers

// Security headers middleware
app.use((req, res, next) => {
  res.setHeader('X-Content-Type-Options', 'nosniff');
  res.setHeader('X-Frame-Options', 'DENY');
  res.setHeader('X-XSS-Protection', '1; mode=block');
  res.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
  res.setHeader('Content-Security-Policy', "default-src 'self'");
  next();
});

Rate Limiting

const rateLimit = require('express-rate-limit');

const limiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100, // limit each IP to 100 requests per windowMs
  message: 'Too many requests from this IP',
  standardHeaders: true,
  legacyHeaders: false,
});

app.use('/api/', limiter);

Error Handling

  • Never expose stack traces in production
  • Log errors securely without sensitive data
  • Use generic error messages for client responses
  • Implement proper error categorization
  • Monitor and alert on security-related errors

### API Endpoint Command (commands/endpoint.md)
```yaml
---
targets: ["claudecode"]
description: "Generate secure REST API endpoint"
---

# Generate API Endpoint

Create a new REST API endpoint following enterprise security standards.

## Endpoint specification: $ARGUMENTS

Please generate a complete endpoint implementation including:

1. **Route Handler** with proper HTTP methods
2. **Input Validation** using Zod schema
3. **Authentication/Authorization** middleware
4. **Error Handling** with appropriate responses
5. **Database Operations** with proper error handling
6. **Unit Tests** with security test cases
7. **Integration Tests** for complete flow
8. **API Documentation** with OpenAPI spec

## Security Requirements:
- Input validation for all parameters
- Authentication required for protected endpoints
- Role-based authorization where applicable
- Rate limiting configuration
- Audit logging for sensitive operations
- Proper error handling without information disclosure

## Response Format:
All responses must follow our standard format:
```json
{
  "success": true,
  "data": { /* response data */ },
  "timestamp": "2024-01-01T00:00:00Z",
  "requestId": "uuid"
}

Error responses:

{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Validation failed",
    "details": []
  },
  "timestamp": "2024-01-01T00:00:00Z",
  "requestId": "uuid"
}

Please ensure the endpoint follows our security standards and includes comprehensive testing.


### Results and Lessons Learned
**Metrics After 6 Months**:
- **Security Incidents**: Reduced by 80% through consistent validation
- **Code Review Time**: 50% reduction due to automated standards
- **API Consistency**: 98% adherence to response format standards
- **Test Coverage**: Maintained >90% across all services

**Key Lessons**:
- Security-focused rules prevented common vulnerabilities
- Endpoint generation command ensured consistent API patterns
- Enterprise rules required more maintenance but provided significant value
- Multi-team adoption required extensive documentation and training

## Example 3: Open Source Python Library

### Project Context
- **Team Size**: 5-8 contributors (distributed)
- **Tech Stack**: Python, FastAPI, SQLAlchemy, pytest
- **AI Tools**: Claude Code, Cursor, Roo Code
- **Focus**: Code quality, documentation, contributor experience

### Configuration Structure

.rulesync/ ├── overview.md # Library purpose and principles ├── python-standards.md # Python coding standards ├── documentation-rules.md # Documentation requirements ├── testing-standards.md # Testing and quality requirements ├── contribution-guide.md # Contributor guidelines └── commands/ ├── feature.md # Implement new features ├── docs.md # Generate documentation └── release.md # Release checklist


### Python Standards (python-standards.md)
```yaml
---
targets: ["claudecode", "cursor", "roo"]
description: "Python development standards for open source library"
globs: ["src/**/*.py", "tests/**/*.py", "examples/**/*.py"]
---

# Python Development Standards

## Code Style and Formatting
```python
# Use Black for formatting (line length: 88)
# Use isort for import sorting
# Use flake8 for linting with these settings:
# max-line-length = 88
# extend-ignore = E203, W503

from typing import Dict, List, Optional, Union
import asyncio
import logging

from fastapi import FastAPI, HTTPException
from sqlalchemy.orm import Session

from .models import User, UserCreate
from .database import get_db

Type Hints and Documentation

from typing import Dict, List, Optional, Union, Any
from dataclasses import dataclass

@dataclass
class UserResponse:
    """Response model for user operations.
    
    Attributes:
        id: Unique user identifier
        email: User's email address
        created_at: Account creation timestamp
        is_active: Whether the user account is active
    """
    id: int
    email: str
    created_at: str
    is_active: bool = True

def create_user(
    db: Session,
    user_data: UserCreate,
    *,
    send_welcome_email: bool = True
) -> UserResponse:
    """Create a new user account.
    
    Args:
        db: Database session
        user_data: User creation data
        send_welcome_email: Whether to send welcome email
        
    Returns:
        Created user response object
        
    Raises:
        HTTPException: If user creation fails
        ValueError: If email format is invalid
        
    Example:
        >>> user_data = UserCreate(email="test@example.com")
        >>> user = create_user(db, user_data)
        >>> print(user.email)
        test@example.com
    """
    # Implementation here
    pass

Error Handling

import logging
from typing import Optional

logger = logging.getLogger(__name__)

class LibraryError(Exception):
    """Base exception for library-specific errors."""
    pass

class ValidationError(LibraryError):
    """Raised when input validation fails."""
    pass

class DatabaseError(LibraryError):
    """Raised when database operations fail."""
    pass

def safe_operation(data: Dict[str, Any]) -> Optional[Dict[str, Any]]:
    """Perform operation with proper error handling.
    
    Args:
        data: Input data for operation
        
    Returns:
        Operation result or None if failed
        
    Raises:
        ValidationError: If input data is invalid
        DatabaseError: If database operation fails
    """
    try:
        # Validate input
        if not isinstance(data, dict) or not data:
            raise ValidationError("Data must be a non-empty dictionary")
            
        # Perform operation
        result = perform_database_operation(data)
        logger.info(f"Operation completed successfully for {len(data)} items")
        return result
        
    except DatabaseError:
        logger.error("Database operation failed", exc_info=True)
        raise
    except Exception as e:
        logger.error(f"Unexpected error in operation: {e}", exc_info=True)
        raise LibraryError(f"Operation failed: {e}") from e

Testing Requirements

import pytest
from unittest.mock import Mock, patch
from fastapi.testclient import TestClient

from mylib import create_user, UserCreate
from mylib.exceptions import ValidationError

class TestUserOperations:
    """Test suite for user operations."""
    
    def test_create_user_success(self, db_session):
        """Test successful user creation."""
        # Arrange
        user_data = UserCreate(email="test@example.com")
        
        # Act
        result = create_user(db_session, user_data)
        
        # Assert
        assert result.email == "test@example.com"
        assert result.is_active is True
        assert isinstance(result.id, int)
    
    def test_create_user_invalid_email(self, db_session):
        """Test user creation with invalid email."""
        # Arrange
        user_data = UserCreate(email="invalid-email")
        
        # Act & Assert
        with pytest.raises(ValidationError, match="Invalid email format"):
            create_user(db_session, user_data)
    
    @patch('mylib.users.send_email')
    def test_create_user_email_failure(self, mock_send_email, db_session):
        """Test user creation when email sending fails."""
        # Arrange
        mock_send_email.side_effect = Exception("Email service down")
        user_data = UserCreate(email="test@example.com")
        
        # Act
        result = create_user(db_session, user_data, send_welcome_email=True)
        
        # Assert - user should be created even if email fails
        assert result.email == "test@example.com"
        mock_send_email.assert_called_once()

Performance Considerations

  • Use __slots__ for classes with many instances
  • Implement __hash__ and __eq__ for comparable objects
  • Use generators for large data processing
  • Profile code with cProfile for optimization
  • Use async/await for I/O bound operations
  • Implement proper connection pooling for databases

### Documentation Command (commands/docs.md)
```yaml
---
targets: ["claudecode", "cursor"]
description: "Generate comprehensive documentation"
---

# Generate Documentation

Create comprehensive documentation for: $ARGUMENTS

Please generate documentation following our standards:

## 1. API Documentation
```python
def function_name(
    param1: Type1,
    param2: Type2,
    *,
    optional_param: Optional[Type3] = None
) -> ReturnType:
    """Brief description of function purpose.
    
    Longer description explaining the function's behavior,
    use cases, and any important considerations.
    
    Args:
        param1: Description of first parameter
        param2: Description of second parameter
        optional_param: Description of optional parameter
        
    Returns:
        Description of return value and its structure
        
    Raises:
        SpecificError: When this specific error occurs
        AnotherError: When this other error occurs
        
    Example:
        >>> result = function_name("value1", "value2")
        >>> print(result)
        Expected output
        
    Note:
        Any important notes or warnings about usage
        
    See Also:
        related_function: Description of relationship
    """

2. README Section

## Function/Class Name

Brief description of the component.

### Usage

```python
from mylib import ComponentName

# Basic usage example
component = ComponentName(param="value")
result = component.method()
print(result)

Parameters

  • param1 (Type): Description of parameter
  • param2 (Optional[Type], default=None): Description of optional parameter

Returns

Description of return value and type.

Examples

# Example 1: Basic usage
result = function_name("simple", "example")

# Example 2: Advanced usage
result = function_name(
    "complex",
    "example",
    optional_param="custom_value"
)

## 3. Test Documentation
```python
class TestComponentName:
    """Test suite for ComponentName.
    
    This test suite covers all public methods of ComponentName,
    including edge cases and error conditions.
    """
    
    def test_method_name_success_case(self):
        """Test method_name with valid inputs."""
        # Test implementation
        
    def test_method_name_edge_case(self):
        """Test method_name with edge case inputs."""
        # Test implementation
        
    def test_method_name_error_handling(self):
        """Test method_name error handling."""
        # Test implementation

Requirements:

  • Include type hints for all parameters and return values
  • Provide realistic examples that users can run
  • Document all exceptions that can be raised
  • Include performance considerations if relevant
  • Add cross-references to related functionality
  • Follow Google-style docstring format
  • Include both simple and advanced usage examples

### Results and Lessons Learned
**Metrics After 8 Months**:
- **Code Quality**: Maintainability index increased 40%
- **Documentation Coverage**: 95% of public API documented
- **Contributor Onboarding**: New contributors productive in 1-2 days
- **Bug Reports**: 60% reduction in usage-related issues

**Key Lessons**:
- Comprehensive docstring standards improved library adoption
- Testing rules ensured consistent quality across contributors
- Documentation generation command saved hours per feature
- Clear contribution guidelines attracted more contributors

## Example 4: Microservices Architecture

### Project Context
- **Team Size**: 20+ developers across 5 microservices
- **Tech Stack**: Go, gRPC, PostgreSQL, Kubernetes
- **AI Tools**: Claude Code, Windsurf, Cursor
- **Focus**: Consistency, observability, inter-service communication

### Multi-Service Configuration Strategy
Each service has its own rulesync configuration with shared standards:

```bash
# Shared configuration repository structure
shared-standards/
├── .rulesync/
│   ├── microservices-overview.md
│   ├── grpc-standards.md
│   ├── observability-rules.md
│   └── security-standards.md
└── scripts/
    └── sync-to-services.sh

# Individual services import shared standards
user-service/
├── .rulesync/
│   ├── service-specific-rules.md
│   └── imported/              # Shared standards
│       ├── microservices-overview.md
│       ├── grpc-standards.md
│       └── observability-rules.md
└── rulesync.jsonc

Shared gRPC Standards (grpc-standards.md)

---
targets: ["*"]
description: "gRPC service development standards across microservices"
globs: ["**/*.proto", "**/*.go", "internal/**/*"]
---

# gRPC Service Standards

## Protocol Buffer Definitions
```protobuf
syntax = "proto3";

package user.v1;

option go_package = "github.com/company/user-service/gen/user/v1;userv1";

import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";
import "validate/validate.proto";

service UserService {
  // Get user by ID
  rpc GetUser(GetUserRequest) returns (GetUserResponse) {
    option (google.api.http) = {
      get: "/v1/users/{user_id}"
    };
  }
  
  // Create new user
  rpc CreateUser(CreateUserRequest) returns (CreateUserResponse) {
    option (google.api.http) = {
      post: "/v1/users"
      body: "*"
    };
  }
}

message User {
  string id = 1 [(validate.rules).string.uuid = true];
  string email = 2 [(validate.rules).string.email = true];
  string name = 3 [(validate.rules).string.min_len = 1];
  google.protobuf.Timestamp created_at = 4;
  google.protobuf.Timestamp updated_at = 5;
}

message GetUserRequest {
  string user_id = 1 [(validate.rules).string.uuid = true];
}

message GetUserResponse {
  User user = 1;
}

Go Service Implementation

package main

import (
    "context"
    "fmt"
    "log"
    "net"
    
    "google.golang.org/grpc"
    "google.golang.org/grpc/codes"
    "google.golang.org/grpc/status"
    "go.opentelemetry.io/otel"
    "go.opentelemetry.io/otel/trace"
    
    userv1 "github.com/company/user-service/gen/user/v1"
)

type UserServiceServer struct {
    userv1.UnimplementedUserServiceServer
    userRepo UserRepository
    tracer   trace.Tracer
}

func NewUserServiceServer(userRepo UserRepository) *UserServiceServer {
    return &UserServiceServer{
        userRepo: userRepo,
        tracer:   otel.Tracer("user-service"),
    }
}

func (s *UserServiceServer) GetUser(
    ctx context.Context,
    req *userv1.GetUserRequest,
) (*userv1.GetUserResponse, error) {
    // Start tracing span
    ctx, span := s.tracer.Start(ctx, "GetUser")
    defer span.End()
    
    // Validate request
    if err := req.Validate(); err != nil {
        return nil, status.Error(codes.InvalidArgument, err.Error())
    }
    
    // Add user ID to span attributes
    span.SetAttributes(attribute.String("user.id", req.UserId))
    
    // Fetch user from repository
    user, err := s.userRepo.GetByID(ctx, req.UserId)
    if err != nil {
        if errors.Is(err, ErrUserNotFound) {
            return nil, status.Error(codes.NotFound, "user not found")
        }
        // Log error and return internal error
        log.Printf("failed to get user: %v", err)
        return nil, status.Error(codes.Internal, "failed to get user")
    }
    
    // Convert to proto message
    protoUser := &userv1.User{
        Id:        user.ID,
        Email:     user.Email,
        Name:      user.Name,
        CreatedAt: timestamppb.New(user.CreatedAt),
        UpdatedAt: timestamppb.New(user.UpdatedAt),
    }
    
    return &userv1.GetUserResponse{User: protoUser}, nil
}

Error Handling Standards

import (
    "google.golang.org/grpc/codes"
    "google.golang.org/grpc/status"
)

// Standard error mapping
func mapError(err error) error {
    switch {
    case errors.Is(err, ErrNotFound):
        return status.Error(codes.NotFound, "resource not found")
    case errors.Is(err, ErrInvalidInput):
        return status.Error(codes.InvalidArgument, err.Error())
    case errors.Is(err, ErrUnauthorized):
        return status.Error(codes.Unauthenticated, "authentication required")
    case errors.Is(err, ErrForbidden):
        return status.Error(codes.PermissionDenied, "insufficient permissions")
    default:
        // Log internal errors, return generic message
        log.Printf("internal error: %v", err)
        return status.Error(codes.Internal, "internal server error")
    }
}

// Custom error types
var (
    ErrNotFound     = errors.New("not found")
    ErrInvalidInput = errors.New("invalid input")
    ErrUnauthorized = errors.New("unauthorized")
    ErrForbidden    = errors.New("forbidden")
)

Inter-Service Communication

// Service client with retry and circuit breaker
type PaymentServiceClient struct {
    client     paymentv1.PaymentServiceClient
    retryMax   int
    timeoutDur time.Duration
}

func (c *PaymentServiceClient) CreatePayment(
    ctx context.Context,
    req *paymentv1.CreatePaymentRequest,
) (*paymentv1.CreatePaymentResponse, error) {
    ctx, cancel := context.WithTimeout(ctx, c.timeoutDur)
    defer cancel()
    
    var resp *paymentv1.CreatePaymentResponse
    var err error
    
    for i := 0; i < c.retryMax; i++ {
        resp, err = c.client.CreatePayment(ctx, req)
        if err == nil {
            return resp, nil
        }
        
        // Check if error is retryable
        if st, ok := status.FromError(err); ok {
            switch st.Code() {
            case codes.Unavailable, codes.DeadlineExceeded:
                // Retryable errors - wait and retry
                time.Sleep(time.Duration(i+1) * 100 * time.Millisecond)
                continue
            default:
                // Non-retryable error
                return nil, err
            }
        }
    }
    
    return nil, fmt.Errorf("max retries exceeded: %w", err)
}

### Configuration Sync Script
```bash
#!/bin/bash
# scripts/sync-standards.sh

SHARED_REPO="https://github.com/company/shared-standards.git"
SERVICES=(
    "user-service"
    "payment-service"
    "notification-service"
    "order-service"
    "inventory-service"
)

echo "=== Syncing Shared Standards ==="

# Clone or update shared standards
if [ ! -d "shared-standards" ]; then
    git clone $SHARED_REPO shared-standards
else
    cd shared-standards && git pull && cd ..
fi

# Sync to each service
for service in "${SERVICES[@]}"; do
    echo "Syncing standards to $service..."
    
    if [ -d "$service" ]; then
        # Create imported directory
        mkdir -p "$service/.rulesync/imported"
        
        # Copy shared standards
        cp shared-standards/.rulesync/*.md "$service/.rulesync/imported/"
        
        # Generate configurations
        cd "$service"
        npx rulesync generate
        cd ..
        
        echo "✅ $service updated"
    else
        echo "⚠️  $service directory not found"
    fi
done

echo "=== Sync Complete ==="

Results and Lessons Learned

Metrics After 12 Months:

  • Inter-Service Consistency: 95% adherence to gRPC standards
  • Development Velocity: 30% faster service creation
  • Bug Reduction: 50% fewer integration issues
  • Onboarding Time: New developers productive across services in 3 days

Key Lessons:

  • Shared standards repository crucial for consistency
  • Automated sync process prevented configuration drift
  • Service-specific rules complemented shared standards well
  • Observability rules dramatically improved debugging experience

Common Patterns and Best Practices

Configuration File Patterns

// Small team configuration
{
  "targets": ["cursor", "claudecode"],
  "delete": true,
  "verbose": false
}

// Enterprise configuration
{
  "targets": ["*"],
  "exclude": [],
  "baseDir": ["./services/api", "./services/web"],
  "outputPaths": {
    "copilot": ".github/custom-instructions.md"
  },
  "verbose": true
}

// Open source configuration
{
  "targets": ["claudecode", "cursor", "roo"],
  "aiRulesDir": ".rulesync",
  "aiCommandsDir": ".rulesync/commands",
  "delete": false
}

Command Organization Patterns

# Simple project
.rulesync/commands/
├── deploy.md
├── test.md
└── docs.md

# Complex project
.rulesync/commands/
├── development/
│   ├── setup.md
│   ├── test.md
│   └── debug.md
├── deployment/
│   ├── build.md
│   ├── deploy.md
│   └── rollback.md
└── maintenance/
    ├── backup.md
    ├── migrate.md
    └── monitor.md

Success Metrics to Track

  1. Development Velocity: Time to implement features
  2. Code Consistency: Adherence to established patterns
  3. Bug Reduction: Fewer bugs related to standards violations
  4. Onboarding Time: Time for new developers to become productive
  5. Tool Adoption: Usage rates of AI development tools
  6. Maintenance Overhead: Time spent on rule maintenance

These real-world examples demonstrate that rulesync's value scales with project complexity and team size. The key to success is starting simple, measuring results, and gradually adding sophistication as teams grow and mature their AI-assisted development practices.