prisma-model-cli
v1.2.51
Published
Generate service/controller/routes for Prisma models
Downloads
7
Maintainers
Readme
📦 PrismaGen CLI
PrismaGen is a flexible CLI tool that auto-generates a scalable API structure from your schema.prisma file.
Supports:
- ✅ NestJS (TypeScript)
- REST API
- GraphQL API
- ✅ Express (TypeScript or JavaScript)
- ✅ GraphQL (TypeScript or JavaScript)
- ✅ TypeScript API Client via Swagger/OpenAPI
🚀 Installation
npm install -g prisma-model-cliinstall locally:
npm install prisma-model-cli🔧 Usage
prismagenYou can also use flags to skip the interactive dialog:
▶️ CLI Options
NestJS Options
| Command | Description |
| ----------------------------------------- | ---------------------------------------------------------- |
| prismagen --nestjs | Generate NestJS REST API structure (TypeScript) |
| prismagen --nestjs --no-swagger | Generate NestJS REST API without Swagger setup |
| prismagen --nestjs --graphql | Generate NestJS GraphQL API structure (TypeScript) |
| prismagen --nestjs --graphql --no-swagger | Generate NestJS GraphQL API without Swagger setup |
Express Options
| Command | Description |
| --------------------------------- | ---------------------------------------------------------- |
| prismagen --express | Generate Express API structure (TypeScript) |
| prismagen --express --output-js | Generate Express API structure (JavaScript) |
GraphQL Options
| Command | Description |
| --------------------------------- | ---------------------------------------------------------- |
| prismagen --graphql | Generate GraphQL API structure (TypeScript) |
| prismagen --graphql --output-js | Generate GraphQL API structure (JavaScript) |
Swagger/OpenAPI Options
| Command | Description |
| --------------------------------- | ---------------------------------------------------------- |
| prismagen generate swagger | Generate NestJS REST + Swagger UI TypeScript client |
| prismagen generate swagger --graphql | Generate NestJS GraphQL + Swagger UI TypeScript client |
General Options
| Command | Description |
| --------------------------------- | ---------------------------------------------------------- |
| prismagen --help or -h | Show CLI help |
| prismagen --version or -v | Show installed version |
📁 Output Structure
NestJS REST API Structure
models/
└── user/
├── user.controller.ts
├── user.service.ts
├── dto/
│ ├── create-user.dto.ts
│ └── update-user.dto.tsNestJS GraphQL API Structure
models/
└── user/
├── user.resolver.ts
├── user.service.ts
├── dto/
│ ├── create-user.input.ts
│ └── update-user.input.ts
└── user.types.tsExpress API Structure
models/
└── user/
├── user.controller.ts
├── user.service.ts
└── routes/
└── user.routes.tsGraphQL API Structure
models/
└── user/
├── user.resolver.ts
├── user.service.ts
├── user.types.ts
└── user.inputs.ts🧬 Generate Swagger TypeScript Client
To generate a TypeScript SDK using openapi-generator-cli from your running NestJS Swagger endpoint:
prismagen generate swaggerFor GraphQL API:
prismagen generate swagger --graphqlYou'll be prompted to:
- Enter the Swagger JSON URL (defaults to
http://localhost:3000/api-json) - Choose the output directory (defaults to
../client/src/app/api)
The CLI will:
- Run NestJS model generation via
run.ts - Validate the Swagger endpoint is reachable
- Generate a TypeScript Axios client via OpenAPI Generator
⚙️ Prerequisites
Ensure your project has:
Prisma installed and set up:
npm install prisma @prisma/client npx prisma initA valid
schema.prismain/prisma/schema.prisma
Run:
npx prisma generate🧠 How It Works
- Parses all models from your Prisma schema.
- Generates base CRUD logic (
BaseController,GenericPrismaService). - Outputs language-specific files based on the selected mode.
- Optionally, generates a Swagger client using
openapi-generator-cli.
🛠 Dev Setup (if modifying CLI)
Clone this repo
Build the CLI:
npm install npm run buildLink it globally to use
prismagenfrom anywhere:npm link
🧩 Future Features
- Support for custom middleware
- Soft deletes
- Swagger docs out of the box
- Authentication scaffolding (JWT, session-based)
📬 Issues / Contributions
Open issues or PRs on GitHub
We welcome contributions!
