agentleFS
drvossdrvoss/everything-copilot-cli/skills/development/nextjs-prisma/SKILL.md

nextjs-prisma

Skill47 starsChanged 4 months agoMITView on GitHub

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.

  • Reads credentials
  • Installs packages

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Ensure Prisma client is instantiated only once across hot reloads:

    line 23
  2. Very specific:

    Never import prisma in "use client" components — it will fail at runtime

    line 76
  3. Very specific:

    Use prisma.$transaction() when a page requires multiple dependent writes

    line 77
  4. Very specific:

    Run prisma generate after every schema change before running the dev server

    line 79

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

Next.js version note: The global cache pattern below is recommended for Next.js 13/14. In Next.js 15 (with React 19), module-level singletons are stable across hot reloads — you can use export const prisma = new PrismaClient(...) directly in lib/prisma.ts.

// lib/prisma.ts  (Next.js 13/14 pattern)
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

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.