Complete CLI toolkit for generating DDD domains, utilities, auth configuration, and app structure for Next.js applications
npm install nextjs-ddd-cliA powerful command-line interface for generating Domain-Driven Design (DDD) domains with progressive complexity levels, Swagger integration, and full-stack capabilities for Next.js applications.
- ๐๏ธ Progressive Complexity: Start simple, grow complex as needed (4 levels)
- ๐ Swagger Integration: Generate domains from OpenAPI/Swagger docs
- ๐ฏ Full-Stack Generation: Complete domain with UI, tests, and docs
- ๐ Value Objects: Built-in DDD value objects with validation
- ๐งช Testing Ready: Comprehensive test suites (unit, integration, E2E)
- ๐จ Modern UI: TailwindCSS, Chakra UI, Material UI support
- ๐ Documentation: Auto-generated docs and Storybook stories
- โก Performance: Built-in optimizations and best practices
``bash`
npm install -g or
yarn global add nextjs-ddd-clior
pnpm add -g nextjs-ddd-cli
Bootstrap your Next.js project with essential utility libraries and custom hooks:
`bash`
nextjs-ddd-cli setupor with force flag to overwrite existing files
nextjs-ddd-cli setup --force
This will generate:
- lib/ - Essential utility functions (array helpers, object helpers, fetcher, date helpers, etc.)
- hooks/ - Custom React hooks (useDebounce, useEntityTable, useMobile, useInView)
- config/ - NextAuth configuration with custom session tokens
- src/app/ - Complete app structure with protected/unprotected routes
- @types/ - TypeScript type definitions
- constants/ - Application constants and route URLs
- components/ - Shared UI components
App Structure Generated:
- src/app/page.tsx - Root page with auth redirectsrc/app/(protected)/
- - Protected routes requiring authenticationsrc/app/(unprotected)/
- - Public routes (login, register, etc.)src/app/api/auth/[...nextauth]/
- - NextAuth API routes
Create a new domain with Level 1 (CRUD) structure:
`bash
nextjs-ddd-cli generate or
nextjs-ddd-cli g
Options:
-
-d, --description - Domain description
- -p, --path - Custom domains path (default: src/domains)$3
Upgrade a domain to a higher complexity level:
`bash
nextjs-ddd-cli add-complexity --level <2-4>
or
nextjs-ddd-cli ac -l <2-4>Example
nextjs-ddd-cli add-complexity products --level 2
`$3
View all domains and their current complexity levels:
`bash
nextjs-ddd-cli list
or
nextjs-ddd-cli ls
`$3
Create a complete full-stack domain with advanced features:
`bash
nextjs-ddd-cli generate-full-stack
or
nextjs-ddd-cli gfs Example
nextjs-ddd-cli gfs products
`This command provides an interactive setup for:
- Complexity Level: Choose from 4 progressive levels
- UI Framework: React with TailwindCSS, Chakra UI, Material UI, or Ant Design
- Features: Tests, docs, authentication, performance optimizations
- Advanced Tools: Storybook stories, E2E tests with Playwright
$3
Generate a complete DDD module from Swagger/OpenAPI documentation:
`bash
nextjs-ddd-cli add-module-swagger
or
nextjs-ddd-cli ams Examples
nextjs-ddd-cli ams https://petstore.swagger.io/v2/swagger.json
nextjs-ddd-cli ams ./api-docs/swagger.json
`This command will:
- Parse Swagger documentation and extract available modules
- Generate complete TypeScript types from schemas
- Create service layer with all CRUD operations
- Generate React Query hooks for data fetching
- Create React components and pages with modern UI
- NEW: Include value objects for domain modeling
- Include comprehensive tests and documentation
Options:
-
-p, --path - Custom domains path (default: src/domains)Enhanced Features:
- โ
Full CRUD operation detection (GET, POST, PUT, PATCH, DELETE)
- โ
TypeScript type generation from Swagger schemas
- โ
Request/response type extraction
- โ
Query parameter and filter type generation
- โ
React Query integration with proper caching
- โ
Module update detection and smart merging
- โ
NEW: Value objects (Status, Email, ID) generation
- โ
NEW: Enhanced UI components with TailwindCSS
- โ
NEW: Comprehensive form handling with react-hook-form + Zod
- โ
Comprehensive error handling and validation
Complexity Levels
$3
- Basic types and interfaces
- Simple service layer
- API integration
- React hooks
- UI components
- Page components$3
- Value objects
- Validation services
- Business rules
- Domain-specific errors$3
- Domain entities
- Aggregate roots
- Domain services
- Repository pattern
- Specifications
- Factories$3
- Complex workflows
- Domain events
- Event handlers
- Application services
- Command/Query pattern
- Facades for UIExample Workflow
1. Create a new domain:
`bash
nextjs-ddd-cli generate orders
`2. Start developing with basic CRUD operations
3. Add validation and business rules when needed:
`bash
nextjs-ddd-cli add-complexity orders --level 2
`4. Introduce rich domain models:
`bash
nextjs-ddd-cli add-complexity orders --level 3
`5. Add complex workflows and events:
`bash
nextjs-ddd-cli add-complexity orders --level 4
`Generated Structure
$3
`
orders/
โโโ models/
โ โโโ order.types.ts
โ โโโ order.schema.ts
โโโ services/
โ โโโ order.service.ts
โโโ api/
โ โโโ order.api.ts
โ โโโ order.queries.ts
โ โโโ order.mutations.ts
โโโ hooks/
โ โโโ useOrders.ts
โ โโโ useOrder.ts
โ โโโ useOrderMutations.ts
โโโ components/
โ โโโ OrderList.tsx
โ โโโ OrderCard.tsx
โ โโโ OrderForm.tsx
โ โโโ OrderFilters.tsx
โโโ pages/
โ โโโ OrdersPage.tsx
โ โโโ OrderDetailPage.tsx
โ โโโ OrderEditPage.tsx
โโโ README.md
`$3
Level 2 adds:
-
value-objects/ - Domain value objects
- errors/ - Domain-specific errorsLevel 3 adds:
-
entities/ - Domain entities
- repositories/ - Repository interfaces
- infrastructure/ - Technical implementations
- specifications/ - Business specifications
- factories/ - Entity factoriesLevel 4 adds:
-
workflows/ - Complex business workflows
- events/ - Domain events
- facades/ - Simplified API for UI
- application/ - Application servicesConfiguration
Create a
.dddrc.json file in your project root for default settings:`json
{
"domainsPath": "src/domains",
"includeTests": true,
"includeApi": true,
"defaultLevel": 1
}
`Development
$3
`bash
cd packages/cli
npm install
npm run build
`$3
`bash
npm link
nextjs-ddd-cli --help
``MIT