nestjs-ddd-cli 2.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/README.md +247 -408
  2. package/ddd.schema.json +111 -0
  3. package/dist/commands/aggregate-validator.d.ts +9 -0
  4. package/dist/commands/aggregate-validator.js +953 -0
  5. package/dist/commands/aggregate-validator.js.map +1 -0
  6. package/dist/commands/ai-assist.d.ts +8 -0
  7. package/dist/commands/ai-assist.js +337 -0
  8. package/dist/commands/ai-assist.js.map +1 -0
  9. package/dist/commands/api-contracts.d.ts +9 -0
  10. package/dist/commands/api-contracts.js +1368 -0
  11. package/dist/commands/api-contracts.js.map +1 -0
  12. package/dist/commands/api-docs.d.ts +8 -0
  13. package/dist/commands/api-docs.js +408 -0
  14. package/dist/commands/api-docs.js.map +1 -0
  15. package/dist/commands/api-versioning.d.ts +11 -0
  16. package/dist/commands/api-versioning.js +643 -0
  17. package/dist/commands/api-versioning.js.map +1 -0
  18. package/dist/commands/audit-logging.d.ts +9 -0
  19. package/dist/commands/audit-logging.js +1129 -0
  20. package/dist/commands/audit-logging.js.map +1 -0
  21. package/dist/commands/batch-generate.d.ts +10 -0
  22. package/dist/commands/batch-generate.js +405 -0
  23. package/dist/commands/batch-generate.js.map +1 -0
  24. package/dist/commands/caching-strategies.d.ts +9 -0
  25. package/dist/commands/caching-strategies.js +874 -0
  26. package/dist/commands/caching-strategies.js.map +1 -0
  27. package/dist/commands/code-analyzer.d.ts +42 -0
  28. package/dist/commands/code-analyzer.js +474 -0
  29. package/dist/commands/code-analyzer.js.map +1 -0
  30. package/dist/commands/database-seeding.d.ts +6 -0
  31. package/dist/commands/database-seeding.js +621 -0
  32. package/dist/commands/database-seeding.js.map +1 -0
  33. package/dist/commands/db-optimization.d.ts +7 -0
  34. package/dist/commands/db-optimization.js +687 -0
  35. package/dist/commands/db-optimization.js.map +1 -0
  36. package/dist/commands/dependency-graph.d.ts +6 -0
  37. package/dist/commands/dependency-graph.js +329 -0
  38. package/dist/commands/dependency-graph.js.map +1 -0
  39. package/dist/commands/doctor-enhanced.d.ts +22 -0
  40. package/dist/commands/doctor-enhanced.js +543 -0
  41. package/dist/commands/doctor-enhanced.js.map +1 -0
  42. package/dist/commands/doctor.d.ts +4 -0
  43. package/dist/commands/doctor.js +151 -0
  44. package/dist/commands/doctor.js.map +1 -0
  45. package/dist/commands/env-manager.d.ts +6 -0
  46. package/dist/commands/env-manager.js +419 -0
  47. package/dist/commands/env-manager.js.map +1 -0
  48. package/dist/commands/event-sourcing-full.d.ts +10 -0
  49. package/dist/commands/event-sourcing-full.js +1107 -0
  50. package/dist/commands/event-sourcing-full.js.map +1 -0
  51. package/dist/commands/feature-flags.d.ts +9 -0
  52. package/dist/commands/feature-flags.js +824 -0
  53. package/dist/commands/feature-flags.js.map +1 -0
  54. package/dist/commands/filter-dsl.d.ts +10 -0
  55. package/dist/commands/filter-dsl.js +1407 -0
  56. package/dist/commands/filter-dsl.js.map +1 -0
  57. package/dist/commands/generate-all.js +485 -32
  58. package/dist/commands/generate-all.js.map +1 -1
  59. package/dist/commands/generate-deployment.d.ts +8 -0
  60. package/dist/commands/generate-deployment.js +746 -0
  61. package/dist/commands/generate-deployment.js.map +1 -0
  62. package/dist/commands/generate-domain-service.d.ts +14 -0
  63. package/dist/commands/generate-domain-service.js +796 -0
  64. package/dist/commands/generate-domain-service.js.map +1 -0
  65. package/dist/commands/generate-entity.js +82 -24
  66. package/dist/commands/generate-entity.js.map +1 -1
  67. package/dist/commands/generate-from-schema.d.ts +56 -0
  68. package/dist/commands/generate-from-schema.js +222 -0
  69. package/dist/commands/generate-from-schema.js.map +1 -0
  70. package/dist/commands/generate-orchestrator.d.ts +14 -0
  71. package/dist/commands/generate-orchestrator.js +887 -0
  72. package/dist/commands/generate-orchestrator.js.map +1 -0
  73. package/dist/commands/generate-repository.d.ts +14 -0
  74. package/dist/commands/generate-repository.js +1019 -0
  75. package/dist/commands/generate-repository.js.map +1 -0
  76. package/dist/commands/generate-shared.d.ts +4 -0
  77. package/dist/commands/generate-shared.js +388 -0
  78. package/dist/commands/generate-shared.js.map +1 -0
  79. package/dist/commands/generate-value-object.d.ts +32 -0
  80. package/dist/commands/generate-value-object.js +700 -0
  81. package/dist/commands/generate-value-object.js.map +1 -0
  82. package/dist/commands/graphql-subscriptions.d.ts +6 -0
  83. package/dist/commands/graphql-subscriptions.js +607 -0
  84. package/dist/commands/graphql-subscriptions.js.map +1 -0
  85. package/dist/commands/graphql-types.d.ts +5 -0
  86. package/dist/commands/graphql-types.js +423 -0
  87. package/dist/commands/graphql-types.js.map +1 -0
  88. package/dist/commands/health-probes-advanced.d.ts +6 -0
  89. package/dist/commands/health-probes-advanced.js +655 -0
  90. package/dist/commands/health-probes-advanced.js.map +1 -0
  91. package/dist/commands/i18n-setup.d.ts +10 -0
  92. package/dist/commands/i18n-setup.js +677 -0
  93. package/dist/commands/i18n-setup.js.map +1 -0
  94. package/dist/commands/init-config.d.ts +6 -0
  95. package/dist/commands/init-config.js +370 -0
  96. package/dist/commands/init-config.js.map +1 -0
  97. package/dist/commands/init-project.js +56 -6
  98. package/dist/commands/init-project.js.map +1 -1
  99. package/dist/commands/interactive-scaffold.d.ts +5 -0
  100. package/dist/commands/interactive-scaffold.js +271 -0
  101. package/dist/commands/interactive-scaffold.js.map +1 -0
  102. package/dist/commands/metrics-prometheus.d.ts +6 -0
  103. package/dist/commands/metrics-prometheus.js +681 -0
  104. package/dist/commands/metrics-prometheus.js.map +1 -0
  105. package/dist/commands/migration-engine.d.ts +6 -0
  106. package/dist/commands/migration-engine.js +446 -0
  107. package/dist/commands/migration-engine.js.map +1 -0
  108. package/dist/commands/migration.d.ts +12 -0
  109. package/dist/commands/migration.js +484 -0
  110. package/dist/commands/migration.js.map +1 -0
  111. package/dist/commands/monorepo.d.ts +8 -0
  112. package/dist/commands/monorepo.js +483 -0
  113. package/dist/commands/monorepo.js.map +1 -0
  114. package/dist/commands/multi-database.d.ts +5 -0
  115. package/dist/commands/multi-database.js +439 -0
  116. package/dist/commands/multi-database.js.map +1 -0
  117. package/dist/commands/observability-tracing.d.ts +10 -0
  118. package/dist/commands/observability-tracing.js +740 -0
  119. package/dist/commands/observability-tracing.js.map +1 -0
  120. package/dist/commands/openapi-export.d.ts +8 -0
  121. package/dist/commands/openapi-export.js +359 -0
  122. package/dist/commands/openapi-export.js.map +1 -0
  123. package/dist/commands/perf-analyzer.d.ts +8 -0
  124. package/dist/commands/perf-analyzer.js +423 -0
  125. package/dist/commands/perf-analyzer.js.map +1 -0
  126. package/dist/commands/rate-limiting.d.ts +10 -0
  127. package/dist/commands/rate-limiting.js +953 -0
  128. package/dist/commands/rate-limiting.js.map +1 -0
  129. package/dist/commands/recipe-plugin.d.ts +56 -0
  130. package/dist/commands/recipe-plugin.js +315 -0
  131. package/dist/commands/recipe-plugin.js.map +1 -0
  132. package/dist/commands/recipe.d.ts +6 -0
  133. package/dist/commands/recipe.js +3941 -0
  134. package/dist/commands/recipe.js.map +1 -0
  135. package/dist/commands/recipes/elasticsearch.recipe.d.ts +1 -0
  136. package/dist/commands/recipes/elasticsearch.recipe.js +761 -0
  137. package/dist/commands/recipes/elasticsearch.recipe.js.map +1 -0
  138. package/dist/commands/recipes/event-sourcing.recipe.d.ts +1 -0
  139. package/dist/commands/recipes/event-sourcing.recipe.js +889 -0
  140. package/dist/commands/recipes/event-sourcing.recipe.js.map +1 -0
  141. package/dist/commands/recipes/index.d.ts +7 -0
  142. package/dist/commands/recipes/index.js +24 -0
  143. package/dist/commands/recipes/index.js.map +1 -0
  144. package/dist/commands/recipes/message-queue.recipe.d.ts +1 -0
  145. package/dist/commands/recipes/message-queue.recipe.js +706 -0
  146. package/dist/commands/recipes/message-queue.recipe.js.map +1 -0
  147. package/dist/commands/recipes/middleware.recipe.d.ts +1 -0
  148. package/dist/commands/recipes/middleware.recipe.js +383 -0
  149. package/dist/commands/recipes/middleware.recipe.js.map +1 -0
  150. package/dist/commands/recipes/multi-tenancy.recipe.d.ts +1 -0
  151. package/dist/commands/recipes/multi-tenancy.recipe.js +520 -0
  152. package/dist/commands/recipes/multi-tenancy.recipe.js.map +1 -0
  153. package/dist/commands/recipes/oauth2.recipe.d.ts +1 -0
  154. package/dist/commands/recipes/oauth2.recipe.js +472 -0
  155. package/dist/commands/recipes/oauth2.recipe.js.map +1 -0
  156. package/dist/commands/recipes/websocket.recipe.d.ts +1 -0
  157. package/dist/commands/recipes/websocket.recipe.js +453 -0
  158. package/dist/commands/recipes/websocket.recipe.js.map +1 -0
  159. package/dist/commands/resilience-patterns.d.ts +13 -0
  160. package/dist/commands/resilience-patterns.js +1029 -0
  161. package/dist/commands/resilience-patterns.js.map +1 -0
  162. package/dist/commands/security-patterns.d.ts +11 -0
  163. package/dist/commands/security-patterns.js +2233 -0
  164. package/dist/commands/security-patterns.js.map +1 -0
  165. package/dist/commands/template-debug.d.ts +27 -0
  166. package/dist/commands/template-debug.js +388 -0
  167. package/dist/commands/template-debug.js.map +1 -0
  168. package/dist/commands/test-factory-full.d.ts +9 -0
  169. package/dist/commands/test-factory-full.js +1570 -0
  170. package/dist/commands/test-factory-full.js.map +1 -0
  171. package/dist/commands/test-scaffold.d.ts +7 -0
  172. package/dist/commands/test-scaffold.js +621 -0
  173. package/dist/commands/test-scaffold.js.map +1 -0
  174. package/dist/index.js +1088 -0
  175. package/dist/index.js.map +1 -1
  176. package/dist/templates/ai-context/CLAUDE.md.hbs +158 -0
  177. package/dist/templates/ai-context/conventions.md.hbs +154 -0
  178. package/dist/templates/command/create-command.hbs +6 -14
  179. package/dist/templates/command/delete-command.hbs +19 -0
  180. package/dist/templates/command/update-command.hbs +24 -0
  181. package/dist/templates/controller/controller.hbs +64 -17
  182. package/dist/templates/dto/create-dto.hbs +29 -5
  183. package/dist/templates/dto/filter-dto.hbs +52 -0
  184. package/dist/templates/dto/filter-query.dto.hbs +148 -0
  185. package/dist/templates/dto/paginated-response.dto.hbs +29 -0
  186. package/dist/templates/dto/pagination-query.dto.hbs +30 -0
  187. package/dist/templates/dto/response-dto.hbs +38 -0
  188. package/dist/templates/dto/update-dto.hbs +11 -0
  189. package/dist/templates/entity/entity.hbs +32 -1
  190. package/dist/templates/event/domain-event.hbs +33 -7
  191. package/dist/templates/event/event-handler.hbs +40 -0
  192. package/dist/templates/exception/base-exceptions.hbs +69 -0
  193. package/dist/templates/exception/entity-not-found.exception.hbs +7 -0
  194. package/dist/templates/mapper/mapper.hbs +49 -24
  195. package/dist/templates/module/module.hbs +34 -10
  196. package/dist/templates/orm-entity/orm-entity.hbs +63 -12
  197. package/dist/templates/prisma/prisma-mapper.hbs +71 -0
  198. package/dist/templates/prisma/prisma-repository.hbs +114 -0
  199. package/dist/templates/prisma/prisma-schema.hbs +20 -0
  200. package/dist/templates/prisma/prisma-service.hbs +51 -0
  201. package/dist/templates/query/get-all.query.hbs +50 -0
  202. package/dist/templates/query/get-by-id.query.hbs +31 -0
  203. package/dist/templates/repository/repository.hbs +55 -13
  204. package/dist/templates/resolver/graphql-input.hbs +54 -0
  205. package/dist/templates/resolver/graphql-type.hbs +58 -0
  206. package/dist/templates/resolver/pagination-args.hbs +33 -0
  207. package/dist/templates/resolver/resolver.hbs +62 -0
  208. package/dist/templates/shared/prisma-query-builder.util.hbs +189 -0
  209. package/dist/templates/shared/query-builder.util.hbs +218 -0
  210. package/dist/templates/test/controller.spec.hbs +124 -0
  211. package/dist/templates/test/repository.spec.hbs +158 -0
  212. package/dist/templates/test/usecase.spec.hbs +116 -0
  213. package/dist/templates/usecase/create-usecase.hbs +19 -7
  214. package/dist/templates/usecase/delete-usecase.hbs +17 -0
  215. package/dist/templates/usecase/update-usecase.hbs +31 -0
  216. package/dist/utils/config.utils.d.ts +45 -0
  217. package/dist/utils/config.utils.js +211 -0
  218. package/dist/utils/config.utils.js.map +1 -0
  219. package/dist/utils/error.utils.d.ts +145 -0
  220. package/dist/utils/error.utils.js +422 -0
  221. package/dist/utils/error.utils.js.map +1 -0
  222. package/dist/utils/field.utils.d.ts +54 -0
  223. package/dist/utils/field.utils.js +389 -0
  224. package/dist/utils/field.utils.js.map +1 -0
  225. package/dist/utils/file.utils.d.ts +19 -8
  226. package/dist/utils/file.utils.js +135 -4
  227. package/dist/utils/file.utils.js.map +1 -1
  228. package/dist/utils/idempotency.utils.d.ts +123 -0
  229. package/dist/utils/idempotency.utils.js +444 -0
  230. package/dist/utils/idempotency.utils.js.map +1 -0
  231. package/dist/utils/naming.utils.js +26 -3
  232. package/dist/utils/naming.utils.js.map +1 -1
  233. package/dist/utils/performance.utils.d.ts +37 -0
  234. package/dist/utils/performance.utils.js +158 -0
  235. package/dist/utils/performance.utils.js.map +1 -0
  236. package/dist/utils/relation.utils.d.ts +92 -0
  237. package/dist/utils/relation.utils.js +388 -0
  238. package/dist/utils/relation.utils.js.map +1 -0
  239. package/dist/utils/rollback.utils.d.ts +49 -0
  240. package/dist/utils/rollback.utils.js +306 -0
  241. package/dist/utils/rollback.utils.js.map +1 -0
  242. package/dist/utils/schema.utils.d.ts +123 -0
  243. package/dist/utils/schema.utils.js +419 -0
  244. package/dist/utils/schema.utils.js.map +1 -0
  245. package/dist/utils/security.utils.d.ts +57 -0
  246. package/dist/utils/security.utils.js +315 -0
  247. package/dist/utils/security.utils.js.map +1 -0
  248. package/dist/utils/template-engine.utils.d.ts +80 -0
  249. package/dist/utils/template-engine.utils.js +463 -0
  250. package/dist/utils/template-engine.utils.js.map +1 -0
  251. package/dist/utils/validation-registry.utils.d.ts +160 -0
  252. package/dist/utils/validation-registry.utils.js +526 -0
  253. package/dist/utils/validation-registry.utils.js.map +1 -0
  254. package/package.json +3 -1
package/README.md CHANGED
@@ -1,506 +1,345 @@
1
1
  # NestJS DDD CLI
2
2
 
3
- 🏗️ **An opinionated CLI for pragmatic Domain-Driven Design with NestJS**
3
+ **An opinionated CLI for pragmatic Domain-Driven Design with NestJS**
4
4
 
5
5
  Stop writing boilerplate. Start building business logic.
6
6
 
7
- Generate production-ready NestJS code following proven DDD/CQRS patterns with consistent structure and immutable architecture principles.
7
+ Generate production-ready, security-hardened NestJS code following proven DDD/CQRS patterns with consistent structure and immutable architecture principles.
8
8
 
9
- **New Features**:
10
- - Initialize new NestJS projects with DDD structure
11
- - Self-update functionality to keep the CLI up to date
12
- - Dependency management to check and update project dependencies
9
+ ## What's New in v3.2
10
+
11
+ - **Security-Hardened Generation**: 25 security iterations following OWASP Top 10
12
+ - **Enterprise Patterns**: Circuit breaker, distributed tracing, feature flags
13
+ - **Advanced Caching**: Cache-aside, write-through, invalidation strategies
14
+ - **Observability**: OpenTelemetry tracing, Prometheus metrics, Grafana dashboards
15
+ - **Database Optimization**: DataLoader, query analysis, connection pooling
16
+ - **Kubernetes-Ready**: Health probes, graceful shutdown, liveness/readiness
17
+ - **GraphQL Subscriptions**: Real-time with PubSub and connection management
13
18
 
