Conext-Driven Development with Cursor Rules

How We Built the Wix UCP Integration Without Writing Code First

🎯 The Challenge

Build a complete UCP integration for Wix e-commerce with:

  • 6 complex modules
  • 16 MCP tools
  • 493+ tests
  • Full API documentation
  • Production deployment

Traditional approach: Jump into code, figure it out as we go

Our approach: Write specifications first, then generate code

πŸ’‘ The Cursor Rules Methodology

What are Cursor Rules?

Cursor Rules (.mdc files) are markdown specification documents that:

  1. πŸ“‹ Define what to build
  2. πŸ—οΈ Specify how to structure it
  3. βœ… Establish quality standards
  4. πŸ€– Guide AI code generation

Think of them as executable blueprints that Cursor AI can follow.

πŸ“ Our Rule Structure

.cursor/rules/
β”œβ”€β”€ 00-project-overview.mdc      # Master blueprint
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ core-ucp.mdc            # Types, schemas, utilities
β”‚   β”œβ”€β”€ payment-handler.mdc     # Payment tokenization
β”‚   β”œβ”€β”€ checkout.mdc            # Checkout capability
β”‚   β”œβ”€β”€ discovery.mdc           # Business profile
β”‚   β”œβ”€β”€ identity.mdc            # OAuth linking
β”‚   β”œβ”€β”€ orders.mdc              # Order management
β”‚   └── mcp-bridge.mdc          # AI agent interface
β”œβ”€β”€ infrastructure/
β”‚   β”œβ”€β”€ deployment.mdc          # Render hosting
β”‚   └── render-deployment.mdc   # Live deployment details
└── practices/
    β”œβ”€β”€ tdd.mdc                 # Test-driven development
    β”œβ”€β”€ testing.mdc             # Testing strategy
    └── security.mdc            # Security practices

πŸ“„ Rule #1: Project Overview

File: 00-project-overview.mdc

What it defines:

  • 🎯 Project purpose and scope
  • πŸ—οΈ High-level architecture diagram
  • πŸ› οΈ Technology stack decisions
  • πŸ“¦ Module responsibilities
  • πŸ“ Directory structure
  • πŸ“ Coding standards
  • πŸ”„ Git workflow

πŸ“„ Rule #1: Project Overview

File: 00-project-overview.mdc

Key excerpt:

## Module Responsibilities

| Module | Responsibility |
|--------|----------------|
| `core-ucp` | UCP protocol types, schemas, utilities |
| `payment-handler` | Wix Payments tokenization as UCP handler |
| `checkout-capability` | UCP Checkout using Wix eCommerce |
| `discovery-profile` | Business profile advertisement |
| `mcp-bridge` | Bridge Wix MCP to UCP protocol |
| `identity-linking` | OAuth 2.0 account linking |
| `order-management` | Post-purchase order tracking |

πŸ“„ Rule #2: Core Types & Schemas

File: modules/core-ucp.mdc

What it defines:

  • πŸ“Š All TypeScript interfaces
  • βœ… Zod validation schemas
  • πŸ”§ Utility function signatures
  • πŸ“Œ Protocol constants
  • ⚠️ Error types and codes

πŸ“„ Rule #2: Core Types & Schemas

File: modules/core-ucp.mdc

Key excerpt:

// Types defined BEFORE implementation
interface CheckoutSession {
  ucp: UCPVersion;
  id: string;
  status: CheckoutStatus;
  currency: string;
  buyer?: Buyer;
  lineItems: LineItem[];
  totals: Total[];
  payment?: PaymentInfo;
  // ...
}

type CheckoutStatus = 
  | 'incomplete'
  | 'ready_for_payment'
  | 'ready_for_complete'
  | 'completed'
  | 'expired'
  | 'cancelled';

πŸ“„ Rule #3: Module Specifications

