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:
- ๐ Define what to build
- ๐๏ธ Specify how to structure it
- โ Establish quality standards
- ๐ค 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:
- Purpose - Why this module exists
- File structure - Exact files to create
- API endpoints - Request/response contracts
- Service interfaces - Method signatures
- State machines - Status transitions
- 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:
- Be specific - Include exact types, not just descriptions
- Be complete - Cover error cases and edge conditions
- Be consistent - Use same patterns across modules
- 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
- GitHub: https://github.com/itayshmool/wix-ucp
-
Rules folder:
.cursor/rules/ - Live demo: https://wix-ucp-api.onrender.com/test-ui/wizard
๐ Thank You!
Questions about specification-first development?
Browse the rules: https://github.com/itayshmool/wix-ucp/tree/main/.cursor/rules
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