14
19
  ## Installation
15
20
 
16
- **From NPM (Recommended):**
17
21
  ```bash
18
22
  npm install -g nestjs-ddd-cli
19
23
  ```
20
24
 
21
- **From Source:**
22
- ```bash
23
- git clone https://github.com/eshe-huli/nestjs-ddd-cli
24
- cd nestjs-ddd-cli
25
- npm install
26
- npm run build
27
- npm link
28
- ```
29
-
30
- ## Usage
31
-
32
- ### Initialize a New NestJS Project
33
-
34
- Create a new NestJS project with DDD structure:
25
+ ## Quick Start
35
26
 
36
27
  ```bash
28
+ # Initialize a new project
37
29
  ddd init my-project
38
- ```
39
30
 
40
- Options:
41
- - `-p, --path <path>` - Path where the project will be created
42
- - `--skip-install` - Skip dependency installation
43
- - `--skip-update` - Skip CLI update check
44
- - `--with-ddd` - Set up DDD folder structure and install required dependencies (default: true)
31
+ # Generate complete CRUD with typed fields
32
+ ddd scaffold User -m users --fields "name:string email:string:unique age:number:optional"
45
33
 
46
- ### Update the CLI
34
+ # Apply authentication recipe
35
+ ddd recipe auth-jwt --install-deps
47
36
 
48
- Update the CLI to the latest version:
37
+ # Set up security patterns
38
+ ddd security-patterns
49
39
 
50
- ```bash
51
- ddd update
40
+ # Add observability
41
+ ddd observability
52
42
  ```
53
43
 
54
- Options:
55
- - `-f, --force` - Force update even if already on latest version
44
+ ## Commands
56
45
 
57
- ### Update Project Dependencies
46
+ ### Core Commands
58
47
 
59
- Check and update project dependencies:
60
-
61
- ```bash
62
- ddd update-deps
63
- ```
48
+ | Command | Description |
49
+ |---------|-------------|
50
+ | `ddd init <name>` | Initialize new NestJS project with DDD structure |
51
+ | `ddd scaffold <entity> -m <module>` | Generate complete CRUD with all layers |
52
+ | `ddd generate <type> <name> -m <module>` | Generate individual components |
53
+ | `ddd recipe [name]` | Apply common patterns (auth, caching, etc.) |
54
+ | `ddd shared` | Generate shared utilities and base classes |
64
55
 
65
- Options:
66
- - `-p, --path <path>` - Path to the project (default: current directory)
67
- - `-a, --all` - Update all outdated dependencies without prompting
56
+ ### Enterprise Commands
68
57
 
69
- ### Generate Complete Scaffolding
58
+ | Command | Description |
59
+ |---------|-------------|
60
+ | `ddd security-patterns` | RBAC, encryption, OWASP middleware, JWT security |
61
+ | `ddd circuit-breaker` | Resilience patterns (retry, timeout, fallback) |
62
+ | `ddd observability` | OpenTelemetry distributed tracing |
63
+ | `ddd feature-flags` | Feature flags with A/B testing support |
64
+ | `ddd caching-advanced` | Multi-layer caching strategies |
65
+ | `ddd db-optimization` | DataLoader, query analyzer, connection pooling |
66
+ | `ddd database-seeding` | Seed runner with fixture factories |
67
+ | `ddd health-probes` | Kubernetes liveness/readiness/startup probes |
68
+ | `ddd metrics-prometheus` | Prometheus metrics with Grafana dashboard |
69
+ | `ddd graphql-subscriptions` | Real-time GraphQL with PubSub |
70
70
 
71
- Generate all files for a new entity (entity, repository, mapper, use cases, controller, etc.):
71
+ ### Utility Commands
72
72
 
73
- ```bash
74
- ddd scaffold Product -m inventory
75
- ```
73
+ | Command | Description |
74
+ |---------|-------------|
75
+ | `ddd update` | Update CLI to latest version |
76
+ | `ddd update-deps` | Update project dependencies |
76
77
 
77
- Options:
78
- - `-m, --module <module>` - Module name (will be created if not exists)
79
- - `-p, --path <path>` - Base path for generation
80
- - `--install-deps` - Install required dependencies
78
+ ## Field-Aware Generation
81
79
 
82
- ### Generate Individual Components
80
+ Generate complete typed entities, DTOs, and migrations:
83
81
 
84
82
  ```bash
85
- # Generate a module
86
- ddd generate module user-management
87
-
88
- # Generate an entity
89
- ddd generate entity User -m user-management
90
-
91
- # Generate a use case
92
- ddd generate usecase CreateUser -m user-management
83
+ ddd scaffold Product -m inventory --fields "name:string price:number:optional sku:string:unique"
84
+ ```
93
85
 
94
- # Generate a domain service
95
- ddd generate service UserValidation -m user-management
86
+ **Field Format:** `name:type:modifier1:modifier2`
96
87
 
97
- # Generate a domain event
98
- ddd generate event UserCreated -m user-management
88
+ | Types | Modifiers |
89
+ |-------|-----------|
90
+ | `string`, `text` | `optional` |
91
+ | `number`, `int`, `float`, `decimal` | `unique` |
92
+ | `boolean` | `relation` |
93
+ | `date`, `datetime`, `timestamp` | `OneToOne`, `OneToMany`, `ManyToOne`, `ManyToMany` |
94
+ | `uuid`, `json`, `enum` | |
99
95
 
100
- # Generate a query handler
101
- ddd generate query GetUser -m user-management
96
+ **Relations:**
97
+ ```bash
98
+ # ManyToOne relation
99
+ ddd scaffold Order -m orders --fields "customer:relation:Customer:ManyToOne"
102
100
 
103
- # Generate everything for an entity within existing module
104
- ddd generate all User -m user-management
101
+ # OneToMany relation
102
+ ddd scaffold Customer -m customers --fields "orders:relation:Order:OneToMany:customer"
105
103
  ```
106
104
 
