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
generatecommand) @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 withdrizzle-orm/node-postgres and a lazy-initialized connection pool.
Key dependencies: drizzle-orm, pg, @woltz/rich-domain-drizzle
fullstack-typeorm
Uses TypeORM withDataSource, decorator-based entities, and synchronize: true in development.
Key dependencies: typeorm, pg, reflect-metadata, @woltz/rich-domain-typeorm
Getting Started
After runninginit:
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:Generated Structure
For a Prisma schema withUser, 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
- Review classifications - Adjust Aggregate/Entity based on actual domain boundaries
- Add business logic - The generated code is a starting point
- Add validation rules - Customize schemas with business constraints
- Configure hooks - Add lifecycle hooks as needed
When to Re-generate
- After changing Prisma schema structure
- After adding new models
- Use
--modelsflag to regenerate specific models only
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 aname:type format with support for various modifiers:
Props Examples
Auto-Detection
Theadd command automatically detects:
- Validation Library: Checks
package.jsonforzod,valibot, orarktype - Prisma Adapter: Detects
@woltz/rich-domain-prismafor repository/mapper generation - Output Directory: Looks for existing
src/domainorsrcdirectories
If
@woltz/rich-domain-prisma is not installed, generic implementations are generated that youβll need to customize for your database.