Files: modules/*.mdc

Each module rule defines:

  1. Purpose - Why this module exists
  2. File structure - Exact files to create
  3. API endpoints - Request/response contracts
  4. Service interfaces - Method signatures
  5. State machines - Status transitions
  6. Test requirements - What to test

πŸ“„ Rule #3: Module Specifications

Files: modules/*.mdc

Example: Checkout Module

## File Structure

src/modules/checkout/
β”œβ”€β”€ index.ts              # Module exports
β”œβ”€β”€ service.ts            # Main checkout service
β”œβ”€β”€ session-manager.ts    # Session lifecycle
β”œβ”€β”€ cart-mapper.ts        # Wix β†’ UCP mapping
β”œβ”€β”€ pricing-engine.ts     # Calculations
β”œβ”€β”€ state-machine.ts      # Status transitions
β”œβ”€β”€ types.ts              # Module types
└── routes.ts             # API endpoints

πŸ“„ Rule #4: TDD Enforcement

File: practices/tdd.mdc

Mandatory Rules:

- ❌ NEVER write implementation without a failing test first
- ❌ NEVER skip the red phase
- βœ… ALWAYS write test before implementation
- βœ… ALWAYS confirm test fails before implementing

Red-Green-Refactor Cycle:

Phase Action
πŸ”΄ RED Write failing test
βœ… GREEN Write minimal code to pass
πŸ”„ REFACTOR Clean up while tests pass

Coverage Targets:

  • Overall: 70% minimum
  • Business logic: 90%+
  • Payment flows: 95%+

πŸ“„ Rule #5: Infrastructure

File: infrastructure/deployment.mdc

Complete deployment spec:

# Render services defined before writing code
services:
  - name: wix-ucp-api
    type: web_service
    runtime: node
    plan: starter
    
  - name: wix-ucp-db
    type: postgres
    plan: free
    
  - name: wix-ucp-redis
    type: redis
    plan: free

πŸ“„ Rule #5: Infrastructure

File: infrastructure/deployment.mdc

Architecture diagram:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 RENDER PLATFORM                  β”‚
β”‚                                                  β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚ Web Serviceβ”‚   β”‚ Postgresβ”‚   β”‚  Redis  β”‚   β”‚
β”‚   β”‚  (API)     │──▢│(Storage)β”‚   β”‚ (Cache) β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“„ Rule #6: Security Practices

File: practices/security.mdc

Security requirements defined upfront:

Area Requirement
Auth JWT with jose library
Validation Zod schemas on all inputs
Rate Limiting @fastify/rate-limit
Headers @fastify/helmet
Tokens 15-minute TTL, checkout-bound
Secrets Environment variables only

πŸ”„ The Development Workflow

Phase 1: Write Specifications (Rules)

πŸ“‹ Define types β†’ πŸ“‹ Define APIs β†’ πŸ“‹ Define tests

Phase 2: Generate Code (with Cursor)

πŸ€– "Implement the checkout module following checkout.mdc"

Phase 3: Iterate & Refine

βœ… Run tests β†’ πŸ”§ Fix issues β†’ πŸ“ Update rules

πŸ“Š Results: What We Achieved

Metric Value
Modules 8
MCP Tools 16
Test Cases 493+
Code Coverage 70%+
API Endpoints 25+
Time to Deploy Hours, not weeks

🎯 Benefits of Spec-First

1. Clarity Before Complexity

  • Know exactly what you're building
  • No scope creep or feature confusion

2. Consistent Architecture

  • Same patterns across all modules
  • Easy for AI to follow

3. Built-in Quality

  • Tests defined before code
  • Security baked in from start

4. Faster Development

  • AI generates boilerplate
  • Focus on business logic

5. Self-Documenting

  • Rules ARE the documentation
  • Always up to date

πŸ“ Creating Your Own Rules

Rule Template:

# Module: [Name]

## Purpose
[One-line description]

## File Structure
[Directory tree]

## API Endpoints
[Request/Response specs]

## Service Interface
[Method signatures]

## Testing Requirements
[What to test]

Tips:

  1. Be specific - Include exact types, not just descriptions
  2. Be complete - Cover error cases and edge conditions
  3. Be consistent - Use same patterns across modules
  4. Be testable - Define what success looks like

πŸ”— Our Complete Rule Set

Rule File Purpose
00-project-overview.mdc Master blueprint, architecture
modules/core-ucp.mdc Types, schemas, utilities
modules/payment-handler.mdc Tokenization spec
modules/checkout.mdc Checkout capability
modules/discovery.mdc Profile advertisement
modules/identity.mdc OAuth linking
modules/orders.mdc Order management
modules/mcp-bridge.mdc AI agent interface
infrastructure/deployment.mdc Render hosting
practices/tdd.mdc Test-first rules
practices/testing.mdc Testing strategy
practices/security.mdc Security practices

πŸš€ Key Takeaway

"The best code is the code you don't have to debug because it was specified correctly from the start."

By writing detailed specifications in Cursor Rules before coding:

  • βœ… Clear contracts between modules
  • βœ… Consistent code generation
  • βœ… Built-in test requirements
  • βœ… Security by design
  • βœ… Production-ready from day one

πŸ“š Resources

πŸ™ Thank You!

Questions about specification-first development?