How i improved code analysis and output using .cursorrules inspired in image generation AIs

How i improved code analysis and output using .cursorrules inspired in image generation AIs

As a UI/UX designer with 15 years of experience, I am able to understand programming logic but i struggle with actual coding. For years, this meant being dependent on developers to bring my designs to life. That changed two months ago when I started using AI coding assistants like Cursor.

This enabled me to became a Indie Hacker, creating products by my own.

Which also created problems on its own.

While AI helped me code independently, I kept running into the same issues:

  • Having to fix similar problems repeatedly
  • Getting shallow solutions for complex systems
  • Missing the depth that comes from developer review
  • Spending too much time testing and validating the code - because i cant do any serious review

As a designer who thinks in systems, this bothered me. There had to be a better way to make AI generate more reliable, well-thought-out code.


:speech_balloon: Results: some issues that i spent days and more than 300 bad prompts - i managed to fix with 5 prompts in less than 10 minutes after doing all these steps.

AI-generated Arts and AI-Generated Code - concept

I was researching AI-generated art when I stumbled upon GANs (Generative Adversarial Networks). The concept immediately clicked with my design background - it was like having an artist and an art critic working together:

  • The Artist (Generator) creates work

  • The Critic (Discriminator) reviews it

  • Their interaction produces better results

This reminded me of my design process:

  • Create a design (like the Generator)

  • Review it critically (like the Discriminator)

  • Iterate until it’s perfect

The Connection to Code Review

Then it hit me - this was exactly what I was missing in my AI coding workflow! When working with real developers, there’s always:

  • One dev writing the code

  • Another dev reviewing it

  • Back-and-forth until the code is solid

But with AI, I was only getting the first part - the code generation. What if I could make Cursor act like both developers?

From Design Process to Code Rules

As a designer, I’m used to creating systems and rules. So I thought:

  • If GANs work through structured opposition…

  • And good code comes from developer collaboration…

  • Then I could create a rule system that makes AI act like two developers!

That’s when I decided to create a Cursor rule that would force every piece of code to go through this dual-validation process. Just like in my design reviews, nothing would be approved until it passed both perspectives.

The Solution: GAN-Inspired Dual Validation

Using my experience with design systems, I created a JSON configuration that makes AI act as two senior developers working together…

Here’s how it works:

  • Developer 1 (The Generator)

  • Analyzes requirements thoroughly

  • Proposes complete solutions

  • Implements changes when needed

  • Documents everything

  • Developer 2 (The Discriminator)

  • Validates every aspect

  • Challenges assumptions

  • Spots potential issues

  • Ensures best practices

  • Only approves when everything is perfect

Nothing proceeds until both “developers” agree – just like in real pair programming!

The rules for the IA

Imagine and Act as two senior developers in pair programming:

Developer 1 (Generator):
1. Analyzes initial requirements
2. When in doubt about requirements:
   - Ask specific questions to the user
   - List all assumed premises
   - Wait for confirmation before proceeding
3. ALWAYS before proposing solution:
   - Verify existing files
   - Analyze required dependencies
   - Plan implementation
   - Separate UI from logic
   - Verify complete application context
4. Proposes initial solution following:
   - DRY and KISS principles
   - Clear documentation
   - Error handling
5. Documents technical decisions
6. Adjusts code based on feedback

Developer 2 (Discriminator):
1. Validates if requirements are clear
2. In case of ambiguity:
   - Question Developer 1
   - Request clarification from user
   - Document received answers
3. Validates proposal by checking:
   - File existence and structure
   - Dependencies and versions
   - SOLID, DRY and KISS principles
   - Separation of concerns (UI/Logic)
   - Security and best practices
   - Overall application context
   - Potential introduced errors
4. Provides detailed feedback
5. Only approves after:
   - All doubts resolved
   - All validations pass
   - Regression check

How to Use This Yourself (.cursorrules format)

{
  "version": "1.0",
  "project": {
    "name": "GAN-Inspired Validation Rules",
    "version": "1.0.0",
    "description": "Dual validation system inspired by GAN architecture"
  },
  "ai_behavior": {
    "roles": {
      "developer1": {
        "type": "generator",
        "responsibilities": [
          "analyze_requirements",
          "propose_solutions",
          "implement_changes",
          "document_decisions"
        ],
        "validation_steps": [
          "verify_existing_files",
          "check_dependencies",
          "plan_implementation",
          "separate_ui_logic",
          "verify_context"
        ]
      },
      "developer2": {
        "type": "discriminator",
        "responsibilities": [
          "validate_proposals",
          "challenge_assumptions",
          "identify_issues",
          "ensure_quality"
        ],
        "validation_criteria": [
          "file_structure",
          "dependencies",
          "code_principles",
          "security",
          "error_handling"
        ]
      }
    },
    "workflow": {
      "require_dual_validation": true,
      "validation_steps": [
        "dev1_proposal",
        "dev2_review",
        "clarification_if_needed",
        "implementation_approval"
      ]
    }
  }
}

Just paste the code below in the cursorrules file as a starting point. then you can prompt your own composer to read your project and add context to the cursorrules files or a .cursorcontext file

Improving: Add context from the project

While this GAN-inspired validation system already improves code quality, here is the catch prompt you can use to generate better material for your cursorrules.

Project Context Analysis Prompt

Analyze my project's @codebase, and please follow this systematic approach and generate a single .cursorcontext.json file. add natural language explanation for each file:

1. Initial Project Scan
   - Map the complete directory structure
   - Identify all file types and their purposes
   - Discover component relationships and dependencies
   - Determine the overall architectural pattern
   - Document build and configuration files

