Backend API patterns for Shopify app. Auto-apply when writing webhooks, Prisma models, background jobs, API routes, authentication, or server-side code in app/models/ or app/services/.
Áp dụng conventions này khi develop backend code: API routes, webhooks, database, background jobs, authentication.
| Layer | Technology | Notes |
|---|---|---|
| Runtime | Node.js | LTS version |
| Framework | Remix (server-side) | Loaders/actions = API endpoints |
| ORM | Prisma | Type-safe DB access |
| Database | SQLite → PostgreSQL | SQLite for start, PostgreSQL when scaling |
| Queue | DB-based queue | Lightweight, no Redis dependency |
| Cron | node-cron | In-process scheduled tasks |
| Validation | Zod | Runtime type validation |
| Auth | Shopify OAuth |
Via @shopify/shopify-app-remix |
app/
├── models/ # Prisma helper functions (data access layer)
│ ├── product.server.ts
│ ├── order.server.ts
│ └── setting.server.ts
├── services/ # Business logic layer
│ ├── order-processing.server.ts
│ ├── sync.server.ts
│ └── notification.server.ts
├── jobs/ # Background job definitions
│ ├── queue.server.ts # DB-based queue setup
│ ├── cron.server.ts # Scheduled tasks (node-cron)
│ ├── processOrder.ts
│ └── syncInventory.ts
├── utils/
│ ├── validation.server.ts # Zod schemas
│ └── errors.server.ts # Custom error classes
└── webhooks/ # Webhook handlers
├── orders-create.ts
├── app-uninstalled.ts
└── index.ts # Webhook registry
.server.ts suffix cho server-only code (Remix tree-shakes client bundles)Xem chi tiết tại patterns.md bao gồm:
// Naming: PascalCase models, camelCase fields
// Mọi model có timestamps
// Soft delete qua deletedAt
// Shop relation bắt buộc (multi-tenant)
model Resource {
id String @id @default(cuid())
shop String // Shopify shop domain (tenant key)
name String
slug String
status ResourceStatus @default(DRAFT)
description String?
// Relations
items Item[]
// Timestamps
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime? // Soft delete
// Indexes
@@unique([shop, slug])
@@index([shop, status])
@@index([deletedAt])
}
enum ResourceStatus {
DRAFT
ACTIVE
PAUSED
ARCHIVED
}
.server.ts suffix cho tất cả server-only code{ error: { code, message, details } }console.log plain text)cuid() hoặc ulid() cho IDs (không auto-increment)console.log trong production — dùng structured loggerany type cho API responses$ARGUMENTS