Skip to content

Add Cursor AI rules for improved code generation#4

Open
burnjohn wants to merge 2 commits into
mainfrom
feature/add-cursor-rules
Open

Add Cursor AI rules for improved code generation#4
burnjohn wants to merge 2 commits into
mainfrom
feature/add-cursor-rules

Conversation

@burnjohn
Copy link
Copy Markdown
Collaborator

@burnjohn burnjohn commented Dec 7, 2025

Adds structured Cursor rules to improve AI-assisted development:

  • global.mdc: Core style rules (no semicolons, Ant Design only, theme tokens)
  • frontend.mdc: React patterns, hooks, i18n, forms
  • backend.mdc: Express patterns, asyncHandler, route organization

KISS approach with 3 focused files + README. All examples use actual codebase patterns.

- Add 3 concise rule files: global, frontend, and backend
- Rules enforce Ant Design patterns, theme tokens, and project conventions
- Include contextual patterns for React components and Express controllers
Comment thread .cursor/rules/backend.mdc Outdated
Comment thread .cursor/rules/backend.mdc
Address PR review comments:
- Change 'Bad' label to 'Verbose' in Controller Pattern example
- Add explanation of why asyncHandler is preferred (DRY, consistency, maintainability)
- Expand Validation section with 7 comprehensive patterns:
  * ObjectId validation
  * Enum/allowed values validation
  * File type and size validation
  * Email validation
  * String sanitization
  * Conditional validation
- Add reference to validators/blogValidator.js for real examples
Copy link
Copy Markdown
Collaborator Author

@burnjohn burnjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the excellent questions! I've addressed both comments with comprehensive improvements:

Comment 1 (Controller Pattern): You're right - the try-catch isn't "bad", just verbose. I've relabeled it and added a detailed explanation of why asyncHandler is preferred (DRY principle, consistency, maintainability).

Comment 2 (Validation): Added 7 comprehensive validation patterns:

  • ObjectId validation with mongoose
  • Enum/allowed values checking
  • File type and size validation
  • Email format validation
  • String sanitization and trimming
  • Conditional business logic validation

Also added a reference to the actual validators/blogValidator.js file for real-world examples from the codebase.

All changes maintain the project's style guide (no semicolons, single quotes).

@burnjohn
Copy link
Copy Markdown
Collaborator Author

burnjohn commented Dec 7, 2025

Updates Pushed! 🎉

I've addressed both of your review comments with comprehensive improvements:

Comment 1: "Is it really a bad example?"

Resolution: You're absolutely right! The try-catch pattern isn't "bad" - it's valid code that works correctly.

Changes made:

  • Changed label from "Bad" to "Verbose - manual try-catch (repetitive across controllers)"
  • Added explanation section covering:
    • DRY principle - Centralizes error handling
    • Consistency - Uniform handling across controllers
    • Less boilerplate - Eliminates repetition
    • Maintainability - Single place to update logic

Comment 2: "Can you suggest any other validation"

Resolution: Expanded the Validation section significantly!

Added 7 validation patterns:

  1. Basic Field Validation (improved existing example)
  2. ObjectId Validation - MongoDB ID format checking with mongoose.Types.ObjectId.isValid()
  3. Enum/Allowed Values - Category whitelist validation
  4. File Type & Size - MIME type and 5MB limit checks
  5. Email Validation - Regex-based format validation
  6. String Sanitization - Trim and length limiting
  7. Conditional Validation - Business logic constraints (e.g., "must be reviewed before publishing")

Bonus: Added reference to validators/blogValidator.js for real-world examples from our actual codebase.


All changes follow project conventions (no semicolons, single quotes). Ready for another review! ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant