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?

Specification-First Development with Cursor Rules

By Itay Shmool

Specification-First Development with Cursor Rules

Discover the innovative Cursor Rules methodology that enabled seamless integration of Wix UCP without coding. Explore the project overview, core types, schemas, and module specifications that revolutionize development processes. Curiosity awaits!

  • 17