CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-nestjs--schematics

Angular-style schematics for the NestJS framework, enabling generation of application components through a command-line interface.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

schematics.mddocs/

Schematics Collection

Complete collection of 20+ code generators for NestJS applications, providing standardized component creation with TypeScript support, dependency injection setup, and consistent project structure.

Capabilities

Common Options

All component schematics share common configuration options:

interface BaseSchematicOptions {
  /** Component name */
  name: string;
  /** Target path for generation */
  path?: string | Path;
  /** Module to import the component into */
  module?: Path;
  /** Skip importing into module */
  skipImport?: boolean;
  /** Metadata type for module declaration */
  metadata?: string;
  /** Programming language (ts/js) */
  language?: string;
  /** Source root directory */
  sourceRoot?: string;
  /** Generate spec files */
  spec?: boolean;
  /** Spec file suffix */
  specFileSuffix?: string;
  /** Generate in flat structure */
  flat?: boolean;
}

// Angular DevKit Types
type Path = string;
type Tree = import('@angular-devkit/schematics').Tree;
type SchematicContext = import('@angular-devkit/schematics').SchematicContext;
type Rule = (tree: Tree, context: SchematicContext) => Tree | Observable<Tree> | void;
type Observable<T> = import('rxjs').Observable<T>;

Application Schematics

Application Generator

Creates a complete NestJS application with project structure, configuration, and dependencies.

/**
 * Generate a new NestJS application
 * @param options - Application configuration options
 * @returns Angular DevKit Rule for application generation
 */
function application(options: ApplicationOptions): Rule;

interface ApplicationOptions {
  name: string | number;
  author?: string;
  description?: string;
  directory?: string;
  strict?: boolean;
  version?: string;
  language?: string;
  packageManager?: 'npm' | 'yarn' | 'pnpm' | 'undefined';
  dependencies?: string;
  devDependencies?: string;
  spec?: boolean;
  specFileSuffix?: string;
}

Usage Examples:

# Generate new application
nest new my-app

# With custom options
nest new my-app --strict --package-manager=yarn

Library Generator

Creates a library within a monorepo structure.

/**
 * Generate a Nest library for monorepo projects
 * @param options - Library configuration options
 * @returns Angular DevKit Rule for library generation
 */
function library(options: LibraryOptions): Rule;

interface LibraryOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate library
nest generate library shared

# With alias
nest g lib utils

Sub-Application Generator

Creates a sub-application within a monorepo.

/**
 * Generate a sub-application for monorepo projects
 * @param options - Sub-application configuration options
 * @returns Angular DevKit Rule for sub-application generation
 */
function subApp(options: SubAppOptions): Rule;

interface SubAppOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate sub-application
nest generate sub-app api

# With alias
nest g app admin

Core Component Schematics

Module Generator

Creates NestJS modules with proper decorator setup and file structure.

/**
 * Generate a Nest module
 * @param options - Module configuration options
 * @returns Angular DevKit Rule for module generation
 */
function module(options: ModuleOptions): Rule;

interface ModuleOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate module
nest generate module users

# Generate without importing to parent module
nest g mo products --skip-import

Controller Generator

Creates NestJS controllers with routing and dependency injection setup.

/**
 * Generate a Nest controller
 * @param options - Controller configuration options
 * @returns Angular DevKit Rule for controller generation
 */
function controller(options: ControllerOptions): Rule;

interface ControllerOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate controller
nest generate controller auth

# Generate without spec file
nest g co users --no-spec

# Generate in specific path
nest g co admin/users --path=src/admin

Service Generator

Creates NestJS services (providers) with dependency injection setup.

/**
 * Generate a Nest service
 * @param options - Service configuration options
 * @returns Angular DevKit Rule for service generation
 */
function service(options: ServiceOptions): Rule;

interface ServiceOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate service
nest generate service users

# Generate with flat structure
nest g s auth --flat

Provider Generator

Creates generic NestJS providers.

/**
 * Generate a Nest provider
 * @param options - Provider configuration options
 * @returns Angular DevKit Rule for provider generation
 */
function provider(options: ProviderOptions): Rule;

interface ProviderOptions extends BaseSchematicOptions {
  name: string;
}

HTTP and Request Handling

Guard Generator

Creates NestJS guards for route protection and authorization.

/**
 * Generate a Nest guard
 * @param options - Guard configuration options
 * @returns Angular DevKit Rule for guard generation
 */
function guard(options: GuardOptions): Rule;

interface GuardOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate guard
nest generate guard auth

# Generate with alias
nest g gu roles

Interceptor Generator

Creates NestJS interceptors for request/response transformation.

/**
 * Generate a Nest interceptor
 * @param options - Interceptor configuration options
 * @returns Angular DevKit Rule for interceptor generation
 */
function interceptor(options: InterceptorOptions): Rule;

interface InterceptorOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate interceptor
nest generate interceptor logging

# Generate with alias
nest g itc transform

Pipe Generator

Creates NestJS pipes for data transformation and validation.

/**
 * Generate a Nest pipe
 * @param options - Pipe configuration options
 * @returns Angular DevKit Rule for pipe generation
 */
