PluginBench
Skill
Review
Audit score 70

nestjs

giuseppe-trisciuoglio/developer-kit

NestJS framework patterns with Drizzle ORM for building scalable REST/GraphQL APIs and microservices.

What is nestjs?

Provides comprehensive NestJS patterns integrated with Drizzle ORM for production-ready server-side applications. Covers CRUD modules, JWT authentication, database operations, migrations, testing, and microservices. Use when building NestJS APIs, implementing authentication, working with databases, or setting up microservices.

  • Generate REST and GraphQL API endpoints with NestJS controllers and services
  • Implement JWT authentication guards and role-based authorization
  • Create and manage database schemas with Drizzle ORM table definitions
  • Build CRUD modules using Repository pattern with dependency injection
  • Write unit and integration tests with mocked repositories
  • Execute database transactions for multi-table operations

How to install nestjs

npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill nestjs
Prerequisites
  • Node.js and npm installed
  • NestJS project initialized (npx @nestjs/cli new project-name)
  • PostgreSQL database or compatible SQL database
  • npm packages: drizzle-orm, pg, drizzle-kit, @nestjs/jwt, class-validator
Claude Code
Cursor
Windsurf
Cline

How to use nestjs

  1. 1.Install dependencies: npm i drizzle-orm pg && npm i -D drizzle-kit tsx
  2. 2.Define database schema in src/db/schema.ts using Drizzle pgTable definitions
  3. 3.Create DatabaseService to inject Drizzle client as a NestJS provider
  4. 4.Build CRUD modules following Controller → Service → Repository pattern
  5. 5.Add input validation using class-validator DTOs with ValidationPipe
  6. 6.Implement JWT authentication guards and role-based access control guards
  7. 7.Write unit tests using @nestjs/testing with mocked repositories
  8. 8.Run migrations: npx drizzle-kit generate, verify SQL, then npx drizzle-kit migrate

Use cases

Good for
  • Building a REST API with user authentication and role-based access control
  • Creating a GraphQL server with Drizzle ORM database integration
  • Implementing database migrations and schema management with drizzle-kit
  • Setting up microservices that communicate via TCP or Redis
  • Writing comprehensive unit tests for services and controllers with mocked dependencies
Who it's for
  • Backend developers building NestJS applications
  • Full-stack engineers implementing authentication and authorization
  • DevOps/platform engineers setting up microservices
  • QA engineers writing integration tests
  • Database architects designing Drizzle ORM schemas

nestjs FAQ

What database systems does this support?

Drizzle ORM supports PostgreSQL, MySQL, and SQLite. The skill examples use PostgreSQL (pgTable), but patterns apply to other databases.

How do I handle authentication in NestJS?

Implement a JwtAuthGuard that extracts and verifies JWT tokens from request headers, then attach the decoded user to the request context for use in controllers.

Should I use transactions for all database operations?

No, use transactions only for multi-table operations that must succeed or fail together (e.g., fund transfers). Single-table operations don't need transactions.

What's the recommended project structure?

Organize by feature modules (users, products, etc.), each with controller, service, repository, DTO, and entity files. Keep database schema in src/db/schema.ts.

How do I avoid circular dependencies?

Prefer restructuring modules to eliminate circular imports. Use forwardRef() only as a last resort, and consider extracting shared logic into separate modules.

Full instructions (SKILL.md)

Source of truth, from giuseppe-trisciuoglio/developer-kit.


name: nestjs description: Provides comprehensive NestJS framework patterns with Drizzle ORM integration for building scalable server-side applications. Generates REST/GraphQL APIs, implements authentication guards, creates database schemas, and sets up microservices. Use when building NestJS applications, setting up APIs, implementing authentication, working with databases, or integrating Drizzle ORM. allowed-tools: Read, Write, Edit, Glob, Grep, Bash

NestJS Framework with Drizzle ORM

Overview

Provides NestJS patterns with Drizzle ORM for building production-ready server-side applications. Covers CRUD modules, JWT authentication, database operations, migrations, testing, microservices, and GraphQL integration.

When to Use

  • Building REST APIs or GraphQL servers with NestJS
  • Setting up authentication and authorization with JWT
  • Implementing database operations with Drizzle ORM
  • Creating microservices with TCP/Redis transport
  • Writing unit and integration tests
  • Running database migrations with drizzle-kit

Instructions

  1. Install dependencies: npm i drizzle-orm pg && npm i -D drizzle-kit tsx
  2. Define schema: Create src/db/schema.ts with Drizzle table definitions
  3. Create DatabaseService: Inject Drizzle client as a NestJS provider
  4. Build CRUD module: Controller → Service → Repository pattern
  5. Add validation: Use class-validator DTOs with ValidationPipe
  6. Implement guards: Create JWT/Roles guards for route protection
  7. Write tests: Use @nestjs/testing with mocked repositories
  8. Run migrations: npx drizzle-kit generateVerify SQLnpx drizzle-kit migrate

Examples

Complete CRUD Module with Drizzle

// src/db/schema.ts
export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
  email: text('email').notNull().unique(),
  createdAt: timestamp('created_at').defaultNow(),
});

// src/users/dto/create-user.dto.ts
export class CreateUserDto {
  @IsString() @IsNotEmpty() name: string;
  @IsEmail() email: string;
}

// src/users/user.repository.ts
@Injectable()
export class UserRepository {
  constructor(private db: DatabaseService) {}

  async findAll() {
    return this.db.database.select().from(users);
  }

  async create(data: typeof users.$inferInsert) {
    return this.db.database.insert(users).values(data).returning();
  }
}

// src/users/users.service.ts
@Injectable()
export class UsersService {
  constructor(private repo: UserRepository) {}