2. Code Analysis
   - Examine each TypeScript/JavaScript file to:
     * Extract component purposes and responsibilities
     * Identify state management patterns
     * Map custom hooks and their usage
     * Document API integration points
     * Note error handling approaches
     * Find performance optimizations

3. Feature Mapping
   - For each core feature:
     * List all related components
     * Document the user workflow
     * Map state management
     * Identify entry points
     * Note edge cases and error states
     * Document loading states
     * List dependencies

4. Component Documentation
   - For each component document:
     * Main responsibility
     * Props and their purposes
     * State management approach
     * Child components
     * Event handlers
     * Key functions
     * Error handling
     * Performance considerations

5. State Management Analysis
   - Document all stores with:
     * Purpose and responsibility
     * State structure
     * Actions and their effects
     * Selectors
     * Integration points
     * Data flow patterns

6. Infrastructure Analysis
   - Document:
     * Build configuration
     * Environment setup
     * API integration
     * Authentication flow
     * Data persistence
     * File storage
     * Security measures

Please generate a cursorcontext.json that includes:
1. Complete project metadata
2. Feature-by-feature breakdown
3. Component hierarchy and relationships
4. State management flows
5. Utility functions and their purposes
6. Code standards and patterns
7. Security considerations
8. Performance optimizations

The output should be:
- Hierarchically organized
- Clear about relationships
- Completely documented
- Actionable for developers
- Focused on maintainability

Each feature documentation must include:
- Clear entry points
- Complete workflow
- Error states
- Loading states
- Dependencies
- State management

Each component documentation must include:
- Clear responsibility
- Props documentation
- State management
- Error handling
- Child components
- Event handlers
- Short explanation of what it does in natural language

Depending on the size of your project, your context is going to be huge. Here’s what i got from my project which is a little similar to instagram in terms of features.

{
  "project": {
    "name": "vite_react_shadcn_ts",
    "description": "A modern React application built with Vite and TypeScript, featuring a comprehensive social commerce platform with authentication, real-time messaging, and product management capabilities.",
    "architecture": {
      "frontend": {
        "framework": {
          "core": "React + Vite",
          "language": "TypeScript",
          "ui_system": "shadcn/ui + TailwindCSS",
          "state": "Zustand",
          "routing": "React Router",
          "form": "react-hook-form",
          "i18n": "i18next"
        },
        "explanation": "The frontend architecture uses React with Vite for fast development and builds, TypeScript for type safety, and shadcn/ui with TailwindCSS for consistent styling. State management is handled by Zustand for its simplicity and performance."
      }
    }
  },
  "feature_modules": {
    "auth": {
      "description": "Authentication module handling user login, registration, and session management. Implements both email/password and Google OAuth flows with email verification.",
      "entry_points": {
        "LoginModal": {
          "description": "Modal component that serves as the main entry point for user authentication. Handles both email/password and social login flows, with built-in validation and error handling.",
          "key_features": [
            "Email/password authentication",
            "Google OAuth integration",
            "Form validation",
            "Error message display",
            "Loading states"
          ]
        },
        "AuthContent": {
          "description": "Container component that manages the authentication flow state and renders the appropriate authentication step based on the current state.",
          "workflow": "Handles the progression through authentication steps, from initial login to email verification and success states."
        }
      }
    },
    "search": {
      "description": "Comprehensive search system with filters, real-time results, and caching capabilities.",
      "components": {
        "SearchContainer": {
          "description": "Main search interface container that coordinates the search experience. Manages search state, filters, and results display.",
          "key_features": [
            "Real-time search updates",
            "Filter management",
            "Results pagination",
            "Search history"
          ]
        },
        "SearchFilters": {
          "description": "Filter interface allowing users to refine search results. Supports multiple filter types and combinations.",
          "features": [
            "Dynamic filter options",
            "Filter combination logic",
            "Clear filters",
            "Filter persistence"
          ]
        }
      }
    },
    "product": {
      "description": "Product management module handling product creation, editing, and display.",
      "components": {
        "ProductList": {
          "description": "Displays a grid of products with infinite scroll and filtering capabilities. Optimized for performance with virtualization for large lists.",
          "features": [
            "Infinite scroll",
            "Grid/List view toggle",
            "Quick actions",
            "Loading states"
          ]
        },
        "ProductForm": {
          "description": "Form component for creating and editing products. Handles image uploads, validation, and product metadata.",
          "features": [
            "Multi-image upload",
            "Form validation",
            "Auto-save drafts",
            "Preview mode"
          ]
        }
      }
    },
    "messages": {
      "description": "Real-time messaging system with conversation management and media sharing capabilities.",
      "components": {
        "MessageDialog": {
          "description": "Main messaging interface showing conversations and message thread. Supports real-time updates and message status.",
          "features": [
            "Real-time messages",
            "Read receipts",
            "Media sharing",
            "Typing indicators"
          ]
        },
       }

/// i wont paste it all here because i got over 2000 lines
}

Taking It Further: Self-Improving Rules with CursorFocus

We can make it even smarter by combining it with CursorFocus. Instead of static rules, your validation system can evolve with your project in real-time.

The Simple Workflow:

Why This Matters:

The validation system automatically:

  • Learn your project’s patterns as you code

  • Update validation rules based on new components

  • Adjust to architectural changes in real-time

  • Maintain context across different coding sessions

The two virtual developers (Generator and Discriminator) have real-time knowledge to the entire project. They have full context and adapt to the specific codebase as it grows.

By using the focus.md generated by CursorFocus as file reference, we dont need to manually update rules or explain project context repeatedly. Just ask Cursor to re-read Focus.md whenever you want the latest context applied to your validation rules.

11 Likes

Amazing post, it’s cool to see the solution you came up with to better make use of Cursor’s power while filling in some of its knowledge gaps about your codebase!

This post is a goldmine, thank you for writing this.

1 Like