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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tgraph/backend-generator

v0.0.3

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 – End-to-end TypeScript types from database to frontend (including Swagger-generated API clients)
  • Smart Introspection – Automatically discovers your project structure
  • Unique Field Getters – Auto-generated methods for fields marked with @unique in Prisma
  • Relation Support – Configurable relation includes in service selects
  • Static Infrastructure – Generate guards, interceptors, decorators, and utilities
  • Field Directives – Fine-grained control with @tg_format, @tg_upload, @tg_readonly
  • Safe Regeneration – Preserves your custom code, regenerates boilerplate
  • 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 + admin dashboard in seconds.

What Gets Generated

Backend (NestJS)

  • ✅ REST controllers with pagination and search
  • ✅ Services with CRUD operations and unique field getters
  • ✅ DTOs with class-validator decorators (including array validators)
  • ✅ Automatic AppModule updates
  • ✅ Static infrastructure files (guards, interceptors, decorators)
  • ✅ Configurable relation includes in queries

Frontend (React Admin)

  • ✅ List/Edit/Create/Show pages
  • ✅ Studio pages (spreadsheet-like editing)
  • ✅ Type-appropriate inputs (date pickers, file uploads, etc.)
  • ✅ Relation handling with autocomplete
  • ✅ 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 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
tgraph preflight

# Generate only API
tgraph api

# Generate only dashboard
tgraph dashboard

# With options
tgraph all --suffix Admin --no-update-data-provider

# 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, for dashboard generation)

Documentation

📚 Complete Documentation

Getting Started

Guides

Advanced

Configuration

Initialize a configuration file in your project:

npx tgraph init

This creates tgraph.config.ts in your project root with default values:

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

export const config: Config = {
  input: {
    schemaPath: 'prisma/schema.prisma',
  },

  output: {
    backend: {
      dtos: 'src/dtos/generated',
      modules: {
        searchPaths: ['src/features', 'src/modules', 'src'],
        defaultRoot: 'src/features',
      },
      staticFiles: {
        guards: 'src/guards',
        decorators: 'src/decorators',
        dtos: 'src/dtos',
        interceptors: 'src/interceptors',
      },
    },
    dashboard: {
      root: 'src/dashboard/src',
      resources: 'src/dashboard/src/resources',
      swagger: {
        command: 'npm run generate:swagger',
        jsonPath: 'src/dashboard/src/types/swagger.json',
      },
    },
  },

  api: {
    suffix: 'Admin',
    prefix: 'tg-api',
    authentication: {
      enabled: true,
      requireAdmin: true,
      guards: [{ name: 'JwtAuthGuard', importPath: '@/guards/jwt-auth.guard' }],
      adminGuards: [{ name: 'AdminGuard', importPath: '@/guards/admin.guard' }],
    },
    relations: {
      include: [], // or 'all' or ['author', 'comments']
    },
  },

  dashboard: {
    enabled: true,
    updateDataProvider: true,
    components: {
      form: {}, // Override React Admin form components
      display: {}, // Override React Admin display components
    },
  },

  behavior: {
    nonInteractive: false,
  },
};

The new structured configuration makes it easy to:

  • Generate multiple APIs with different configs (--config tgraph.admin.config.ts)
  • Customize component imports for consistent UI
  • Configure authentication guards per API
  • Control where files are generated

Customize the values for your project, or use the --config flag to use different configurations.

Public vs Admin Controllers

  • Set api.authentication.enabled = false or leave guards empty to generate public controllers without @UseGuards.
  • Set api.authentication.requireAdmin = true to add @IsAdmin() to controllers.

Route Prefix

  • api.prefix controls controller base route (e.g., tg-api, public-api). This replaces previous hardcoded defaults.

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 <dashboardRoot>/types/swagger.json and generates api.ts. Ensure swagger.json is up to date before running.

Programmatic Usage

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

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

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

See SDK Reference for complete API documentation.

Project Structure

your-project/
├── prisma/
│   └── schema.prisma          # Source of truth
├── src/
│   ├── app.module.ts          # Auto-updated
│   ├── features/
│   │   └── user/
│   │       ├── user.tg.controller.ts   # Generated
│   │       ├── user.tg.service.ts      # Generated
│   │       ├── create-user.tg.dto.ts   # Generated
│   │       └── user.service.ts         # Your custom code
│   └── dashboard/src/
│       ├── App.tsx            # Auto-updated
│       └── resources/
│           └── users/
│               ├── UserList.tsx        # Generated
│               ├── UserEdit.tsx        # Generated
│               └── ...

Field Directives

Control generation with special comments:

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

  /// @tg_upload(image)
  avatar String?

  /// @tg_readonly
  ipAddress String?
}

See Field Directives Guide for all directives.

Philosophy

TGraph Backend Generator follows these principles:

  • Convention over Configuration – Works out of the box
  • Generate, Don't Replace – Coexist with custom code
  • Progressive Disclosure – Start simple, add complexity as needed
  • Type Safety First – Compile-time error checking

Read more in Philosophy & Principles.

Contributing

Contributions are welcome! See Contributing Guide.

Publishing

For maintainers: See Publishing Guide for release process.

License

ISC

Links


Made with ❤️ by the TruGraph team