function pipe(options: PipeOptions): Rule;

interface PipeOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate pipe
nest generate pipe validation

# Generate with alias
nest g pi parse-int

Filter Generator

Creates NestJS exception filters for error handling.

/**
 * Generate a Nest exception filter
 * @param options - Filter configuration options
 * @returns Angular DevKit Rule for filter generation
 */
function filter(options: FilterOptions): Rule;

interface FilterOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate filter
nest generate filter http-exception

# Generate with alias
nest g f validation

Middleware Generator

Creates NestJS middleware for request processing.

/**
 * Generate a Nest middleware
 * @param options - Middleware configuration options
 * @returns Angular DevKit Rule for middleware generation
 */
function middleware(options: MiddlewareOptions): Rule;

interface MiddlewareOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate middleware
nest generate middleware logger

# Generate with alias
nest g mi cors

Gateway and Real-time Communication

Gateway Generator

Creates NestJS WebSocket gateways for real-time communication.

/**
 * Generate a Nest WebSocket gateway
 * @param options - Gateway configuration options
 * @returns Angular DevKit Rule for gateway generation
 */
function gateway(options: GatewayOptions): Rule;

interface GatewayOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate gateway
nest generate gateway chat

# Generate with alias
nest g ga events

GraphQL Integration

Resolver Generator

Creates GraphQL resolvers for NestJS GraphQL applications.

/**
 * Generate a GraphQL resolver
 * @param options - Resolver configuration options
 * @returns Angular DevKit Rule for resolver generation
 */
function resolver(options: ResolverOptions): Rule;

interface ResolverOptions extends BaseSchematicOptions {
  name: string;
}

Usage Examples:

# Generate resolver
nest generate resolver user

# Generate with alias
nest g r posts

Advanced Generators

Resource Generator

Creates a complete CRUD resource with controller, service, DTOs, and entities.

/**
 * Generate a complete CRUD resource
 * @param options - Resource configuration options
 * @returns Angular DevKit Rule for resource generation
 */
function resource(options: ResourceOptions): Rule;

interface ResourceOptions extends BaseSchematicOptions {
  name: string;
  type?: 'rest' | 'graphql-code-first' | 'graphql-schema-first' | 'microservice' | 'ws';
  crud?: boolean;
  isSwaggerInstalled?: boolean;
}

Usage Examples:

# Generate REST resource with CRUD
nest generate resource posts --type=rest --crud

# Generate GraphQL resource
nest g res users --type=graphql-code-first

# Generate microservice resource
nest g res orders --type=microservice

Utility and Structure Generators

Class Generator

Creates generic TypeScript classes.

/**
 * Generate a TypeScript class
 * @param options - Class configuration options
 * @returns Angular DevKit Rule for class generation
 */
function classGenerator(options: ClassOptions): Rule;

interface ClassOptions extends BaseSchematicOptions {
  name: string;
}

Interface Generator

Creates TypeScript interfaces.

/**
 * Generate a TypeScript interface
 * @param options - Interface configuration options
 * @returns Angular DevKit Rule for interface generation
 */
function interfaceGenerator(options: InterfaceOptions): Rule;

interface InterfaceOptions extends BaseSchematicOptions {
  name: string;
}

Decorator Generator

Creates custom TypeScript decorators.

/**
 * Generate a custom decorator
 * @param options - Decorator configuration options
 * @returns Angular DevKit Rule for decorator generation
 */
function decorator(options: DecoratorOptions): Rule;

interface DecoratorOptions extends BaseSchematicOptions {
  name: string;
}

Client Integration

Angular App Generator

Creates Angular client applications integrated with NestJS backend.

/**
 * Generate an Angular client application
 * @param options - Angular app configuration options
 * @returns Angular DevKit Rule for Angular app generation
 */
function angularApp(options: AngularOptions): Rule;

interface AngularOptions extends BaseSchematicOptions {
  name: string;
}

Configuration

Configuration Generator

Creates Nest CLI configuration files.

/**
 * Generate Nest CLI configuration
 * @param options - Configuration options
 * @returns Angular DevKit Rule for configuration generation
 */
function configuration(options: any): Rule;

Common Patterns

Schematic Aliases

Most schematics support short aliases for faster CLI usage:

SchematicAliasExample
application-nest g application my-app
classclnest g cl my-class
controllerconest g co auth
decoratordnest g d custom
filterfnest g f exception
gatewayganest g ga chat
guardgunest g gu auth
interceptoritcnest g itc logging
interfaceitfnest g itf user
librarylibnest g lib shared
middlewareminest g mi cors
modulemonest g mo users
pipepinest g pi validation
providerprnest g pr config
resolverrnest g r user
resourceresnest g res posts
servicesnest g s users
sub-appappnest g app admin

Factory Function Pattern

All schematics follow the Angular DevKit factory pattern:

/**
 * Factory function pattern for all schematics
 * @param options - Schematic-specific options
 * @returns Angular DevKit Rule for tree transformation
 */
function schematicFactory<T>(options: T): Rule;

docs

index.md

schematics.md

utilities.md

tile.json