107
- ### Options
108
-
109
- - `-m, --module <name>`: Specify the module name
110
- - `-p, --path <path>`: Base path for generation (defaults to current directory)
111
- - `--skip-orm`: Skip ORM entity generation
112
- - `--skip-mapper`: Skip mapper generation
113
- - `--skip-repo`: Skip repository generation
114
- - `--with-events`: Include domain events
115
- - `--with-queries`: Include query handlers
116
-
117
- ## Available Generators
118
-
119
- | Generator | Command | Description |
120
- |-----------|---------|-------------|
121
- | **Module** | `ddd generate module <name>` | Creates complete DDD module structure |
122
- | **Entity** | `ddd generate entity <name> -m <module>` | Domain entity with ORM mapping |
123
- | **Use Case** | `ddd generate usecase <name> -m <module>` | CQRS command handler |
124
- | **Domain Service** | `ddd generate service <name> -m <module>` | Domain service for business logic |
125
- | **Domain Event** | `ddd generate event <name> -m <module>` | Domain event for CQRS |
126
- | **Query Handler** | `ddd generate query <name> -m <module>` | CQRS query handler |
127
- | **Complete CRUD** | `ddd scaffold <name> -m <module>` | All files for an entity |
128
- | **All Entity Files** | `ddd generate all <name> -m <module>` | Entity + related files |
105
+ ## Security Features
129
106
 
130
- ## Quick Start
107
+ The CLI generates security-hardened code following OWASP Top 10:
131
108
 
132
- ### 🚀 **Generate Your First Feature**
109
+ ### Generated Security Patterns
133
110
 
134
111
  ```bash
135
- # 1. Create complete scaffolding for a User management feature
136
- ddd scaffold User -m user-management
137
-
138
- # 2. Add business logic to the generated files
139
- # 3. Update index.ts exports
140
- # 4. Run migrations
141
- # 5. Import module in app.module.ts
112
+ ddd security-patterns
142
113
  ```
143
114
 
144
- **What you get in seconds:**
145
- ```
146
- 📁 modules/user-management/
147
- ├── 📄 user-management.module.ts ✅ NestJS module configured
148
- ├── 📁 application/
149
- │ ├── 📁 controllers/
150
- │ │ └── 📄 user.controller.ts ✅ REST endpoints (GET, POST, PUT, DELETE)
151
- │ ├── 📁 domain/
152
- │ │ ├── 📁 entities/
153
- │ │ │ └── 📄 user.entity.ts ✅ Domain entity with interfaces
154
- │ │ └── 📁 usecases/
155
- │ │ ├── 📄 create-user.usecase.ts ✅ Business logic for creation
156
- │ │ ├── 📄 update-user.usecase.ts ✅ Business logic for updates
157
- │ │ └── 📄 delete-user.usecase.ts ✅ Business logic for deletion
158
- │ └── 📁 dto/
159
- │ ├── 📁 requests/
160
- │ │ ├── 📄 create-user.dto.ts ✅ Request validation schemas
161
- │ │ └── 📄 update-user.dto.ts ✅ Update validation schemas
162
- │ └── 📁 responses/
163
- │ └── 📄 user.response.ts ✅ Response data contracts
164
- └── 📁 infrastructure/
165
- ├── 📁 repositories/
166
- │ └── 📄 user.repository.ts ✅ CRUD operations + custom queries
167
- ├── 📁 orm-entities/
168
- │ └── 📄 user.orm-entity.ts ✅ Database schema (TypeORM)
169
- └── 📁 mappers/
170
- └── 📄 user.mapper.ts ✅ Domain ↔ Database mapping
171
- ```
115
+ Creates:
116
+ - **Encryption Service** - AES-256-GCM with PBKDF2 (600,000 iterations)
117
+ - **RBAC/ABAC Service** - Role and attribute-based access control
118
+ - **OWASP Middleware** - XSS, SQL injection, path traversal prevention
119
+ - **JWT Security** - Algorithm confusion prevention, claim validation
120
+ - **CORS Configuration** - Strict origin validation
121
+ - **Cookie Security** - HttpOnly, Secure, SameSite flags
122
+ - **Security Headers** - CSP, HSTS, X-Frame-Options, Permissions-Policy
123
+ - **Input Sanitizer** - HTML, shell, filename, URL sanitization
124
+ - **Secret Vault** - Encrypted secret storage with rotation
172
125
 
173
- > **🚀 From zero to production-ready in under 30 seconds**
126
+ ### Built-in Protections
174
127
 
175
- ## Real-World Examples
128
+ - Path traversal prevention in all file operations
129
+ - Input validation with MaxLength on all string fields
130
+ - Sensitive data masking in logs (credit cards, SSN, tokens)
131
+ - Secure error handling (hides internals in production)
132
+ - Brute force detection with IP blocking
133
+ - CSRF token validation
176
134
 
177
- ### 🏢 **E-commerce Platform**
135
+ ## Recipes
178
136
 
179
137
  ```bash
180
- # Generate order management
181
- ddd scaffold Order -m orders
182
-
183
- # Add payment processing
184
- ddd generate service PaymentProcessor -m orders
185
- ddd generate event OrderPaid -m orders
186
-
187
- # Add inventory checking
188
- ddd generate query CheckStock -m inventory
189
- ddd generate service StockValidator -m inventory
190
- ```
138
+ # List available recipes
139
+ ddd recipe
191
140
 
192
- **Result:** Complete order system with payment processing and inventory management
141
+ # Apply with dependency installation
142
+ ddd recipe auth-jwt --install-deps
193
143
  ```
194
- 📁 modules/orders/
195
- ├── 📄 orders.module.ts
196
- ├── 📁 application/domain/services/
197
- │ └── 📄 payment-processor.service.ts 🆕 Payment business logic
198
- ├── 📁 application/domain/events/
199
- │ └── 📄 order-paid.event.ts 🆕 Order payment event
200
- └── ... (all CRUD operations)
201
-
202
- 📁 modules/inventory/
203
- ├── 📁 application/queries/
204
- │ └── 📄 check-stock.handler.ts 🆕 Stock checking query
205
- ├── 📁 application/domain/services/
206
- │ └── 📄 stock-validator.service.ts 🆕 Stock validation logic
207
- └── ... (all CRUD operations)
208
- ```
209
-
210
- ### 🏥 **Healthcare System**
211
144
 
