.claude/skills/prisma/SKILL.md
Prisma ORM for type-safe database operations with PostgreSQL. Use when: Defining schemas, writing type-safe queries, creating migrations, modeling relations, or replacing raw SQL with ORM patterns.
npx skillsauth add kaxuna1/ecomsite prismaInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Provides type-safe database operations as an alternative to raw SQL. This codebase currently uses the pg library with raw SQL queries. Prisma offers automatic type generation, declarative schema modeling, and migration management - eliminating the manual row mapping and SQL injection risks present in raw SQL approaches.
cd backend
npm install prisma @prisma/client
npx prisma init
// prisma/schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Product {
id Int @id @default(autoincrement())
name String
shortDescription String @map("short_description")
description String
price Decimal @db.Decimal(10, 2)
salePrice Decimal? @map("sale_price") @db.Decimal(10, 2)
imageUrl String @map("image_url")
inventory Int @default(0)
categories Json
highlights Json?
usage String?
isNew Boolean @default(false) @map("is_new")
isFeatured Boolean @default(false) @map("is_featured")
salesCount Int @default(0) @map("sales_count")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
translations ProductTranslation[]
orderItems OrderItem[]
variants ProductVariant[]
@@map("products")
}
model ProductTranslation {
id Int @id @default(autoincrement())
productId Int @map("product_id")
languageCode String @map("language_code") @db.VarChar(10)
name String @db.VarChar(255)
shortDescription String @map("short_description")
description String
highlights Json?
usage String?
slug String? @db.VarChar(255)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
language Language @relation(fields: [languageCode], references: [code], onDelete: Cascade)
@@unique([productId, languageCode])
@@map("product_translations")
}
// backend/src/db/prisma.ts
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['query', 'warn', 'error'] : ['error'],
});
export { prisma };
| Concept | Usage | Example |
|---------|-------|---------|
| @map | Map field to snake_case column | @map("created_at") |
| @@map | Map model to table name | @@map("products") |
| Relations | Define FK relationships | product Product @relation(...) |
| @db.Decimal | Specify PostgreSQL types | @db.Decimal(10, 2) |
| @@unique | Composite unique constraints | @@unique([productId, languageCode]) |
| Transactions | Atomic operations | prisma.$transaction([...]) |
When: Getting localized content with English fallback
const product = await prisma.product.findUnique({
where: { id: productId },
include: {
translations: {
where: { languageCode: lang },
},
},
});
// Apply translation or fallback to base
const name = product.translations[0]?.name ?? product.name;
When: Creating orders with inventory updates
await prisma.$transaction(async (tx) => {
const order = await tx.order.create({ data: orderData });
for (const item of items) {
await tx.orderItem.create({
data: { orderId: order.id, ...item },
});
await tx.product.update({
where: { id: item.productId },
data: { inventory: { decrement: item.quantity } },
});
}
return order;
});
tools
Zustand lightweight state management with persistence and middleware. Use when: managing client-side state (cart, auth, UI preferences), replacing React Context with simpler API, accessing state outside React components, implementing localStorage persistence
development
Zod schema validation and TypeScript integration for runtime type safety. Use when: Validating API payloads, form inputs, environment variables, or any external data boundaries where TypeScript types alone cannot guarantee safety.
tools
Configures Vite 5.x build tool, dev server, and frontend asset optimization for the Luxia e-commerce platform. Use when: configuring builds, adding environment variables, optimizing bundle size, setting up testing, debugging HMR issues, or adding Vite plugins.
development
Enforces strict TypeScript types across frontend and backend codebases. Use when: Writing new services, DTOs, interfaces, type guards, debugging type errors, or ensuring type safety at API boundaries.