  async create(dto: CreateUserDto) {
    return this.repo.create(dto);
  }
}

// src/users/users.controller.ts
@Controller('users')
export class UsersController {
  constructor(private service: UsersService) {}

  @Post()
  create(@Body() dto: CreateUserDto) {
    return this.service.create(dto);
  }
}

// src/users/users.module.ts
@Module({
  controllers: [UsersController],
  providers: [UsersService, UserRepository, DatabaseService],
  exports: [UsersService],
})
export class UsersModule {}

JWT Authentication Guard

@Injectable()
export class JwtAuthGuard implements CanActivate {
  constructor(private jwtService: JwtService) {}

  canActivate(context: ExecutionContext) {
    const token = context.switchToHttp().getRequest()
      .headers.authorization?.split(' ')[1];
    if (!token) return false;
    try {
      const decoded = this.jwtService.verify(token);
      context.switchToHttp().getRequest().user = decoded;
      return true;
    } catch {
      return false;
    }
  }
}

Database Transactions

async transferFunds(fromId: number, toId: number, amount: number) {
  return this.db.database.transaction(async (tx) => {
    await tx.update(accounts)
      .set({ balance: sql`${accounts.balance} - ${amount}` })
      .where(eq(accounts.id, fromId));
    await tx.update(accounts)
      .set({ balance: sql`${accounts.balance} + ${amount}` })
      .where(eq(accounts.id, toId));
  });
}

Unit Testing with Mocks

describe('UsersService', () => {
  let service: UsersService;
  let repo: jest.Mocked<UserRepository>;

  beforeEach(async () => {
    const module = await Test.createTestingModule({
      providers: [
        UsersService,
        { provide: UserRepository, useValue: { findAll: jest.fn(), create: jest.fn() } },
      ],
    }).compile();
    service = module.get(UsersService);
    repo = module.get(UserRepository);
  });

  it('should create user', async () => {
    const dto = { name: 'John', email: 'john@example.com' };
    repo.create.mockResolvedValue({ id: 1, ...dto, createdAt: new Date() });
    expect(await service.create(dto)).toMatchObject(dto);
  });
});

Constraints and Warnings

  • DTOs required: Always use DTOs with class-validator, never accept raw objects
  • Transactions: Keep transactions short; avoid nested transactions
  • Guards order: JWT guard must run before Roles guard
  • Environment variables: Never hardcode DATABASE_URL or JWT_SECRET
  • Migrations: Run drizzle-kit generate after schema changes before deploying
  • Circular dependencies: Use forwardRef() carefully; prefer module restructuring

Best Practices

  • Validate all inputs with global ValidationPipe
  • Use transactions for multi-table operations
  • Document APIs with OpenAPI/Swagger decorators

References

Advanced patterns and detailed examples available in:

  • references/reference.md - Core patterns, guards, interceptors, microservices, GraphQL
  • references/drizzle-reference.md - Drizzle ORM installation, configuration, queries
  • references/workflow-optimization.md - Development workflows, parallel execution strategies

Related skills

More from giuseppe-trisciuoglio/developer-kit and the wider catalog.

NEnestjs-best-practices logo

nestjs-best-practices

giuseppe-trisciuoglio/developer-kit

Provides comprehensive NestJS best practices including modular architecture, dependency injection scoping, exception filters, DTO validation with class-validator, and Drizzle ORM integration. Use when designing NestJS modules, implementing providers, creating exception filters, validating DTOs, or integrating Drizzle ORM within NestJS applications.

1.2k installsAudited
NEnestjs-code-review logo

nestjs-code-review

giuseppe-trisciuoglio/developer-kit

Provides comprehensive code review capability for NestJS applications, analyzing controllers, services, modules, guards, interceptors, pipes, dependency injection, and database integration patterns. Use when reviewing NestJS code changes, before merging pull requests, after implementing new features, or for architecture validation. Triggers on "review NestJS code", "NestJS code review", "check my NestJS controller/service".

1.2k installsAudited
NEnestjs-drizzle-crud-generator logo

nestjs-drizzle-crud-generator

giuseppe-trisciuoglio/developer-kit

Generates complete CRUD modules for NestJS applications with Drizzle ORM. Use when building server-side features in NestJS that require database operations, including creating new entities with full CRUD endpoints, services with Drizzle queries, Zod-validated DTOs, and unit tests. Triggered by requests like "generate a user module", "create a product CRUD", "add a new entity with endpoints", or when setting up database-backed features in NestJS.

1.2k installs
NEnextjs-app-router logo

nextjs-app-router

giuseppe-trisciuoglio/developer-kit

Patterns and code examples for Next.js 16+ App Router architecture with Server Components, Server Actions, and caching.

1.3k installs
NEnextjs-authentication logo

nextjs-authentication

giuseppe-trisciuoglio/developer-kit

Provides authentication implementation patterns for Next.js 15+ App Router using Auth.js 5 (NextAuth.js). Use when setting up authentication flows, implementing protected routes, managing sessions in Server Components and Server Actions, configuring OAuth providers, implementing role-based access control, or handling sign-in/sign-out flows in Next.js applications.

1.3k installs
NEnextjs-code-review logo

nextjs-code-review

giuseppe-trisciuoglio/developer-kit

Provides comprehensive code review capability for Next.js applications, validates Server Components, Client Components, Server Actions, caching strategies, metadata, API routes, middleware, and performance patterns. Use when reviewing Next.js App Router code changes, before merging pull requests, after implementing new features, or for architecture validation. Triggers on "review Next.js code", "Next.js code review", "check my Next.js app".

1.2k installsAudited