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

prisma-backgen

v1.1.0

Published

Generate a complete, production-ready Express.js REST API backend from a Prisma schema file

Readme

Backgen

Generate a production-ready REST API backend from a Prisma schema and /// @bcm.* directives.

npm CI Playground CI License: MIT Node.js >= 18

Backgen turns a Prisma schema into a structured Express or Fastify codebase with controllers, services, repositories, DTOs, route tests, repository unit tests, OpenAPI output, Postman collection export, background job scaffolding (BullMQ or pg-boss), real-time WebSocket support, and deployable infra files.

Why Backgen

  • Generates CRUD modules from Prisma models, including selector-aware item routes for @id, @@id, @unique, and @@unique.
  • Uses schema directives to control auth, RBAC, soft delete, caching, uploads, searchable fields, and nested relation inputs.
  • Produces route tests and repository unit tests that mock Prisma delegates, so generated pnpm test does not require a database.
  • Exports a Postman Collection v2.1 JSON importable by Postman, Insomnia, Thunder Client, or Bruno.
  • Ships a CLI-backed playground package that uses the same generation pipeline as the published CLI.

Quick Start

pnpm add -g prisma-backgen

bcm init my-api
cd my-api

# edit prisma/schema.prisma
bcm validate --schema ./prisma/schema.prisma
bcm generate --schema ./prisma/schema.prisma --output . --force

pnpm install
cp .env.example .env
pnpm exec prisma migrate dev --name init
pnpm dev

Use --framework fastify to target Fastify instead of the default Express output. Add --jobs bullmq or --jobs pg-boss for background job scaffolding. Add --ws for real-time WebSocket support (models with @bcm.ws broadcast mutations to subscribers).

Canonical Example Schema

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

enum Role {
  USER
  ADMIN
}

/// @bcm.authModel
model User {
  id        String   @id @default(cuid())
  /// @bcm.identifier
  email     String   @unique
  /// @bcm.password
  password  String
  role      Role     @default(USER)
  posts     Post[]
  /// @bcm.readonly
  createdAt DateTime @default(now())
}

/// @bcm.protected
/// @bcm.softDelete
/// @bcm.cache(ttl: 300)
model Post {
  id        String    @id @default(cuid())
  /// @bcm.searchable
  title     String
  content   String?
  /// @bcm.hidden
  authorId  String
  /// @bcm.nested
  author    User      @relation(fields: [authorId], references: [id])
  deletedAt DateTime?
  /// @bcm.readonly
  createdAt DateTime  @default(now())
}

Generated API Snapshot

For the schema above, Backgen emits routes under /api/v1 plus shared service endpoints:

  • GET /api/v1/posts
  • POST /api/v1/posts
  • GET /api/v1/posts/{id}
  • PUT /api/v1/posts/{id}
  • PATCH /api/v1/posts/{id}
  • DELETE /api/v1/posts/{id}
  • POST /api/v1/auth/login
  • POST /api/v1/auth/refresh
  • POST /api/v1/auth/logout
  • GET /health
  • Swagger UI at /api/docs

Generated auth uses access tokens plus refresh-token rotation when an @bcm.authModel is present. ACCESS_TOKEN_TTL defaults to 15m, and Redis is required for auth sessions, @bcm.cache, and --jobs bullmq.

Output Snapshot

src/
  app.ts
  server.ts
  config/
  middlewares/
  modules/
    auth/
    user/
    post/
  jobs/          # when --jobs is used
  ws/            # when --ws is used
  utils/
prisma/
  seed.ts
openapi.json
postman-collection.json
Dockerfile
docker-compose.yml
.env.example
README.md
package.json

Documentation

CLI command index: bcm init, bcm generate, bcm add, bcm diff, bcm validate, bcm eject (see Usage Guide for full flags and JSON contracts).

Playground

The local playground is a separate package that shells out to the real CLI in --dry-run --json mode.

pnpm install --frozen-lockfile
pnpm run build
cd packages/playground
pnpm install --frozen-lockfile
pnpm dev

It serves the monolithic playground at http://localhost:4173.

License

MIT