Skip to main content

Overview

@woltz/rich-domain-cli provides CLI tools for scaffolding DDD projects and generating domain entities from Prisma schemas.

Project Scaffolding

Initialize complete projects from templates

Prisma Introspection

Generate domain from existing schemas

Smart Classification

Auto-detects Aggregates vs Entities

Full Stack Generation

Schemas, entities, repositories, mappers

Requirements

  • Node.js >= 20
  • Prisma schema file (for generate command)
  • @woltz/rich-domain (required)
  • @woltz/rich-domain-prisma (optional, for repositories/mappers)
  • Validation library (optional, for runtime validation)

Commands

The CLI provides three main commands:

init

Initialize a new DDD project from a template with all infrastructure pre-configured.

Options

Examples


Templates

Available Templates

All templates share the same DDD architecture and generate the same project structure. They differ only in the ORM layer.

Generated Project Structure

Scripts

All templates include the same base scripts:
TypeORM does not include db:generate, db:migrate, db:push, or db:studio β€” schema synchronization is handled by synchronize: true in development mode.

fullstack-prisma

Uses Prisma v7 with the @prisma/adapter-pg driver adapter (required in v7) and prisma.config.ts for schema configuration. Key dependencies: @prisma/client, @prisma/adapter-pg, pg, @woltz/rich-domain-prisma

fullstack-drizzle

Uses Drizzle ORM with drizzle-orm/node-postgres and a lazy-initialized connection pool. Key dependencies: drizzle-orm, pg, @woltz/rich-domain-drizzle

fullstack-typeorm

Uses TypeORM with DataSource, decorator-based entities, and synchronize: true in development. Key dependencies: typeorm, pg, reflect-metadata, @woltz/rich-domain-typeorm
The TypeORM template enables synchronize: true in development mode. Disable this and use migrations in production.

Getting Started

After running init:

generate

Generate domain entities, repositories, and mappers from your Prisma schema.

Options

Examples

Package Detection

The CLI automatically detects installed packages and adjusts generation accordingly:
Repository and mapper files are only generated when @woltz/rich-domain-prisma is installed.

Generated Structure

For a Prisma schema with User, Post, and Comment models:

Classification Logic

The CLI classifies models as Aggregates or Entities based on their relationships.

Classification Rules


Validation Libraries

Zod (Default)

Valibot

ArkType

None (Interfaces Only)


Best Practices

After Generation

  1. Review classifications - Adjust Aggregate/Entity based on actual domain boundaries
  2. Add business logic - The generated code is a starting point
  3. Add validation rules - Customize schemas with business constraints
  4. Configure hooks - Add lifecycle hooks as needed

When to Re-generate

  • After changing Prisma schema structure
  • After adding new models
  • Use --models flag to regenerate specific models only
Use --dry-run first to preview changes before overwriting files.

Manual Adjustments

Some scenarios require manual adjustment:

add

Manually create an entity, aggregate, or value object without requiring a Prisma schema.

Options

Examples

Props Syntax

The props follow a name:type format with support for various modifiers:

Props Examples

Auto-Detection

The add command automatically detects:
  1. Validation Library: Checks package.json for zod, valibot, or arktype
  2. Prisma Adapter: Detects @woltz/rich-domain-prisma for repository/mapper generation
  3. Output Directory: Looks for existing src/domain or src directories
If @woltz/rich-domain-prisma is not installed, generic implementations are generated that you’ll need to customize for your database.