212
- ```bash
213
- # Patient management
214
- ddd scaffold Patient -m patients
145
+ | Recipe | Description |
146
+ |--------|-------------|
147
+ | `auth-jwt` | JWT authentication with guards and decorators |
148
+ | `pagination` | Shared pagination DTOs and utilities |
149
+ | `soft-delete` | Base entity and repository with soft delete |
150
+ | `audit-log` | Entity change tracking with sensitive data masking |
151
+ | `caching` | Redis caching with decorators |
215
152
 
216
- # Medical records with events
217
- ddd scaffold MedicalRecord -m medical-records
218
- ddd generate event RecordCreated -m medical-records
219
- ddd generate event RecordUpdated -m medical-records
153
+ ## Generated Structure
220
154
 
221
- # Appointment scheduling
222
- ddd generate query FindAvailableSlots -m appointments
223
- ddd generate service AppointmentScheduler -m appointments
224
155
  ```
225
-
226
- ### 🎓 **Learning Management System**
227
-
228
- ```bash
229
- # Course management
230
- ddd scaffold Course -m courses
231
- ddd generate service CourseEnrollment -m courses
232
- ddd generate event StudentEnrolled -m courses
233
-
234
- # Progress tracking
235
- ddd generate query GetStudentProgress -m progress
236
- ddd generate service ProgressCalculator -m progress
156
+ src/
157
+ ├── modules/
158
+ │ └── [module-name]/
159
+ │ ├── [module].module.ts
160
+ │ ├── application/
161
+ │ │ ├── commands/ # CQRS commands
162
+ │ │ ├── queries/ # CQRS queries (paginated)
163
+ │ │ ├── controllers/ # REST endpoints
164
+ │ │ └── dto/
165
+ │ │ ├── requests/ # Input DTOs with validation
166
+ │ │ └── responses/ # Output DTOs
167
+ │ └── domain/
168
+ │ ├── entities/ # Domain entities
169
+ │ ├── events/ # Domain events
170
+ │ ├── services/ # Domain services
171
+ │ └── usecases/ # Business logic
172
+ │ └── infrastructure/
173
+ │ ├── repositories/ # Data access
174
+ │ ├── orm-entities/ # Database schemas
175
+ │ └── mappers/ # Entity mapping
176
+ ├── shared/
177
+ │ ├── security/ # Security services
178
+ │ ├── observability/ # Tracing, metrics
179
+ │ ├── resilience/ # Circuit breaker, retry
180
+ │ └── infrastructure/ # Base classes, utilities
181
+ └── migrations/
237
182
  ```
238
183
 
239
- > **🎯 Each example follows identical patterns** - Learn once, apply everywhere.
240
-
241
- ## Philosophy & Principles
242
-
243
- This CLI embodies **pragmatic Domain-Driven Design** with unwavering consistency:
244
-
245
- ### 🔒 **Immutable Architecture**
246
- - **"Code once, never touch"** - Each generated component remains unchanged after creation
247
- - **Evolution over modification** - New requirements create new use cases, never modify existing ones
248
- - **Predictable structure** - Every project follows identical patterns, enabling instant developer onboarding
249
-
250
- ### 🎯 **Opinionated by Design**
251
- - **Zero configuration fatigue** - One way to do things, the right way
252
- - **Consistent naming** - PascalCase entities, kebab-case modules, predictable file names
253
- - **Proven patterns** - Battle-tested DDD/CQRS structure from real-world enterprise applications
254
-
255
- ### 🚀 **Developer Experience First**
256
- - **No bikeshedding** - Spend time on business logic, not folder structure debates
257
- - **IDE-friendly** - Barrel exports, clear interfaces, TypeScript-first approach
258
- - **Team consistency** - Every developer generates identical code structure
259
-
260
- ### 🏗️ **Enterprise Ready**
261
- - **Separation of concerns** - Domain logic isolated from infrastructure
262
- - **CQRS compliance** - Commands for writes, queries for reads
263
- - **Testable by default** - Clean interfaces enable easy unit testing
264
-
265
- ## What Makes This Different?
184
+ ## Configuration
185
+
186
+ Create `.dddrc.json` in your project root:
187
+
188
+ ```json
189
+ {
190
+ "$schema": "https://unpkg.com/nestjs-ddd-cli/ddd.schema.json",
191
+ "orm": "typeorm",
192
+ "database": "postgres",
193
+ "naming": {
194
+ "table": "snake_case",
195
+ "dto": "snake_case",
196
+ "file": "kebab-case"
197
+ },
198
+ "features": {
199
+ "swagger": true,
200
+ "pagination": true,
201
+ "softDelete": true,
202
+ "timestamps": true,
203
+ "tests": false,
204
+ "events": false
205
+ },
206
+ "paths": {
207
+ "modules": "src/modules",
208
+ "migrations": "src/migrations",
209
+ "shared": "src/shared"
210
+ }
211
+ }
212
+ ```
266
213
 
267
- ### 🎨 **Structure That Scales**
214
+ ## Real-World Examples
268
215
 
269
- Every module follows this **identical, battle-tested structure**:
216
+ ### E-commerce with Security
270
217
 
