Claude GitHub Copilot Skill

nextjs-prisma

Use when working on a Next.js App Router project that uses Prisma as the ORM — covers server component data fetching, singleton client setup, and type-safe query patterns.

LLM Mart · 0 points · 2 views 0 listing impressions 0 install-command copies
Download drvoss-everything-copilot-cli-skills_development_nextjs-prisma-1ca2355.zip · 1 KB

Install

skills CLI npx skills add https://github.com/drvoss/everything-copilot-cli/tree/main/skills/development/nextjs-prisma
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install drvoss-everything-copilot-cli@llmmart
Git git clone https://github.com/drvoss/everything-copilot-cli.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole drvoss/everything-copilot-cli collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

Next.js + Prisma Combo Skill

When to Use

  • Setting up Prisma in a new Next.js App Router project
  • Reviewing or refactoring data-fetching logic in Server Components
  • Debugging Prisma client instantiation issues (hot-reload client explosion)
  • Implementing type-safe CRUD operations across Server Actions and API routes

Workflow

1. Singleton Client Setup

Ensure Prisma client is instantiated only once across hot reloads:

Use the global cache pattern below (same as rules/frameworks/prisma.md) so development hot reloads reuse one PrismaClient.

// lib/prisma.ts
import { PrismaClient } from "@prisma/client"

const globalForPrisma = global as unknown as { prisma: PrismaClient }

export const prisma =
  globalForPrisma.prisma ??
  new PrismaClient({
    log: process.env.NODE_ENV === "development" ? ["query", "error"] : ["error"],
  })

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma

2. Data Fetching in Server Components

// app/users/page.tsx
import { prisma } from "@/lib/prisma"

export default async function UsersPage() {
  // Runs on the server — safe to use Prisma directly
  const users = await prisma.user.findMany({
    select: { id: true, name: true, email: true },
    orderBy: { createdAt: "desc" },
  })
  return <UserList users={users} />
}

3. Server Actions with Prisma

// app/users/actions.ts
"use server"
import { prisma } from "@/lib/prisma"
import { revalidatePath } from "next/cache"

export async function createUser(data: { name: string; email: string }) {
  await prisma.user.create({ data })
  revalidatePath("/users")
}

4. Avoiding Common Pitfalls

  • Never import prisma in "use client" components — it will fail at runtime
  • Use prisma.$transaction() when a page requires multiple dependent writes
  • Apply select to limit fields — avoid sending sensitive columns to the client
  • Run prisma generate after every schema change before running the dev server

5. Environment Setup Checklist

# 1. Install
pnpm add prisma @prisma/client
pnpm prisma init

# 2. Add DATABASE_URL to .env
# 3. Define schema in prisma/schema.prisma
# 4. Run first migration
pnpm prisma migrate dev --name init

# 5. Generate client
pnpm prisma generate

Rules Applied

  • rules/frameworks/nextjs.md — App Router, Server Components, environment variables
  • rules/frameworks/prisma.md — schema design, singleton client, query safety
  • rules/common/security.md — secrets management, input validation
Files (everything-copilot-cli)
  • SKILL.md 2.8 KB
    ---
    name: nextjs-prisma
    license: MIT
    description: Use when working on a Next.js App Router project that uses Prisma as the ORM — covers server component data fetching, singleton client setup, and type-safe query patterns.
    metadata:
      category: development
      agent_type: general-purpose
      combo: "next, prisma"
    ---
    
    # Next.js + Prisma Combo Skill
    
    ## When to Use
    
    - Setting up Prisma in a new Next.js App Router project
    - Reviewing or refactoring data-fetching logic in Server Components
    - Debugging Prisma client instantiation issues (hot-reload client explosion)
    - Implementing type-safe CRUD operations across Server Actions and API routes
    
    ## Workflow
    
    ### 1. Singleton Client Setup
    
    Ensure Prisma client is instantiated only once across hot reloads:
    
    > Use the `global` cache pattern below (same as `rules/frameworks/prisma.md`) so development hot reloads reuse one `PrismaClient`.
    
    ```typescript
    // lib/prisma.ts
    import { PrismaClient } from "@prisma/client"
    
    const globalForPrisma = global as unknown as { prisma: PrismaClient }
    
    export const prisma =
      globalForPrisma.prisma ??
      new PrismaClient({
        log: process.env.NODE_ENV === "development" ? ["query", "error"] : ["error"],
      })
    
    if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma
    ```
    
    ### 2. Data Fetching in Server Components
    
    ```typescript
    // app/users/page.tsx
    import { prisma } from "@/lib/prisma"
    
    export default async function UsersPage() {
      // Runs on the server — safe to use Prisma directly
      const users = await prisma.user.findMany({
        select: { id: true, name: true, email: true },
        orderBy: { createdAt: "desc" },
      })
      return <UserList users={users} />
    }
    ```
    
    ### 3. Server Actions with Prisma
    
    ```typescript
    // app/users/actions.ts
    "use server"
    import { prisma } from "@/lib/prisma"
    import { revalidatePath } from "next/cache"
    
    export async function createUser(data: { name: string; email: string }) {
      await prisma.user.create({ data })
      revalidatePath("/users")
    }
    ```
    
    ### 4. Avoiding Common Pitfalls
    
    - Never import `prisma` in `"use client"` components — it will fail at runtime
    - Use `prisma.$transaction()` when a page requires multiple dependent writes
    - Apply `select` to limit fields — avoid sending sensitive columns to the client
    - Run `prisma generate` after every schema change before running the dev server
    
    ### 5. Environment Setup Checklist
    
    ```bash
    # 1. Install
    pnpm add prisma @prisma/client
    pnpm prisma init
    
    # 2. Add DATABASE_URL to .env
    # 3. Define schema in prisma/schema.prisma
    # 4. Run first migration
    pnpm prisma migrate dev --name init
    
    # 5. Generate client
    pnpm prisma generate
    ```
    
    ## Rules Applied
    
    - `rules/frameworks/nextjs.md` — App Router, Server Components, environment variables
    - `rules/frameworks/prisma.md` — schema design, singleton client, query safety
    - `rules/common/security.md` — secrets management, input validation
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.