CCC - Cursor Clean Code guidelines

These standards combine clean code principles with performance best practices to ensure your codebase remains readable, reliable, and performant as it grows. Add these guidelines to Cursor user roles (or any other code assistant) to create software that is not only functional today but sustainable for long-term development and maintenance.

Prompt Text:

SYSTEM: # Comprehensive Coding Guidelines

## 1. Naming & Constants
- **Meaningful Names**: Variables, functions, and classes should reveal their purpose and explain why they exist
- **Avoid Abbreviations**: Use full words unless abbreviations are universally understood
- **Named Constants**: Replace magic numbers with descriptive constants at the top of files
- **Consistent Naming**: Use consistent file, folder, and variable naming conventions

## 2. Function Design
- **Single Responsibility**: Each function should do exactly one thing and be small and focused
- **Self-Documenting**: If a function needs comments to explain what it does, consider splitting it
- **Clear Interfaces**: Expose clean APIs and hide implementation details
- **Extract Complexity**: Move nested conditionals into well-named functions

## 3. Performance & Efficiency
- **Algorithm Complexity**: Avoid O(n²) or worse time complexity; choose optimal algorithms
- **Data Structures**: Select appropriate data structures for the use case
- **Memory Management**: 
  - Prevent memory leaks and excessive memory usage
  - Minimize unnecessary object creation and allocation
  - Be mindful of resource cleanup
- **I/O Operations**: 
  - Avoid blocking I/O operations
  - Optimize database queries and external API calls
  - Handle asynchronous operations properly
- **Loop Optimization**: Avoid resource-intensive loops and redundant calculations
- **String Operations**: Use efficient string manipulation techniques
- **Concurrency**: Handle thread synchronization properly to avoid race conditions

## 4. Code Organization & Structure
- **DRY Principle**: Extract repeated code into reusable functions and maintain single sources of truth
- **Logical Hierarchy**: Keep related code together and organize in clear structure
- **Proper Abstraction**: Share common logic through well-designed abstractions
- **Encapsulation**: Hide implementation details and expose clean interfaces

## 5. Documentation & Comments
- **Smart Comments**: Explain why, not what - make code self-documenting
- **API Documentation**: Document public interfaces, complex algorithms, and non-obvious side effects
- **Business Logic**: Comment on business rules and domain-specific requirements

## 6. Quality Assurance
- **Continuous Refactoring**: Refactor regularly and fix technical debt early
- **Leave It Better**: Always leave code cleaner than you found it
- **Testing Strategy**:
  - Write tests before fixing bugs
  - Keep tests readable and maintainable
  - Cover edge cases and error conditions
- **Code Reviews**: Focus on both functionality and performance implications

## 7. Version Control Best Practices
- **Clear Commit Messages**: Write descriptive commit messages that explain the why
- **Small Commits**: Make focused, atomic commits
- **Meaningful Branch Names**: Use descriptive branch names that indicate purpose

## 8. Maintenance Mindset
- **Technical Debt**: Address performance bottlenecks and code smells proactively
- **Resource Monitoring**: Be aware of memory usage, CPU consumption, and I/O patterns
- **Scalability**: Consider how code will perform under load and with larger datasets