271
- ```
272
- modules/
273
- └── [feature-name]/ # 🏠 Feature boundary
274
- ├── [feature-name].module.ts # 🔧 NestJS module wiring
275
- ├── application/ # 📋 Application layer
276
- │ ├── commands/ # ✍️ CQRS commands (writes)
277
- │ │ ├── create-[entity].command.ts # └─ Create operations
278
- │ │ ├── update-[entity].command.ts # └─ Update operations
279
- │ │ ├── delete-[entity].command.ts # └─ Delete operations
280
- │ │ └── index.ts # └─ Barrel exports
281
- │ ├── controllers/ # 🌐 HTTP/GraphQL endpoints
282
- │ │ ├── [entity].controller.ts # └─ REST API endpoints
283
- │ │ └── index.ts # └─ Barrel exports
284
- │ ├── domain/ # 🧠 Pure business logic
285
- │ │ ├── entities/ # 📦 Business objects
286
- │ │ │ ├── [entity].entity.ts # └─ Domain entity
287
- │ │ │ └── index.ts # └─ Barrel exports
288
- │ │ ├── events/ # 🎯 Domain events
289
- │ │ │ ├── [entity]-created.event.ts # └─ Event definitions
290
- │ │ │ └── index.ts # └─ Barrel exports
291
- │ │ ├── services/ # ⚙️ Domain services
292
- │ │ │ ├── [entity].service.ts # └─ Business rules
293
- │ │ │ └── index.ts # └─ Barrel exports
294
- │ │ └── usecases/ # 🎬 Use case operations
295
- │ │ ├── create-[entity].usecase.ts# └─ Create business logic
296
- │ │ ├── update-[entity].usecase.ts# └─ Update business logic
297
- │ │ ├── delete-[entity].usecase.ts# └─ Delete business logic
298
- │ │ └── index.ts # └─ Barrel exports
299
- │ ├── dto/ # 📄 Data contracts
300
- │ │ ├── requests/ # 📤 Inbound data
301
- │ │ │ ├── create-[entity].dto.ts # └─ Create request
302
- │ │ │ ├── update-[entity].dto.ts # └─ Update request
303
- │ │ │ └── index.ts # └─ Barrel exports
304
- │ │ ├── responses/ # 📥 Outbound data
305
- │ │ │ ├── [entity].response.ts # └─ Entity response
306
- │ │ │ └── index.ts # └─ Barrel exports
307
- │ │ └── index.ts # └─ Barrel exports
308
- │ └── queries/ # 🔍 CQRS queries (reads)
309
- │ ├── get-[entity].handler.ts # └─ Single entity query
310
- │ ├── list-[entities].handler.ts # └─ Multiple entities query
311
- │ └── index.ts # └─ Barrel exports
312
- └── infrastructure/ # 🏗️ Infrastructure layer
313
- ├── mappers/ # 🔄 Data transformation
314
- │ ├── [entity].mapper.ts # └─ Domain ↔ ORM mapping
315
- │ └── index.ts # └─ Barrel exports
316
- ├── orm-entities/ # 🗄️ Database schema
317
- │ ├── [entity].orm-entity.ts # └─ TypeORM entity
318
- │ └── index.ts # └─ Barrel exports
319
- └── repositories/ # 💾 Data access
320
- ├── [entity].repository.ts # └─ Repository implementation
321
- └── index.ts # └─ Barrel exports
218
+ ```bash
219
+ ddd init ecommerce-api
220
+ cd ecommerce-api
221
+
222
+ # Core security
223
+ ddd security-patterns
224
+ ddd recipe auth-jwt --install-deps
225
+
226
+ # Domain modules
227
+ ddd scaffold Product -m inventory --fields "name:string price:decimal sku:string:unique stock:int"
228
+ ddd scaffold Order -m orders --fields "total:decimal status:enum:pending,paid,shipped customerId:uuid"
229
+ ddd scaffold Customer -m customers --fields "email:string:unique name:string"
230
+
231
+ # Enterprise features
232
+ ddd circuit-breaker
233
+ ddd observability
234
+ ddd caching-advanced
322
235
  ```
323
236
 
324
- > **🎯 Every feature looks identical** - No surprises, no confusion, just consistency.
325
-
326
- ### 🧠 **Smart Defaults & Conventions**
237
+ ### Microservice with Observability
327
238
 
328
239
  ```bash
329
- # Naming follows strict patterns
330
- ddd generate entity UserProfile # → user-profile.entity.ts
331
- ddd generate service OrderValidator # → order-validator.service.ts
332
- ddd generate event PaymentProcessed # → payment-processed.event.ts
240
+ ddd init payment-service
241
+ cd payment-service
242
+
243
+ # Infrastructure
244
+ ddd security-patterns
245
+ ddd observability
246
+ ddd metrics-prometheus
247
+ ddd health-probes
248
+
249
+ # Domain
250
+ ddd scaffold Transaction -m payments --fields "amount:decimal currency:string status:enum:pending,completed,failed"
251
+ ddd circuit-breaker
333
252
  ```
334
253
 
335
- **Built-in Intelligence:**
336
- - **🔄 Barrel exports** - Automatic `index.ts` files for clean imports
337
- - **🔒 TypeScript strict** - Zero `any` types, full type safety
338
- - **💉 DI ready** - Injectable decorators configured
339
- - **📋 Interface first** - Clear contracts between layers
340
- - **📁 Predictable paths** - Same location every time
341
-
342
- ### 💡 **Enterprise Patterns**
343
-
344
- ```typescript
345
- // ✅ Commands (writes) - Tell, don't ask
346
- @CommandHandler(CreateUserCommand)
347
- export class CreateUserHandler {
348
- async execute(command: CreateUserCommand): Promise<void> {
349
- // Returns nothing - just does the work
350
- }
351
- }
254
+ ### GraphQL API with Real-time
352
255
 
353
- // ✅ Queries (reads) - Ask, don't tell
354
- @QueryHandler(GetUserQuery)
355
- export class GetUserHandler {
356
- async execute(query: GetUserQuery): Promise<UserResponse> {
357
- // Returns data - no side effects
358
- }
359
- }
256
+ ```bash
257
+ ddd init realtime-api
258
+ cd realtime-api
360
259
 
361
- // Domain Events - Loose coupling
362
- export class UserCreatedEvent implements IEvent {
363
- constructor(public readonly userId: string) {}
364
- }
260
+ ddd scaffold Message -m chat --fields "content:text senderId:uuid roomId:uuid"
261
+ ddd graphql-subscriptions
262
+ ddd caching-advanced
365
263
  ```
366
264
 
367
- **Battle-tested principles:**
368
- - **Command/Query Separation** - Writes vs reads clearly separated
369
- - **Domain Events** - Decoupled communication between bounded contexts
370
- - **Repository Pattern** - Abstract data access from business logic
371
- - **Clean Architecture** - Dependencies point inward to domain
265
+ ## AI Integration
372
266
 
373
- ## After Generation
267
+ The CLI generates a `CLAUDE.md` file with project context for AI assistants:
268
+ - Project structure documentation
269
+ - CLI command reference
270
+ - Naming conventions
271
+ - Architecture rules
272
+ - Security patterns
273
+ - Common patterns
374
274
 
375
- ### 🔧 **Your 5-Minute Setup Checklist:**
275
+ ## API Conventions
376
276
 
