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

@hamzatrq/backend-gen

v1.0.0

Published

CLI Generator for Production-Grade NestJS Monoliths

Readme

Backend Generator CLI

A powerful CLI tool for generating production-ready NestJS applications with best practices, security, and scalability built-in.

🚀 Features

  • Production-Ready Setup: Generate complete NestJS applications with all essential configurations
  • Multi-Provider Authentication: Support for JWT, OAuth2 (Google, Microsoft, GitHub), API keys, and OpenID Connect
  • ABAC Authorization: Attribute-Based Access Control with policy engine
  • Security First: Helmet, CORS, CSRF, rate limiting, and optional security features
  • Database Integration: Prisma ORM with PostgreSQL, migrations, and seeding
  • API Documentation: Swagger/OpenAPI v3 with TSDoc comments
  • Testing Pyramid: Unit, integration, and e2e tests with coverage thresholds
  • Docker Support: Multi-stage Dockerfile and docker-compose setup
  • CI/CD Ready: Optional GitHub Actions workflow
  • Monitoring: Health checks, logging with Winston, and optional Sentry integration
  • CRUD Generation: Dynamic CRUD operations from simple entity definitions
  • Optional Services: Email, file storage, caching, notifications, task scheduling, payments, and search

📦 Installation

npm install -g @hamzatrq/backend-gen

🎯 Quick Start

Generate a new project

# Interactive mode
backend-generator init

# Non-interactive mode
backend-generator init --name my-app --api-base /api --api-version v1

Add CRUD operations

# Interactive mode
backend-generator add crud

# With entity name
backend-generator add crud --entity User

# With specification file
backend-generator add crud --spec entities.json

Enable authentication providers

# Interactive mode
backend-generator add auth

# Specific providers
backend-generator add auth --provider google,microsoft,github

Add optional services

# Interactive mode
backend-generator add service

# Specific services
backend-generator add service --service email,cache,storage

Validate project setup

backend-generator doctor

📋 Commands

backend-generator init

Generate a new NestJS project with all configurations.

Options:

  • --name, -n: Project name
  • --api-base, -a: API base path (default: /api)
  • --api-version, -v: API version (default: v1)
  • --skip-install: Skip npm install
  • --skip-git: Skip git initialization

Examples:

backend-generator init
backend-generator init --name my-app --api-base /api/v1
backend-generator init --name my-app --skip-install

backend-generator add crud

Generate CRUD operations for entities using DSL.

Options:

  • --entity, -e: Entity name
  • --spec, -s: Path to entity specification file
  • --skip-tests: Skip test generation

Examples:

backend-generator add crud
backend-generator add crud --entity User
backend-generator add crud --spec entities.json

backend-generator add auth

Enable authentication providers.

Options:

  • --provider, -p: Authentication provider(s) to enable (comma-separated)

Examples:

backend-generator add auth
backend-generator add auth --provider google,microsoft,github

backend-generator add service

Scaffold optional services.

Options:

  • --service, -s: Service(s) to scaffold (comma-separated)

Examples:

backend-generator add service
backend-generator add service --service email,cache,storage

backend-generator doctor

Validate project setup and environment.

Examples:

backend-generator doctor

🏗️ Generated Project Structure

project-root/
├─ src/
│  ├─ app/
│  │  ├─ app.module.ts
│  │  ├─ app.controller.ts
│  │  ├─ app.service.ts
│  │  ├─ main.ts
│  │  ├─ bootstrap/
│  │  │  ├─ versioning.ts
│  │  │  ├─ security.ts
│  │  │  ├─ swagger.ts
│  │  │  └─ logger.ts
│  │  └─ health/
│  │     ├─ health.module.ts
│  │     ├─ health.controller.ts
│  │     └─ health.service.ts
│  │
│  ├─ config/
│  │  ├─ config.module.ts
│  │  ├─ app.config.ts
│  │  ├─ db.config.ts
│  │  ├─ auth.config.ts
│  │  ├─ security.config.ts
│  │  ├─ logging.config.ts
│  │  └─ sentry.config.ts
│  │
│  ├─ core/
│  │  ├─ prisma/
│  │  │  ├─ prisma.module.ts
│  │  │  ├─ prisma.service.ts
│  │  │  └─ prisma-exception.filter.ts
│  │  ├─ auth/
│  │  │  ├─ auth.module.ts
│  │  │  ├─ auth.controller.ts
│  │  │  ├─ auth.service.ts
│  │  │  ├─ strategies/
│  │  │  └─ guards/
│  │  ├─ abac/
│  │  │  ├─ abac.module.ts
│  │  │  ├─ abac.guard.ts
│  │  │  └─ policy.engine.ts
│  │  ├─ security/
│  │  │  ├─ security.module.ts
│  │  │  └─ security.service.ts
│  │  └─ logger/
│  │     ├─ logger.module.ts
│  │     └─ logger.service.ts
│  │
│  ├─ common/
│  │  ├─ decorators/
│  │  ├─ dtos/
│  │  ├─ exceptions/
│  │  ├─ filters/
│  │  ├─ guards/
│  │  ├─ interceptors/
│  │  ├─ middleware/
│  │  └─ utils/
│  │
│  ├─ modules/
│  │  └─ users/
│  │     ├─ users.module.ts
│  │     ├─ users.controller.ts
│  │     ├─ users.service.ts
│  │     ├─ users.repository.ts
│  │     ├─ dtos/
│  │     ├─ entities/
│  │     └─ policies/
│  │
│  └─ docs/
│     ├─ swagger.ts
│     └─ tsdoc.md
│
├─ prisma/
│  ├─ schema.prisma
│  └─ migrations/
│
├─ test/
│  ├─ unit/
│  ├─ integration/
│  ├─ e2e/
│  └─ factories/
│
├─ .env.example
├─ Dockerfile
├─ docker-compose.yml
├─ jest.config.ts
├─ tsconfig.json
├─ .eslintrc.js
├─ .prettierrc
├─ package.json
└─ README.md

