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

@tgraph/backend-generator

v0.1.1

Published

CLI toolkit for generating NestJS APIs, DTOs, and React Admin dashboards from Prisma schemas.

Readme

TGraph Backend Generator

Transform your Prisma schema into production-ready NestJS APIs and React Admin dashboards with a single command.

npm version License: ISC

Features

  • Full-Stack Generation: Generate NestJS controllers, services, DTOs, and React Admin pages from Prisma schemas
  • Type Safety: Carry TypeScript types from database to frontend, including Swagger-based API clients
  • Smart Introspection: Automatically discovers your project structure and preserves custom code
  • Unique Field Getters: Auto-generated getters for every Prisma @unique field
  • Relation Support: React Admin resources and DTOs understand Prisma relations out of the box
  • Static Infrastructure: Generate guards, interceptors, decorators, and utilities
  • Field Directives: Fine-grained control with @tg_format, @tg_upload, and @tg_readonly
  • Safe Regeneration: Generated files live beside your code and can be overwritten safely
  • Convention Over Configuration: Works out of the box with sensible defaults
  • Interactive Wizard: Guided setup with tgraph init

Quick Start

# Install
npm install --save-dev @tgraph/backend-generator

# Initialize configuration
npx tgraph init

# Mark your Prisma models
// @tg_form()
model User {
  id        String   @id @default(uuid())
  name      String
  email     String   @unique
  createdAt DateTime @default(now())
}

# Generate everything
npx tgraph all

Result: Complete CRUD API plus an admin dashboard in seconds.

What Gets Generated

Backend (NestJS)

  • REST controllers with pagination and search
  • Services with CRUD operations, unique field getters, and Prisma integration
  • DTOs with class-validator decorators (including arrays and enums)
  • Automatic AppModule updates
  • Optional static modules (guards, DTOs, interceptors, utilities)

Frontend (React Admin)

  • List/Edit/Create/Show pages for every model
  • Studio pages for spreadsheet-style editing
  • Type-appropriate inputs (dates, uploads, references, JSON)
  • Relation handling with autocomplete widgets
  • Type-safe API client generated from Swagger

Example

Input (Prisma):

// @tg_form()
model Post {
  id        String   @id @default(uuid())
  title     String   // @min(5) @max(200)
  content   String
  published Boolean  @default(false)
  author    User     @relation(fields: [authorId], references: [id])
  authorId  String
  createdAt DateTime @default(now())
}

Output: Instant admin system with a working API and dashboard.

Installation

# Project dependency (recommended)
npm install --save-dev @tgraph/backend-generator

# Global installation
npm install -g @tgraph/backend-generator

Usage

# Generate everything
tgraph all

# Preview pending changes without writing files
tgraph preflight

# Generate only API files
tgraph api

# Generate only dashboard resources
tgraph dashboard

# Generate only DTOs
tgraph dtos

# With options
tgraph all --config tgraph.admin.config.ts --non-interactive

# List available static modules
tgraph static --list

# Generate selected static modules
tgraph static --include admin.guard,pagination.interceptor

# Generate dashboard API types from swagger.json
tgraph types

Requirements

  • Node.js 18.0.0 or newer
  • NestJS project with Prisma
  • React Admin dashboard (optional, only required for dashboard generation)

Documentation

Getting Started

Guides

Advanced

AI Integration

Configuration

Initialize a configuration file in your project:

npx tgraph init

This creates tgraph.config.ts with typed defaults:

import type { Config } from '@tgraph/backend-generator';

export const config: Config = {
  input: {
    prisma: {
      schemaPath: 'prisma/schema.prisma',
      servicePath: 'src/infrastructure/database/prisma.service.ts',
    },
    dashboard: {
      components: { form: {}, display: {} },
    },
  },
  output: {
    backend: {
      root: 'src/features',
      dtosPath: 'src/dtos/generated',
      modulesPaths: ['src/features', 'src/modules', 'src'],
      guardsPath: 'src/guards',
      decoratorsPath: 'src/decorators',
      interceptorsPath: 'src/interceptors',
      utilsPath: 'src/utils',
      appModulePath: 'src/app.module.ts',
    },
    dashboard: {
      enabled: true,
      updateDataProvider: true,
      root: 'src/dashboard/src',
      resourcesPath: 'src/dashboard/src/resources',
      swaggerJsonPath: 'src/dashboard/src/types/swagger.json',
      apiPath: 'src/dashboard/src/types/api.ts',
      appComponentPath: 'src/dashboard/src/App.tsx',
      dataProviderPath: 'src/dashboard/src/providers/dataProvider.ts',
    },
  },
  api: {
    suffix: '',
    prefix: 'tg-api',
    authenticationEnabled: true,
    requireAdmin: true,
    guards: [{ name: 'JwtAuthGuard', importPath: '@/guards/jwt-auth.guard' }],
    adminGuards: [{ name: 'AdminGuard', importPath: '@/guards/admin.guard' }],
  },
  behavior: {
    nonInteractive: false,
  },
};

The structured configuration makes it easy to run multiple variants (--config tgraph.public.config.ts), customize component imports, and control every output path.

Public vs Admin Controllers

  • Set api.authenticationEnabled = false (or pass --public) to generate public controllers without guards.
  • Set api.requireAdmin = true to add the @IsAdmin() decorator and admin guards.

Route Prefix

api.prefix controls the base route for generated controllers (for example tg-api, public-api). Use different prefixes per config file.

Static Assets Generation

  • During tgraph api, you'll be prompted to generate static files. Use --yes for non-interactive generation or tgraph static --include <names> for a targeted run.
  • Available names include: admin.guard, feature-flag.guard, is-admin.decorator, paginated-search-query.dto, paginated-search-result.dto, api-response.dto, pagination.interceptor, audit.interceptor, paginated-search.decorator, paginated-search.util.

Dashboard API Types

tgraph types reads the file defined by output.dashboard.swaggerJsonPath (default src/dashboard/src/types/swagger.json) and generates the client at output.dashboard.apiPath. Ensure swagger.json is fresh before running.

Programmatic Usage

import { ApiGenerator, DashboardGenerator, DtoGenerator } from '@tgraph/backend-generator';
import { config } from './tgraph.config';

const api = new ApiGenerator(config);
await api.generate();

const dashboard = new DashboardGenerator(config);
await dashboard.generate();

const dtos = new DtoGenerator(config);
await dtos.generate();

See the SDK Reference for every method and option.

Project Structure

your-project/
|- prisma/
|  |- schema.prisma
|
|- src/
|  |- app.module.ts
|  |- features/
|     |- user/
|        |- user.tg.controller.ts   # Generated
|        |- user.tg.service.ts      # Generated
|        |- create-user.tg.dto.ts   # Generated
|        |- user.service.ts         # Your custom logic
|
|- dashboard/src/
   |- App.tsx
   |- resources/
      |- users/
         |- UserList.tsx           # Generated
         |- UserEdit.tsx           # Generated
         |- ...

Field Directives

Control generation directly from your Prisma schema:

model User {
  /// @tg_format(email)
  email String @unique

  /// @tg_upload(image)
  avatar String?

  /// @tg_readonly
  ipAddress String?
}

See the Field Directives Guide for every directive.

Philosophy

  • Convention over Configuration: Works out of the box
  • Generate, Don't Replace: Generated files live beside your code
  • Progressive Disclosure: Start simple, add complexity when needed
  • Type Safety First: Catch errors at compile time

Contributing

Contributions are welcome! See the Contributing Guide.

Publishing

For maintainers: see the Publishing Guide for the release process.

License

ISC

Links


Made with love by the TruGraph team.