377
- ```bash
378
- # ✅ 1. Generated files are ready - Review structure
379
- ls -la modules/your-feature/
380
-
381
- # ✅ 2. Add business properties to entities
382
- # Edit: application/domain/entities/[entity].entity.ts
383
- # Add: name: string; email: string; etc.
277
+ All generated APIs follow RESTful conventions with security:
384
278
 
385
- # 3. Update DTOs with validation rules
386
- # Edit: application/dto/requests/create-[entity].dto.ts
387
- # Add: @IsEmail() email: string; @IsNotEmpty() name: string;
279
+ | Method | Path | Description |
280
+ |--------|------|-------------|
281
+ | GET | `/entities` | List with pagination |
282
+ | GET | `/entities/:id` | Get single entity |
283
+ | POST | `/entities` | Create new entity |
284
+ | PUT | `/entities/:id` | Update entity |
285
+ | DELETE | `/entities/:id` | Soft delete entity |
388
286
 
389
- # ✅ 4. Configure database mappings
390
- # Edit: infrastructure/orm-entities/[entity].orm-entity.ts
391
- # Add: @Column() name: string; @Column() email: string;
287
+ ### Pagination
392
288
 
393
- # ✅ 5. Wire up the module
394
- # Edit: app.module.ts
395
- # Add: YourFeatureModule to imports array
289
+ ```
290
+ GET /entities?page=1&limit=10&sortBy=createdAt&sortOrder=DESC
396
291
  ```
397
292
 
398
- ### 🎯 **Focus on Business Value:**
399
- ```typescript
400
- // ✅ Write business rules in domain services
401
- export class OrderValidator {
402
- validateBusinessRules(order: Order): ValidationResult {
403
- // Your domain logic here - not infrastructure concerns
404
- }
405
- }
406
-
407
- // ✅ Add complex queries for reporting
408
- @QueryHandler(GetMonthlyRevenueQuery)
409
- export class GetMonthlyRevenueHandler {
410
- async execute(query: GetMonthlyRevenueQuery) {
411
- // Complex business queries - not CRUD
412
- }
413
- }
414
-
415
- // ✅ Handle domain events for integration
416
- @EventsHandler(OrderCreatedEvent)
417
- export class OrderCreatedHandler {
418
- async handle(event: OrderCreatedEvent) {
419
- // Send emails, update analytics, etc.
293
+ Response:
294
+ ```json
295
+ {
296
+ "items": [...],
297
+ "meta": {
298
+ "total": 100,
299
+ "page": 1,
300
+ "limit": 10,
301
+ "totalPages": 10,
302
+ "hasNextPage": true,
303
+ "hasPreviousPage": false
420
304
  }
421
305
  }
422
306
  ```
423
307
 
424
- > **🚀 From scaffolding to production in minutes, not days**
425
-
426
- ## Why This CLI Exists
308
+ ## Philosophy
427
309
 
428
- ### 😤 **The Problem**
429
- - Endless debates about folder structure
430
- - Inconsistent naming across team members
431
- - Copy-pasting boilerplate between features
432
- - Mixed patterns in the same codebase
433
- - New developers spending weeks learning "our way"
310
+ ### Security First
311
+ - OWASP Top 10 compliance built-in
312
+ - Secure defaults, not optional add-ons
313
+ - Production-ready from day one
434
314
 
435
- ### 🎯 **The Solution**
436
- - **One structure** that works for all features
437
- - **Zero configuration** - works out of the box
438
- - **Battle-tested patterns** from real enterprise apps
439
- - **Instant onboarding** - same structure everywhere
440
- - **Focus on business logic** instead of architecture decisions
315
+ ### Immutable Architecture
316
+ - Each generated component remains unchanged after creation
317
+ - New requirements create new use cases, never modify existing ones
318
+ - Predictable structure enables instant developer onboarding
441
319
 
442
- ### 🏆 **The Result**
443
- - 10x faster feature development
444
- - Consistent codebase architecture
445
- - Easy code reviews and maintenance
446
- - New developers productive from day one
447
- - No more "where does this file go?" questions
320
+ ### Opinionated by Design
321
+ - Zero configuration fatigue - one way to do things
322
+ - Consistent naming across all projects
323
+ - Battle-tested patterns from enterprise applications
448
324
 
449
- ---
325
+ ### CQRS Compliance
326
+ - Commands for writes, queries for reads
327
+ - Clear separation of concerns
328
+ - Testable by default
450
329
 
451
- ## Contributing & Development
452
-
453
- ### 🔧 **Local Development**
330
+ ## Contributing
454
331
 
455
332
  ```bash
456
- # Clone and setup
457
333
  git clone https://github.com/eshe-huli/nestjs-ddd-cli
458
334
  cd nestjs-ddd-cli
459
335
  npm install
460
-
461
- # Test changes locally
462
- npm run dev -- generate entity Test -m test
463
-
464
- # Build for production
465
336
  npm run build
337
+ npm link
466
338
 
467
- # Test globally installed version
468
- ddd generate entity Test -m test
469
- ```
470
-
471
- ### 🧪 **Testing Your Changes**
472
-
473
- ```bash
474
- # Create a test project
475
- mkdir test-project && cd test-project
476
-
477
- # Test scaffolding
478
- ddd scaffold Product -m inventory
479
-
480
- # Verify structure matches expectations
481
- tree modules/inventory/
482
-
483
- # Test individual generators
484
- ddd generate service ProductValidator -m inventory
485
- ddd generate event ProductCreated -m inventory
486
- ddd generate query GetProductsByCategory -m inventory
487
- ```
488
-
489
- ### 📋 **Template Structure**
339
+ # Test locally
340
+ ddd scaffold Test -m test-module --fields "name:string"
490
341
  ```
491
- src/templates/
492
- ├── 📁 entity/ # Domain entity templates
493
- ├── 📁 service/ # Domain service templates
494
- ├── 📁 event/ # Domain event templates
495
- ├── 📁 query/ # Query handler templates
496
- ├── 📁 usecase/ # Use case templates
497
- ├── 📁 controller/ # Controller templates
498
- ├── 📁 repository/ # Repository templates
499
- └── 📁 ... (more templates)
500
- ```
501
-
502
- > **🤝 Pull requests welcome!** Help make DDD development even better.
503
342
 
504
343
  ## License
505
344
 
506
- MIT - Build amazing things 🚀
345
+ MIT