npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vanviolet/prisma-produce

v1.0.0

Published

A powerful CLI tool to generate DTOs, Entities, Interfaces, and Classes from Prisma schema

Downloads

15

Readme

Prisma Produce

🇬🇧 English | 🇮🇩 Bahasa Indonesia | 🇯🇵 日本語

npm version License: MIT


🇬🇧 English

🚀 Features

  • Multiple Output Formats: Generate DTOs, Entities, Interfaces, or Plain Classes
  • Full Decorator Support: Automatic class-validator and class-transformer decorators
  • Swagger Integration: ApiProperty decorators for @nestjs/swagger
  • Interactive Mode: User-friendly CLI with prompts
  • Watch Mode: Auto-regenerate on schema changes
  • Flexible Configuration: Config file or CLI options
  • Split Mode: Generate one file per model or single file
  • Namespace Support: Wrap classes in namespaces
  • Custom Decorators: Add your own field decorators
  • TypeScript First: Full type safety and IntelliSense support

📦 Installation

npm install -g @vanviolet/prisma-produce

Or use in your project:

npm install --save-dev @vanviolet/prisma-produce

🎯 Quick Start

Interactive Mode

Simply run:

prisma-produce

The CLI will guide you through the configuration.

Initialize Config File

prisma-produce init

This creates prisma-produce.config.json in your project root.

Generate with Config

prisma-produce generate

Generate with CLI Options

prisma-produce generate --schema=prisma/schema.prisma --output=src/dto/database.dto.ts

📖 Usage

Commands

generate (default)

Generate DTOs from your Prisma schema.

prisma-produce generate [options]

Options:

  • --schema <path> - Path to Prisma schema file (default: prisma/schema.prisma)
  • --output <path> - Output file path (default: app/common/interface/database.dto.ts)
  • --output-dir <path> - Output directory (for split mode)
  • --format <type> - Output format: dto|entity|interface|class (default: dto)
  • --prefix <string> - Class name prefix (e.g., BaseBaseUserDTO)
  • --suffix <string> - Class name suffix (default: DTO)
  • --namespace <string> - Wrap classes in namespace (e.g., Database.DTO)
  • --models <list> - Include only specific models (comma-separated)
  • --exclude <list> - Exclude specific models (comma-separated)
  • --relations <mode> - Relations mode: none|simple|full (default: none)
  • --relations-depth <n> - Max depth for relations (default: 1)
  • --split-by-model - Generate one file per model
  • -w, --watch - Watch mode (auto-regenerate on changes)
  • --config <path> - Path to config file (default: prisma-produce.config.json)

init

Initialize configuration file.

prisma-produce init

🔧 Configuration

Config File (prisma-produce.config.json)

{
  "schemaPath": "prisma/schema.prisma",
  "outputPath": "src/dto/database.dto.ts",
  "prefix": "",
  "suffix": "DTO",
  "namespace": "",
  "format": "dto",
  "models": [],
  "exclude": [],
  "relations": "none",
  "relationsDepth": 1,
  "splitByModel": false,
  "watch": false,
  "customDecorators": {
    "email": [
      "@Transform(({ value }) => value.toLowerCase())",
      "@Trim()"
    ]
  }
}

📋 Examples

Basic DTO Generation

prisma-produce generate --schema=prisma/schema.prisma --output=src/dto.ts

Input (schema.prisma):

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  role      Role     @default(USER)
  createdAt DateTime @default(now())
}

enum Role {
  USER
  ADMIN
}

Output (src/dto.ts):

import { IsArray, IsEnum, IsNotEmpty, IsOptional, IsString, IsNumber, IsDate } from 'class-validator';
import { Expose, Transform, Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';
import { Role } from '@prisma/client';

export class UserDTO {
  @Expose()
  @ApiProperty({ type: Number })
  @IsNotEmpty()
  @IsNumber()
  id: number;

  @Expose()
  @ApiProperty({ type: String })
  @IsNotEmpty()
  @IsString()
  email: string;

  @Expose()
  @ApiProperty({ type: String, required: false, nullable: true })
  @IsOptional()
  @IsString()
  name?: string | null;

  @Expose()
  @ApiProperty({ enum: Role, enumName: 'Role' })
  @IsNotEmpty()
  @IsEnum(Role)
  role: Role;

  @Expose()
  @ApiProperty({ type: Date })
  @IsNotEmpty()
  @IsDate()
  @Type(() => Date)
  @Transform(({ value }) => {
    if (typeof value === 'string' || typeof value === 'number') {
      return new Date(value);
    }
    return value;
  })
  createdAt: Date;
}

Generate with Prefix and Namespace

prisma-produce generate --prefix=Base --namespace=Database.Models
export namespace Database {
  export namespace Models {
    export class BaseUserDTO {
      // ...
    }
  }
}

Generate Only Specific Models

prisma-produce generate --models=User,Post,Comment

Exclude Models

prisma-produce generate --exclude=AuditLog,SystemConfig

Split by Model

prisma-produce generate --split-by-model --output-dir=src/dto

Generates:

  • src/dto/user.dto.ts
  • src/dto/post.dto.ts
  • src/dto/comment.dto.ts
  • src/dto/index.ts (exports all)

Watch Mode

prisma-produce generate --watch

Entity Format

prisma-produce generate --format=entity --suffix=Entity --output=src/entities.ts

Generates entities without @ApiProperty decorators.

Interface Format

prisma-produce generate --format=interface --suffix="" --output=src/interfaces.ts

Generates plain TypeScript interfaces.

Plain Class Format

prisma-produce generate --format=class --suffix="" --output=src/models.ts

Generates plain classes with constructors.

🎨 Output Formats

1. DTO (Default)

  • Full class-validator decorators
  • Full class-transformer decorators
  • ApiProperty decorators
  • Best for NestJS APIs

2. Entity

  • class-validator decorators
  • class-transformer decorators
  • No ApiProperty decorators
  • Best for database entities

3. Interface

  • Plain TypeScript interfaces
  • No decorators
  • Best for type definitions

4. Class

  • Plain classes with constructors
  • No decorators
  • Best for models/domain objects

🛠️ Custom Decorators

Add custom decorators in genprisma.config.json:

{
  "customDecorators": {
    "email": [
      "@Transform(({ value }) => value.toLowerCase())",
      "@IsEmail()"
    ],
    "phone": [
      "@Transform(({ value }) => value.replace(/\\D/g, ''))"
    ]
  }
}

📦 NPM Scripts

Add to your package.json:

{
  "scripts": {
    "generate:dto": "prisma-produce generate",
    "generate:dto:watch": "prisma-produce generate --watch",
    "generate:dto:init": "prisma-produce init"
  }
}

🔄 Integration with Prisma

Automatically regenerate DTOs after Prisma migrations:

{
  "scripts": {
    "prisma:migrate": "prisma migrate dev && npm run generate:dto"
  }
}

📝 Required Dependencies

The CLI will check if these dependencies are installed in your project and prompt to install them if missing:

Dependencies:

  • class-validator - For validation decorators (DTO/Entity format)
  • class-transformer - For transformation decorators (DTO/Entity format)
  • @nestjs/swagger - For ApiProperty decorators (DTO format only)

Note: The CLI itself includes @prisma/internals and chokidar, so you don't need to install them in your project.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT © vanviolet

🐛 Issues

Report issues at GitHub Issues

📚 Documentation

For more information, visit GitHub Repository

🌟 Show Your Support

If this project helps you, please give it a ⭐️!


Made with ❤️ by vanviolet


Other languages: 🇮🇩 Bahasa Indonesia | 🇯🇵 日本語