# Nestjs Prisma

> Use when building a NestJS application with Prisma — covers PrismaService setup as an injectable singleton, repository pattern integration, and testing with Prisma mocks.

- **Type:** Skill
- **Install:** `agentstack add skill-drvoss-everything-copilot-cli-nestjs-prisma`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [drvoss](https://agentstack.voostack.com/s/drvoss)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [drvoss](https://github.com/drvoss)
- **Source:** https://github.com/drvoss/everything-copilot-cli/tree/main/skills/development/nestjs-prisma

## Install

```sh
agentstack add skill-drvoss-everything-copilot-cli-nestjs-prisma
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# NestJS + Prisma Combo Skill

## When to Use

- Setting up Prisma in a NestJS project for the first time
- Implementing a data access layer using Prisma as the ORM
- Writing unit tests for services that depend on Prisma
- Debugging connection pooling or client lifecycle issues

## Workflow

### 1. PrismaService Setup

```typescript
// src/prisma/prisma.service.ts
import { Injectable, OnModuleInit, OnModuleDestroy } from "@nestjs/common"
import { PrismaClient } from "@prisma/client"

@Injectable()
export class PrismaService
  extends PrismaClient
  implements OnModuleInit, OnModuleDestroy
{
  async onModuleInit() {
    await this.$connect()
  }
  async onModuleDestroy() {
    await this.$disconnect()
  }
}
```

```typescript
// src/prisma/prisma.module.ts
import { Global, Module } from "@nestjs/common"
import { PrismaService } from "./prisma.service"

@Global()
@Module({
  providers: [PrismaService],
  exports: [PrismaService],
})
export class PrismaModule {}
```

Import `PrismaModule` in `AppModule` once — `@Global()` makes it available everywhere.

### 2. Using PrismaService in a Feature Service

```typescript
// src/users/users.service.ts
import { Injectable } from "@nestjs/common"
import { PrismaService } from "../prisma/prisma.service"

@Injectable()
export class UsersService {
  constructor(private prisma: PrismaService) {}

  async findAll() {
    return this.prisma.user.findMany({
      select: { id: true, name: true, email: true },
    })
  }

  async create(data: { name: string; email: string }) {
    return this.prisma.user.create({ data })
  }
}
```

### 3. Unit Testing with Prisma Mock

```typescript
// src/users/users.service.spec.ts
import { Test } from "@nestjs/testing"
import { UsersService } from "./users.service"
import { PrismaService } from "../prisma/prisma.service"

const mockPrismaService = {
  user: {
    findMany: jest.fn(),
    create: jest.fn(),
  },
}

describe("UsersService", () => {
  let service: UsersService

  beforeEach(async () => {
    const module = await Test.createTestingModule({
      providers: [
        UsersService,
        { provide: PrismaService, useValue: mockPrismaService },
      ],
    }).compile()

    service = module.get(UsersService)
  })

  it("returns all users", async () => {
    mockPrismaService.user.findMany.mockResolvedValue([{ id: 1, name: "Alice" }])
    const result = await service.findAll()
    expect(result).toHaveLength(1)
  })
})
```

### 4. Environment Setup Checklist

```bash
# 1. Install
pnpm add @prisma/client
pnpm add -D prisma

# 2. Initialize
pnpm prisma init

# 3. Add DATABASE_URL to .env
# 4. Define schema then migrate
pnpm prisma migrate dev --name init

# 5. Generate client
pnpm prisma generate
```

## Rules Applied

- `rules/frameworks/nestjs.md` — module structure, DI, controllers, security
- `rules/frameworks/prisma.md` — schema design, client lifecycle, query safety
- `rules/common/security.md` — secrets, input validation

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [drvoss](https://github.com/drvoss)
- **Source:** [drvoss/everything-copilot-cli](https://github.com/drvoss/everything-copilot-cli)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** yes
- **Dynamic code execution:** yes

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-drvoss-everything-copilot-cli-nestjs-prisma
- Seller: https://agentstack.voostack.com/s/drvoss
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
