Skip to content

Commit bf7336a

Browse files
feat: Add comprehensive Cursor rules for Medusa development
- Add medusa-development.mdc with Medusa v2 patterns and best practices - Add remix-storefront.mdc for React Router v7 storefront development - Add typescript-patterns.mdc with advanced TypeScript patterns - Add testing-patterns.mdc for comprehensive testing strategies - Add comprehensive README.md documentation - Covers API development, modules, services, components, and testing - Includes TypeScript conventions, error handling, and performance optimization - Provides contextual guidance for AI-assisted development
1 parent 72e47cf commit bf7336a

File tree

5 files changed

+2382
-0
lines changed

5 files changed

+2382
-0
lines changed

.cursor/README.md

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
# Cursor Rules for Medusa Development
2+
3+
This directory contains comprehensive Cursor rules designed to enhance AI-assisted development for Medusa v2 applications. These rules provide context-aware suggestions and best practices for building scalable e-commerce applications.
4+
5+
## 📁 Rule Files Overview
6+
7+
### Core Development Rules
8+
9+
#### `medusa-development.mdc`
10+
**Primary rule file for Medusa v2 backend development**
11+
- Medusa v2 architectural patterns and conventions
12+
- Module, service, and API route development
13+
- Database models and repository patterns
14+
- Workflow and subscriber implementations
15+
- Security and validation best practices
16+
- Performance optimization techniques
17+
18+
#### `remix-storefront.mdc`
19+
**Comprehensive rules for React Router v7 (Remix) storefront development**
20+
- React Router v7 patterns and conventions
21+
- Medusa SDK integration
22+
- Form handling with @lambdacurry/forms
23+
- Component patterns and styling with Tailwind CSS
24+
- SEO optimization and meta tag management
25+
- Performance optimization and accessibility
26+
27+
#### `typescript-patterns.mdc`
28+
**Advanced TypeScript patterns and best practices**
29+
- Type definitions and interface design
30+
- Generic types and utility types
31+
- Error handling patterns
32+
- Async programming patterns
33+
- Functional programming concepts
34+
- Testing type definitions
35+
36+
#### `testing-patterns.mdc`
37+
**Comprehensive testing strategies for Medusa applications**
38+
- Unit testing for services and components
39+
- Integration testing for APIs and databases
40+
- End-to-end testing with Playwright
41+
- Test utilities and factories
42+
- Mocking strategies and best practices
43+
44+
#### `remix-hook-form-migration.mdc`
45+
**Migration guide from remix-validated-form to @lambdacurry/forms**
46+
- Form validation patterns (Yup to Zod)
47+
- Component migration examples
48+
- Error handling updates
49+
- Response handling patterns
50+
51+
## 🚀 Getting Started
52+
53+
### Prerequisites
54+
- Cursor IDE installed
55+
- Medusa v2 project setup
56+
- TypeScript configuration
57+
58+
### Activation
59+
These rules are automatically applied based on file patterns:
60+
- `.mdc` files in `.cursor/rules/` are automatically loaded
61+
- Rules apply to specific file patterns defined in each rule's `globs` section
62+
- `alwaysApply: true` ensures rules are active for matching files
63+
64+
### File Pattern Targeting
65+
66+
| Rule File | Target Files |
67+
|-----------|-------------|
68+
| `medusa-development.mdc` | `apps/medusa/**/*.ts`, `apps/medusa/**/*.tsx` |
69+
| `remix-storefront.mdc` | `apps/storefront/**/*.ts`, `apps/storefront/**/*.tsx` |
70+
| `typescript-patterns.mdc` | `**/*.ts`, `**/*.tsx` |
71+
| `testing-patterns.mdc` | `**/*.test.ts`, `**/*.spec.ts`, `**/__tests__/**/*` |
72+
| `remix-hook-form-migration.mdc` | All TypeScript files (migration context) |
73+
74+
## 🎯 Key Features
75+
76+
### Medusa v2 Specific Guidance
77+
- **Module Development**: Patterns for creating custom Medusa modules
78+
- **Service Layer**: Dependency injection and business logic patterns
79+
- **API Routes**: RESTful endpoint development for admin and store APIs
80+
- **Database Integration**: Model definitions and repository patterns
81+
- **Event-Driven Architecture**: Subscribers and workflow implementations
82+
83+
### React/Remix Best Practices
84+
- **Component Architecture**: Reusable component patterns
85+
- **State Management**: Cart management with Zustand
86+
- **Form Handling**: Modern form patterns with react-hook-form
87+
- **Performance**: Code splitting, image optimization, caching strategies
88+
- **SEO**: Meta tags, structured data, accessibility
89+
90+
### TypeScript Excellence
91+
- **Type Safety**: Advanced type patterns and utility types
92+
- **Error Handling**: Result patterns and custom error types
93+
- **Async Patterns**: Promise utilities and async iterators
94+
- **Testing**: Type-safe testing patterns and mock utilities
95+
96+
## 🛠️ Usage Examples
97+
98+
### Creating a New Medusa Service
99+
When creating a new service file in `apps/medusa/src/services/`, Cursor will suggest:
100+
101+
```typescript
102+
import { MedusaService } from "@medusajs/framework/utils"
103+
104+
class MyService extends MedusaService({
105+
MyModel,
106+
}) {
107+
async create(data: CreateMyEntityInput): Promise<MyEntity> {
108+
return await this.myModelRepository_.create(data)
109+
}
110+
}
111+
```
112+
113+
### Building React Components
114+
When working in `apps/storefront/app/components/`, Cursor will suggest:
115+
116+
```typescript
117+
interface ProductCardProps {
118+
product: Product
119+
className?: string
120+
}
121+
122+
export function ProductCard({ product, className }: ProductCardProps) {
123+
// Component implementation with proper TypeScript and accessibility
124+
}
125+
```
126+
127+
### Writing Tests
128+
When creating test files, Cursor will suggest proper testing patterns:
129+
130+
```typescript
131+
describe("UserService", () => {
132+
let container: MedusaContainer
133+
let userService: UserService
134+
135+
beforeEach(() => {
136+
container = createMedusaContainer()
137+
userService = container.resolve("userService")
138+
})
139+
140+
it("should create a new user with valid data", async () => {
141+
// Arrange, Act, Assert pattern
142+
})
143+
})
144+
```
145+
146+
## 📚 Best Practices Enforced
147+
148+
### Code Quality
149+
- ✅ Strict TypeScript usage
150+
- ✅ Proper error handling
151+
- ✅ Input validation with Zod
152+
- ✅ Comprehensive testing
153+
- ✅ Performance optimization
154+
155+
### Architecture
156+
- ✅ Modular design patterns
157+
- ✅ Dependency injection
158+
- ✅ Event-driven architecture
159+
- ✅ RESTful API design
160+
- ✅ Database best practices
161+
162+
### Security
163+
- ✅ Input sanitization
164+
- ✅ Authentication patterns
165+
- ✅ CORS configuration
166+
- ✅ Environment variable management
167+
- ✅ SQL injection prevention
168+
169+
## 🔧 Customization
170+
171+
### Adding Custom Rules
172+
1. Create a new `.mdc` file in `.cursor/rules/`
173+
2. Define the rule metadata:
174+
```yaml
175+
---
176+
description: Your custom rule description
177+
globs:
178+
- "path/to/target/files/**/*.ts"
179+
alwaysApply: true
180+
---
181+
```
182+
3. Add your custom guidance and patterns
183+
184+
### Modifying Existing Rules
185+
- Edit the relevant `.mdc` file
186+
- Rules are automatically reloaded by Cursor
187+
- Test changes with relevant file types
188+
189+
## 🎨 Integration with Development Workflow
190+
191+
### With Medusa CLI
192+
These rules complement Medusa CLI commands:
193+
- `medusa develop` - Rules provide guidance during development
194+
- `medusa build` - Rules ensure production-ready code patterns
195+
- `medusa db:migrate` - Rules suggest proper migration patterns
196+
197+
### With Package Scripts
198+
Rules enhance development with existing scripts:
199+
- `yarn dev` - Real-time guidance during development
200+
- `yarn build` - Production build optimization suggestions
201+
- `yarn test` - Testing pattern recommendations
202+
- `yarn typecheck` - TypeScript best practice enforcement
203+
204+
## 📖 Learning Resources
205+
206+
### Official Documentation
207+
- [Medusa v2 Documentation](https://docs.medusajs.com/)
208+
- [React Router v7 Documentation](https://reactrouter.com/)
209+
- [Cursor Rules Documentation](https://docs.cursor.com/context/rules)
210+
211+
### Code Examples
212+
Each rule file contains extensive code examples demonstrating:
213+
- Common patterns and anti-patterns
214+
- Best practice implementations
215+
- Error handling strategies
216+
- Performance optimization techniques
217+
218+
## 🤝 Contributing
219+
220+
### Improving Rules
221+
1. Identify areas for improvement in existing rules
222+
2. Add new patterns based on project experience
223+
3. Update examples with real-world scenarios
224+
4. Ensure rules stay current with framework updates
225+
226+
### Feedback
227+
- Report issues with rule suggestions
228+
- Suggest new patterns or improvements
229+
- Share successful implementations
230+
231+
## 📝 Maintenance
232+
233+
### Regular Updates
234+
- Keep rules synchronized with Medusa v2 updates
235+
- Update React Router patterns as the framework evolves
236+
- Refresh TypeScript patterns with new language features
237+
- Maintain testing patterns with latest testing library updates
238+
239+
### Version Compatibility
240+
- Rules are designed for Medusa v2.7.0+
241+
- React Router v7 compatibility
242+
- TypeScript 5.6+ features
243+
- Node.js 20+ patterns
244+
245+
---
246+
247+
These Cursor rules are designed to accelerate development while maintaining code quality and consistency across the Medusa application. They serve as an intelligent coding assistant, providing contextual guidance based on the specific file and framework being used.
248+

0 commit comments

Comments
 (0)