Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions .cursor/rules/medusa-development.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,46 @@ You are an expert in Medusa v2, TypeScript, Node.js, PostgreSQL, and modern e-co
// Module definition pattern
import { Module } from "@medusajs/framework/utils"

export const myModule = Module("my-module", {
export const MY_MODULE = "my-module"

export default Module(MY_MODULE, {
service: MyService,
model: [MyModel],
})
```

// Service pattern with dependency injection
### Service Pattern with Dependency Injection
```typescript
import { MedusaService } from "@medusajs/framework/utils"
import MyModel from "./models/my-model"

class MyService extends MedusaService({
MyModel,
}) {
async create(data: CreateMyEntityInput): Promise<MyEntity> {
return await this.myModelRepository_.create(data)
// CRUD methods are automatically generated by MedusaService
// You can add custom methods here
async customMethod(data: CustomInput): Promise<CustomOutput> {
return await this.myModelRepository_.customQuery(data)
}
}
```

### Module Registration
```typescript
// medusa-config.ts
import { defineConfig } from "@medusajs/framework/utils"

export default defineConfig({
projectConfig: {
// ... other config
},
modules: [
{
resolve: "./src/modules/my-module",
},
],
})
```

### API Route Patterns
```typescript
// Admin API route
Expand Down
Loading