📝 Entity DSL

Define entities using a simple DSL syntax:

EntityName
fieldName:fieldType[?][@unique][@id][@default(value)][@relation(TargetEntity,relationshipType)]

Supported field types:

  • string, text, int, bigint, float, decimal
  • boolean, date, datetime, json, uuid

Modifiers:

  • ?: Optional field
  • @unique: Unique constraint
  • @id: Primary key
  • @default(value): Default value
  • @relation(TargetEntity,type): Relationship

Examples:

# Simple User entity
User
id:uuid@id@default(cuid())
email:string@unique
name:string?
createdAt:datetime@default(now())
updatedAt:datetime@default(now())

# Post entity with relationship
Post
id:uuid@id@default(cuid())
title:string
content:text?
authorId:uuid@relation(User,many-to-one)
publishedAt:datetime?

🔧 Configuration

Environment Variables

The generated project includes a comprehensive .env.example file with all necessary variables:

# Application
NODE_ENV=development
PORT=3000
API_PREFIX=/api
API_VERSION=v1

# Database
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/app?schema=public

# Authentication
JWT_SECRET=change_me
JWT_EXPIRES_IN=15m
REFRESH_JWT_SECRET=change_me_too
REFRESH_JWT_EXPIRES_IN=30d

# Security
CORS_ORIGINS=http://localhost:3000
RATE_LIMIT_POINTS=120
RATE_LIMIT_DURATION=60
CSRF_SECRET=change_me

# Logging
LOG_LEVEL=info
LOG_DESTINATION=console
LOG_FILE_PATH=logs/app.log

# Monitoring
SENTRY_DSN=
SENTRY_ENV=development

# Optional Services
SMTP_HOST=
SMTP_PORT=
SMTP_USER=
SMTP_PASS=
SMTP_FROM=
REDIS_URL=redis://localhost:6379
S3_BUCKET=
S3_REGION=
S3_ACCESS_KEY_ID=
S3_SECRET_ACCESS_KEY=

🚀 Getting Started

  1. Generate a new project:

    backend-generator init
  2. Navigate to the project:

    cd your-project-name
  3. Set up environment:

    cp .env.example .env
    # Edit .env with your configuration
  4. Start the application:

    npm run start:dev
  5. Access your application:

    • API: http://localhost:3000
    • Swagger Docs: http://localhost:3000/docs
    • Health Check: http://localhost:3000/health

🧪 Testing

The generated project includes a complete testing setup:

# Run all tests
npm run test

# Run specific test types
npm run test:unit
npm run test:integration
npm run test:e2e

# Run tests with coverage
npm run test:cov

🐳 Docker

The generated project includes Docker support:

# Start with Docker Compose
docker compose up -d

# View logs
docker compose logs -f app

# Stop services
docker compose down

🔒 Security Features

  • Helmet: Security headers
  • CORS: Cross-origin resource sharing
  • CSRF: Cross-site request forgery protection
  • Rate Limiting: Request rate limiting
  • Input Validation: Global validation pipe
  • ABAC: Attribute-based access control
  • JWT: Secure token-based authentication
  • Optional: Input sanitization, data encryption

📚 Documentation

🚀 Getting Started

🏗️ Architecture & Development

📋 Additional Documentation

  • API Documentation: Auto-generated Swagger/OpenAPI v3 docs in generated projects
  • Code Documentation: TSDoc comments throughout the codebase

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

📄 License

MIT License - see LICENSE file for details.

🆘 Support


Happy coding! 🚀