@andres30xed/nest-hex 0.5.0

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 (150) hide show
  1. package/README.en.md +658 -0
  2. package/README.es.md +658 -0
  3. package/README.md +36 -0
  4. package/dist/application/commands/create-module.command.d.ts +7 -0
  5. package/dist/application/commands/create-module.command.d.ts.map +1 -0
  6. package/dist/application/commands/create-module.command.js +15 -0
  7. package/dist/application/commands/create-module.command.js.map +1 -0
  8. package/dist/application/commands/create-project.command.d.ts +8 -0
  9. package/dist/application/commands/create-project.command.d.ts.map +1 -0
  10. package/dist/application/commands/create-project.command.js +17 -0
  11. package/dist/application/commands/create-project.command.js.map +1 -0
  12. package/dist/application/commands/create-resource.command.d.ts +9 -0
  13. package/dist/application/commands/create-resource.command.d.ts.map +1 -0
  14. package/dist/application/commands/create-resource.command.js +17 -0
  15. package/dist/application/commands/create-resource.command.js.map +1 -0
  16. package/dist/application/dtos/module.dto.d.ts +6 -0
  17. package/dist/application/dtos/module.dto.d.ts.map +1 -0
  18. package/dist/application/dtos/module.dto.js +3 -0
  19. package/dist/application/dtos/module.dto.js.map +1 -0
  20. package/dist/application/dtos/project.dto.d.ts +7 -0
  21. package/dist/application/dtos/project.dto.d.ts.map +1 -0
  22. package/dist/application/dtos/project.dto.js +3 -0
  23. package/dist/application/dtos/project.dto.js.map +1 -0
  24. package/dist/application/dtos/resource.dto.d.ts +8 -0
  25. package/dist/application/dtos/resource.dto.d.ts.map +1 -0
  26. package/dist/application/dtos/resource.dto.js +3 -0
  27. package/dist/application/dtos/resource.dto.js.map +1 -0
  28. package/dist/application/queries/get-project-structure.query.d.ts +5 -0
  29. package/dist/application/queries/get-project-structure.query.d.ts.map +1 -0
  30. package/dist/application/queries/get-project-structure.query.js +11 -0
  31. package/dist/application/queries/get-project-structure.query.js.map +1 -0
  32. package/dist/application/use-cases/create-module.use-case.d.ts +9 -0
  33. package/dist/application/use-cases/create-module.use-case.d.ts.map +1 -0
  34. package/dist/application/use-cases/create-module.use-case.js +21 -0
  35. package/dist/application/use-cases/create-module.use-case.js.map +1 -0
  36. package/dist/application/use-cases/create-project.use-case.d.ts +9 -0
  37. package/dist/application/use-cases/create-project.use-case.d.ts.map +1 -0
  38. package/dist/application/use-cases/create-project.use-case.js +24 -0
  39. package/dist/application/use-cases/create-project.use-case.js.map +1 -0
  40. package/dist/application/use-cases/create-resource.use-case.d.ts +9 -0
  41. package/dist/application/use-cases/create-resource.use-case.d.ts.map +1 -0
  42. package/dist/application/use-cases/create-resource.use-case.js +22 -0
  43. package/dist/application/use-cases/create-resource.use-case.js.map +1 -0
  44. package/dist/application/use-cases/get-project-structure.use-case.d.ts +16 -0
  45. package/dist/application/use-cases/get-project-structure.use-case.d.ts.map +1 -0
  46. package/dist/application/use-cases/get-project-structure.use-case.js +14 -0
  47. package/dist/application/use-cases/get-project-structure.use-case.js.map +1 -0
  48. package/dist/domain/entities/module.entity.d.ts +8 -0
  49. package/dist/domain/entities/module.entity.d.ts.map +1 -0
  50. package/dist/domain/entities/module.entity.js +27 -0
  51. package/dist/domain/entities/module.entity.js.map +1 -0
  52. package/dist/domain/entities/project.entity.d.ts +9 -0
  53. package/dist/domain/entities/project.entity.d.ts.map +1 -0
  54. package/dist/domain/entities/project.entity.js +32 -0
  55. package/dist/domain/entities/project.entity.js.map +1 -0
  56. package/dist/domain/entities/resource.entity.d.ts +15 -0
  57. package/dist/domain/entities/resource.entity.d.ts.map +1 -0
  58. package/dist/domain/entities/resource.entity.js +32 -0
  59. package/dist/domain/entities/resource.entity.js.map +1 -0
  60. package/dist/domain/repositories/module.repository.d.ts +6 -0
  61. package/dist/domain/repositories/module.repository.d.ts.map +1 -0
  62. package/dist/domain/repositories/module.repository.js +7 -0
  63. package/dist/domain/repositories/module.repository.js.map +1 -0
  64. package/dist/domain/repositories/project.repository.d.ts +8 -0
  65. package/dist/domain/repositories/project.repository.d.ts.map +1 -0
  66. package/dist/domain/repositories/project.repository.js +7 -0
  67. package/dist/domain/repositories/project.repository.js.map +1 -0
  68. package/dist/domain/repositories/resource.repository.d.ts +6 -0
  69. package/dist/domain/repositories/resource.repository.d.ts.map +1 -0
  70. package/dist/domain/repositories/resource.repository.js +7 -0
  71. package/dist/domain/repositories/resource.repository.js.map +1 -0
  72. package/dist/domain/services/template.service.d.ts +23 -0
  73. package/dist/domain/services/template.service.d.ts.map +1 -0
  74. package/dist/domain/services/template.service.js +7 -0
  75. package/dist/domain/services/template.service.js.map +1 -0
  76. package/dist/domain/value-objects/orm.type.d.ts +8 -0
  77. package/dist/domain/value-objects/orm.type.d.ts.map +1 -0
  78. package/dist/domain/value-objects/orm.type.js +18 -0
  79. package/dist/domain/value-objects/orm.type.js.map +1 -0
  80. package/dist/domain/value-objects/project-name.value.d.ts +7 -0
  81. package/dist/domain/value-objects/project-name.value.d.ts.map +1 -0
  82. package/dist/domain/value-objects/project-name.value.js +26 -0
  83. package/dist/domain/value-objects/project-name.value.js.map +1 -0
  84. package/dist/index.d.ts +3 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +88 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/infrastructure/repositories/file-system-module.repository.d.ts +14 -0
  89. package/dist/infrastructure/repositories/file-system-module.repository.d.ts.map +1 -0
  90. package/dist/infrastructure/repositories/file-system-module.repository.js +121 -0
  91. package/dist/infrastructure/repositories/file-system-module.repository.js.map +1 -0
  92. package/dist/infrastructure/repositories/file-system-project.repository.d.ts +15 -0
  93. package/dist/infrastructure/repositories/file-system-project.repository.d.ts.map +1 -0
  94. package/dist/infrastructure/repositories/file-system-project.repository.js +132 -0
  95. package/dist/infrastructure/repositories/file-system-project.repository.js.map +1 -0
  96. package/dist/infrastructure/repositories/file-system-resource.repository.d.ts +14 -0
  97. package/dist/infrastructure/repositories/file-system-resource.repository.d.ts.map +1 -0
  98. package/dist/infrastructure/repositories/file-system-resource.repository.js +126 -0
  99. package/dist/infrastructure/repositories/file-system-resource.repository.js.map +1 -0
  100. package/dist/infrastructure/services/handlebars-template.service.d.ts +10 -0
  101. package/dist/infrastructure/services/handlebars-template.service.d.ts.map +1 -0
  102. package/dist/infrastructure/services/handlebars-template.service.js +100 -0
  103. package/dist/infrastructure/services/handlebars-template.service.js.map +1 -0
  104. package/dist/presentation/cli/interactive-prompt.service.d.ts +27 -0
  105. package/dist/presentation/cli/interactive-prompt.service.d.ts.map +1 -0
  106. package/dist/presentation/cli/interactive-prompt.service.js +165 -0
  107. package/dist/presentation/cli/interactive-prompt.service.js.map +1 -0
  108. package/dist/presentation/cli/module.controller.d.ts +11 -0
  109. package/dist/presentation/cli/module.controller.d.ts.map +1 -0
  110. package/dist/presentation/cli/module.controller.js +73 -0
  111. package/dist/presentation/cli/module.controller.js.map +1 -0
  112. package/dist/presentation/cli/project.controller.d.ts +13 -0
  113. package/dist/presentation/cli/project.controller.d.ts.map +1 -0
  114. package/dist/presentation/cli/project.controller.js +73 -0
  115. package/dist/presentation/cli/project.controller.js.map +1 -0
  116. package/dist/presentation/cli/resource.controller.d.ts +18 -0
  117. package/dist/presentation/cli/resource.controller.d.ts.map +1 -0
  118. package/dist/presentation/cli/resource.controller.js +83 -0
  119. package/dist/presentation/cli/resource.controller.js.map +1 -0
  120. package/dist/templates/generic/module/entity.index.ts.hbs +1 -0
  121. package/dist/templates/generic/module/module.module.ts.hbs +8 -0
  122. package/dist/templates/generic/project/.gitignore.hbs +35 -0
  123. package/dist/templates/generic/project/README.md.hbs +41 -0
  124. package/dist/templates/generic/project/app.module.ts.hbs +8 -0
  125. package/dist/templates/generic/project/main.ts.hbs +8 -0
  126. package/dist/templates/generic/resource/controller.ts.hbs +51 -0
  127. package/dist/templates/generic/resource/create-command.ts.hbs +13 -0
  128. package/dist/templates/generic/resource/create-use-case.ts.hbs +28 -0
  129. package/dist/templates/generic/resource/delete-command.ts.hbs +3 -0
  130. package/dist/templates/generic/resource/delete-use-case.ts.hbs +15 -0
  131. package/dist/templates/generic/resource/dto.ts.hbs +8 -0
  132. package/dist/templates/generic/resource/get-query.ts.hbs +3 -0
  133. package/dist/templates/generic/resource/get-use-case.ts.hbs +23 -0
  134. package/dist/templates/generic/resource/list-query.ts.hbs +6 -0
  135. package/dist/templates/generic/resource/list-use-case.ts.hbs +20 -0
  136. package/dist/templates/generic/resource/repository.interface.ts.hbs +9 -0
  137. package/dist/templates/generic/resource/update-command.ts.hbs +8 -0
  138. package/dist/templates/generic/resource/update-use-case.ts.hbs +32 -0
  139. package/dist/templates/mongoose/project/nest-cli.json.hbs +8 -0
  140. package/dist/templates/mongoose/project/package.json.hbs +71 -0
  141. package/dist/templates/mongoose/project/tsconfig.json.hbs +22 -0
  142. package/dist/templates/prisma/project/nest-cli.json.hbs +8 -0
  143. package/dist/templates/prisma/project/package.json.hbs +74 -0
  144. package/dist/templates/prisma/project/tsconfig.json.hbs +22 -0
  145. package/dist/templates/typeorm/project/nest-cli.json.hbs +8 -0
  146. package/dist/templates/typeorm/project/package.json.hbs +72 -0
  147. package/dist/templates/typeorm/project/tsconfig.json.hbs +22 -0
  148. package/dist/templates/typeorm/resource/entity.typeorm.ts.hbs +21 -0
  149. package/dist/templates/typeorm/resource/repository.typeorm.ts.hbs +40 -0
  150. package/package.json +44 -0
package/README.en.md ADDED
@@ -0,0 +1,658 @@
1
+ # nest-hex - Complete Documentation (English)
2
+
3
+ CLI tool that generates NestJS scaffolding using Hexagonal Architecture and CQRS patterns.
4
+
5
+ ## Table of Contents
6
+
7
+ 1. [Installation](#installation)
8
+ 2. [System Requirements](#system-requirements)
9
+ 3. [Getting Started](#getting-started)
10
+ 4. [Commands Reference](#commands-reference)
11
+ 5. [Interactive Mode](#interactive-mode)
12
+ 6. [Flag-Based Mode](#flag-based-mode)
13
+ 7. [Generated Project Structure](#generated-project-structure)
14
+ 8. [Architecture Overview](#architecture-overview)
15
+ 9. [Examples](#examples)
16
+ 10. [Troubleshooting](#troubleshooting)
17
+ 11. [Best Practices](#best-practices)
18
+
19
+ ---
20
+
21
+ ## Installation
22
+
23
+ ### Global Installation (Recommended)
24
+
25
+ Install nest-hex globally to use it from anywhere:
26
+
27
+ ```bash
28
+ npm install -g nest-hex
29
+ ```
30
+
31
+ ### Local Installation
32
+
33
+ You can also install it locally in your project:
34
+
35
+ ```bash
36
+ npm install --save-dev nest-hex
37
+ ```
38
+
39
+ Then use it with `npx`:
40
+
41
+ ```bash
42
+ npx nest-hex new my-project
43
+ ```
44
+
45
+ ### Verify Installation
46
+
47
+ Check if nest-hex is installed correctly:
48
+
49
+ ```bash
50
+ nest-hex --version
51
+ ```
52
+
53
+ You should see the version number (e.g., `1.0.0`).
54
+
55
+ ---
56
+
57
+ ## System Requirements
58
+
59
+ - **Node.js**: >= 18.0.0
60
+ - **npm**: >= 9.0.0 (or yarn/pnpm equivalent)
61
+ - **Operating System**: Windows, macOS, or Linux
62
+ - **TypeScript**: Will be installed as a dependency in generated projects
63
+
64
+ ---
65
+
66
+ ## Getting Started
67
+
68
+ ### 1. Create Your First Project
69
+
70
+ The simplest way to create a new project:
71
+
72
+ ```bash
73
+ nest-hex new my-awesome-project
74
+ ```
75
+
76
+ This will start an interactive session where you'll be prompted for:
77
+ - Project name (if not provided)
78
+ - ORM type (TypeORM, Prisma, or Mongoose)
79
+ - Database type (postgres, mysql, mongodb, etc.)
80
+ - Project path (defaults to current directory)
81
+
82
+ ### 2. Navigate to Your Project
83
+
84
+ ```bash
85
+ cd my-awesome-project
86
+ ```
87
+
88
+ ### 3. Install Dependencies
89
+
90
+ ```bash
91
+ npm install
92
+ ```
93
+
94
+ ### 4. Start Development Server
95
+
96
+ ```bash
97
+ npm run start:dev
98
+ ```
99
+
100
+ Your NestJS application will be running on `http://localhost:3000`.
101
+
102
+ ---
103
+
104
+ ## Commands Reference
105
+
106
+ ### `nest-hex new [project-name]`
107
+
108
+ Creates a new NestJS project with Hexagonal Architecture structure.
109
+
110
+ #### Options
111
+
112
+ - `--orm <orm>`: ORM type (typeorm, prisma, mongoose). Default: `typeorm`
113
+ - `--database <database>`: Database type (e.g., postgres, mysql, mongodb). Default: `postgres`
114
+ - `--path <path>`: Project path. Default: current working directory
115
+
116
+ #### Examples
117
+
118
+ **Flag-based mode:**
119
+ ```bash
120
+ # Create project with TypeORM and PostgreSQL
121
+ nest-hex new my-project --orm typeorm --database postgres
122
+
123
+ # Create project with Prisma and MySQL
124
+ nest-hex new my-project --orm prisma --database mysql
125
+
126
+ # Create project with Mongoose and MongoDB
127
+ nest-hex new my-project --orm mongoose --database mongodb
128
+
129
+ # Specify custom path
130
+ nest-hex new my-project --orm typeorm --database postgres --path /path/to/projects
131
+ ```
132
+
133
+ **Interactive mode:**
134
+ ```bash
135
+ # Start interactive session
136
+ nest-hex new
137
+
138
+ # Or without project name
139
+ nest-hex new
140
+ ```
141
+
142
+ #### Generated Files
143
+
144
+ When you create a new project, the following structure is generated:
145
+
146
+ ```
147
+ my-project/
148
+ ├── src/
149
+ │ ├── domain/ # Domain layer (entities, value objects)
150
+ │ ├── application/ # Application layer (use cases, commands, queries)
151
+ │ │ ├── commands/ # CQRS Commands
152
+ │ │ ├── queries/ # CQRS Queries
153
+ │ │ ├── use-cases/ # Business logic
154
+ │ │ └── dtos/ # Data Transfer Objects
155
+ │ ├── infrastructure/ # Infrastructure layer
156
+ │ │ ├── persistence/ # Database implementations
157
+ │ │ └── presentation/ # API controllers
158
+ │ ├── modules/ # Feature modules
159
+ │ ├── main.ts # Application entry point
160
+ │ └── app.module.ts # Root module
161
+ ├── test/ # Test files
162
+ ├── package.json # Dependencies and scripts
163
+ ├── tsconfig.json # TypeScript configuration
164
+ ├── nest-cli.json # NestJS CLI configuration
165
+ ├── .gitignore # Git ignore rules
166
+ └── README.md # Project documentation
167
+ ```
168
+
169
+ ---
170
+
171
+ ### `nest-hex module [module-name]`
172
+
173
+ Generates a new feature module following Hexagonal Architecture.
174
+
175
+ #### Options
176
+
177
+ - `--project-path <path>`: Path to the NestJS project. Default: current directory
178
+ - `--features <features>`: Comma-separated list of features (e.g., `crud,validation,pagination`)
179
+
180
+ #### Examples
181
+
182
+ **Flag-based mode:**
183
+ ```bash
184
+ # Create module in current directory
185
+ nest-hex module user-management --features crud,validation
186
+
187
+ # Create module in specific project
188
+ nest-hex module order-processing --project-path ./my-project --features crud,pagination
189
+ ```
190
+
191
+ **Interactive mode:**
192
+ ```bash
193
+ # Start interactive session
194
+ nest-hex module
195
+ ```
196
+
197
+ #### Generated Module Structure
198
+
199
+ ```
200
+ src/modules/user-management/
201
+ ├── domain/
202
+ │ ├── entities/ # Domain entities
203
+ │ ├── repositories/ # Repository interfaces
204
+ │ └── value-objects/ # Value objects
205
+ ├── application/
206
+ │ ├── commands/ # CQRS Commands
207
+ │ ├── queries/ # CQRS Queries
208
+ │ ├── use-cases/ # Use cases
209
+ │ └── dtos/ # DTOs
210
+ ├── infrastructure/
211
+ │ ├── persistence/ # Repository implementations
212
+ │ └── presentation/ # Controllers
213
+ └── module.module.ts # NestJS module definition
214
+ ```
215
+
216
+ ---
217
+
218
+ ### `nest-hex resource [resource-name]`
219
+
220
+ Generates a complete CRUD resource with entity, repository, use cases, and controller.
221
+
222
+ #### Options
223
+
224
+ - `--project-path <path>`: Path to the NestJS project. Default: current directory
225
+ - `--module-name <name>`: Target module name (required in flag-based mode)
226
+
227
+ #### Examples
228
+
229
+ **Flag-based mode:**
230
+ ```bash
231
+ # Create resource in a module
232
+ nest-hex resource product --module-name catalog --project-path ./my-project
233
+ ```
234
+
235
+ **Interactive mode:**
236
+ ```bash
237
+ # Start interactive session (will prompt for module selection)
238
+ nest-hex resource
239
+ ```
240
+
241
+ #### Interactive Resource Creation
242
+
243
+ When using interactive mode, you'll be prompted to:
244
+
245
+ 1. **Enter resource name** (kebab-case, e.g., `user-profile`)
246
+ 2. **Select module** from existing modules in the project
247
+ 3. **Add fields** to the resource entity:
248
+ - Field name (camelCase)
249
+ - Field type (string, number, boolean, Date, uuid)
250
+ - Required flag
251
+ - Unique flag
252
+
253
+ #### Generated Resource Files
254
+
255
+ For a resource named `product` in the `catalog` module:
256
+
257
+ ```
258
+ src/modules/catalog/
259
+ ├── domain/
260
+ │ ├── entities/
261
+ │ │ └── product.entity.ts # Entity definition
262
+ │ └── repositories/
263
+ │ └── product.repository.ts # Repository interface
264
+ ├── application/
265
+ │ ├── commands/
266
+ │ │ ├── create-product.command.ts
267
+ │ │ ├── update-product.command.ts
268
+ │ │ └── delete-product.command.ts
269
+ │ ├── queries/
270
+ │ │ ├── get-product.query.ts
271
+ │ │ └── list-products.query.ts
272
+ │ ├── use-cases/
273
+ │ │ ├── create-product.use-case.ts
274
+ │ │ ├── update-product.use-case.ts
275
+ │ │ ├── delete-product.use-case.ts
276
+ │ │ ├── get-product.use-case.ts
277
+ │ │ └── list-products.use-case.ts
278
+ │ └── dtos/
279
+ │ └── product.dto.ts
280
+ └── infrastructure/
281
+ ├── persistence/
282
+ │ └── product.repository.ts # Repository implementation
283
+ └── presentation/
284
+ └── product.controller.ts # REST API controller
285
+ ```
286
+
287
+ ---
288
+
289
+ ## Interactive Mode
290
+
291
+ Interactive mode is activated when you don't provide required arguments. The CLI will guide you through the process with prompts.
292
+
293
+ ### Example: Creating a Project Interactively
294
+
295
+ ```bash
296
+ $ nest-hex new
297
+
298
+ ? Project name (kebab-case): my-awesome-api
299
+ ? Select ORM: (Use arrow keys)
300
+ ❯ TypeORM
301
+ Prisma
302
+ Mongoose
303
+ ? Database type (e.g., postgres, mysql, mongodb): postgres
304
+ ? Project path (leave empty for current directory): ./projects
305
+ ```
306
+
307
+ ### Example: Creating a Resource Interactively
308
+
309
+ ```bash
310
+ $ nest-hex resource
311
+
312
+ ? Resource name (kebab-case): user-profile
313
+ ? Select module: (Use arrow keys)
314
+ ❯ user-management
315
+ order-processing
316
+ catalog
317
+ ? Add fields to the resource? (Y/n): Y
318
+ ? Field name (camelCase): firstName
319
+ ? Field type: (Use arrow keys)
320
+ ❯ string
321
+ number
322
+ boolean
323
+ Date
324
+ uuid
325
+ ? Is this field required? (Y/n): Y
326
+ ? Is this field unique? (y/N): N
327
+ ? Add another field? (Y/n): Y
328
+ ...
329
+ ```
330
+
331
+ ---
332
+
333
+ ## Flag-Based Mode
334
+
335
+ Flag-based mode allows you to provide all information via command-line arguments, making it ideal for automation and CI/CD pipelines.
336
+
337
+ ### Complete Example
338
+
339
+ ```bash
340
+ # Create project
341
+ nest-hex new e-commerce-api \
342
+ --orm typeorm \
343
+ --database postgres \
344
+ --path ./projects
345
+
346
+ # Navigate to project
347
+ cd ./projects/e-commerce-api
348
+
349
+ # Install dependencies
350
+ npm install
351
+
352
+ # Create modules
353
+ nest-hex module user-management --features crud,validation
354
+ nest-hex module product-catalog --features crud,pagination
355
+ nest-hex module order-management --features crud
356
+
357
+ # Create resources
358
+ nest-hex resource user --module-name user-management
359
+ nest-hex resource product --module-name product-catalog
360
+ nest-hex resource order --module-name order-management
361
+ ```
362
+
363
+ ---
364
+
365
+ ## Generated Project Structure
366
+
367
+ ### Complete Directory Tree
368
+
369
+ ```
370
+ my-project/
371
+ ├── src/
372
+ │ ├── domain/ # Domain Layer
373
+ │ │ ├── entities/ # Domain entities (business objects)
374
+ │ │ ├── repositories/ # Repository interfaces (ports)
375
+ │ │ ├── value-objects/ # Value objects
376
+ │ │ └── services/ # Domain services
377
+ │ │
378
+ │ ├── application/ # Application Layer
379
+ │ │ ├── commands/ # CQRS Commands (write operations)
380
+ │ │ ├── queries/ # CQRS Queries (read operations)
381
+ │ │ ├── use-cases/ # Application use cases
382
+ │ │ └── dtos/ # Data Transfer Objects
383
+ │ │
384
+ │ ├── infrastructure/ # Infrastructure Layer
385
+ │ │ ├── persistence/ # Database implementations
386
+ │ │ │ └── [orm-specific]/ # ORM-specific code
387
+ │ │ └── presentation/ # External interfaces
388
+ │ │ └── controllers/ # REST API controllers
389
+ │ │
390
+ │ ├── modules/ # Feature Modules
391
+ │ │ └── [module-name]/ # Each module follows hexagonal structure
392
+ │ │ ├── domain/
393
+ │ │ ├── application/
394
+ │ │ └── infrastructure/
395
+ │ │
396
+ │ ├── main.ts # Application entry point
397
+ │ └── app.module.ts # Root NestJS module
398
+
399
+ ├── test/ # Test files
400
+ │ ├── unit/ # Unit tests
401
+ │ └── e2e/ # End-to-end tests
402
+
403
+ ├── package.json # Dependencies and scripts
404
+ ├── tsconfig.json # TypeScript configuration
405
+ ├── nest-cli.json # NestJS CLI configuration
406
+ ├── .gitignore # Git ignore rules
407
+ └── README.md # Project documentation
408
+ ```
409
+
410
+ ---
411
+
412
+ ## Architecture Overview
413
+
414
+ ### Hexagonal Architecture (Ports and Adapters)
415
+
416
+ nest-hex generates projects following Hexagonal Architecture principles, also known as Ports and Adapters pattern.
417
+
418
+ #### Layer Responsibilities
419
+
420
+ 1. **Domain Layer** (Core)
421
+ - Contains business logic and rules
422
+ - Independent of frameworks and external dependencies
423
+ - Defines entities, value objects, and repository interfaces (ports)
424
+ - No dependencies on other layers
425
+
426
+ 2. **Application Layer**
427
+ - Contains use cases and application logic
428
+ - Implements CQRS pattern (Commands and Queries separation)
429
+ - Depends only on Domain layer
430
+ - Coordinates domain objects to perform tasks
431
+
432
+ 3. **Infrastructure Layer**
433
+ - Implements adapters for external concerns
434
+ - Database implementations (TypeORM, Prisma, Mongoose)
435
+ - External API integrations
436
+ - File system operations
437
+ - Depends on Domain and Application layers
438
+
439
+ 4. **Presentation Layer**
440
+ - User interfaces (CLI, REST API, GraphQL)
441
+ - Controllers and request handlers
442
+ - Depends on Application layer
443
+
444
+ ### CQRS Pattern
445
+
446
+ The generated code follows Command Query Responsibility Segregation (CQRS):
447
+
448
+ - **Commands**: Represent write operations (Create, Update, Delete)
449
+ - **Queries**: Represent read operations (Get, List)
450
+ - **Use Cases**: Separate handlers for commands and queries
451
+ - **Benefits**: Clear separation, scalability, and maintainability
452
+
453
+ ### Example Flow
454
+
455
+ ```
456
+ HTTP Request
457
+
458
+ Controller (Presentation)
459
+
460
+ Use Case (Application)
461
+
462
+ Repository Interface (Domain)
463
+
464
+ Repository Implementation (Infrastructure)
465
+
466
+ Database
467
+ ```
468
+
469
+ ---
470
+
471
+ ## Examples
472
+
473
+ ### Example 1: E-Commerce API
474
+
475
+ ```bash
476
+ # 1. Create project
477
+ nest-hex new e-commerce-api --orm typeorm --database postgres
478
+
479
+ cd e-commerce-api
480
+ npm install
481
+
482
+ # 2. Create modules
483
+ nest-hex module user-management
484
+ nest-hex module product-catalog
485
+ nest-hex module shopping-cart
486
+ nest-hex module order-processing
487
+
488
+ # 3. Create resources interactively
489
+ nest-hex resource
490
+ # Follow prompts to create: User, Product, CartItem, Order
491
+
492
+ # 4. Start development
493
+ npm run start:dev
494
+ ```
495
+
496
+ ### Example 2: Blog Platform
497
+
498
+ ```bash
499
+ # Create project with Prisma
500
+ nest-hex new blog-platform --orm prisma --database postgres
501
+
502
+ cd blog-platform
503
+ npm install
504
+
505
+ # Create modules
506
+ nest-hex module content-management --features crud,validation
507
+ nest-hex module user-authentication --features crud
508
+ nest-hex module comments --features crud,pagination
509
+
510
+ # Create resources
511
+ nest-hex resource post --module-name content-management
512
+ nest-hex resource author --module-name content-management
513
+ nest-hex resource comment --module-name comments
514
+ ```
515
+
516
+ ### Example 3: Task Management System
517
+
518
+ ```bash
519
+ # Create project
520
+ nest-hex new task-manager --orm mongoose --database mongodb
521
+
522
+ cd task-manager
523
+ npm install
524
+
525
+ # Create modules and resources
526
+ nest-hex module task-management
527
+ nest-hex resource task --module-name task-management
528
+ nest-hex resource project --module-name task-management
529
+ ```
530
+
531
+ ---
532
+
533
+ ## Troubleshooting
534
+
535
+ ### Common Issues and Solutions
536
+
537
+ #### Issue: "Project already exists"
538
+
539
+ **Error:**
540
+ ```
541
+ Error: Project already exists at /path/to/project
542
+ ```
543
+
544
+ **Solution:**
545
+ - Choose a different project name
546
+ - Delete the existing directory
547
+ - Use a different path with `--path` option
548
+
549
+ #### Issue: "Module not found"
550
+
551
+ **Error:**
552
+ ```
553
+ Error: No modules found in project. Create a module first.
554
+ ```
555
+
556
+ **Solution:**
557
+ - Make sure you're in the correct project directory
558
+ - Create a module first: `nest-hex module my-module`
559
+ - Check that `src/modules/` directory exists
560
+
561
+ #### Issue: "Invalid project name"
562
+
563
+ **Error:**
564
+ ```
565
+ Error: Project name must be in kebab-case
566
+ ```
567
+
568
+ **Solution:**
569
+ - Use lowercase letters, numbers, and hyphens only
570
+ - Examples: `my-project`, `api-v2`, `user-service`
571
+ - Avoid: `MyProject`, `my_project`, `my project`
572
+
573
+ #### Issue: "Template not found"
574
+
575
+ **Error:**
576
+ ```
577
+ Error: Template not found: template-name for ORM: typeorm
578
+ ```
579
+
580
+ **Solution:**
581
+ - Reinstall nest-hex: `npm install -g nest-hex`
582
+ - Check that templates directory exists in installation
583
+ - Report issue if problem persists
584
+
585
+ #### Issue: "Permission denied"
586
+
587
+ **Error:**
588
+ ```
589
+ Error: EACCES: permission denied
590
+ ```
591
+
592
+ **Solution:**
593
+ - Use `sudo` on Linux/macOS (not recommended)
594
+ - Fix npm permissions: `npm config set prefix ~/.npm-global`
595
+ - Or use `npx` instead of global installation
596
+
597
+ ---
598
+
599
+ ## Best Practices
600
+
601
+ ### 1. Naming Conventions
602
+
603
+ - **Projects**: Use kebab-case (e.g., `user-service`, `api-gateway`)
604
+ - **Modules**: Use kebab-case (e.g., `user-management`, `order-processing`)
605
+ - **Resources**: Use kebab-case (e.g., `user-profile`, `order-item`)
606
+ - **Files**: Use kebab-case for file names
607
+ - **Classes**: Use PascalCase (e.g., `UserEntity`, `CreateUserCommand`)
608
+
609
+ ### 2. Project Organization
610
+
611
+ - Keep modules focused on a single business domain
612
+ - Use resources for entities that need CRUD operations
613
+ - Group related functionality in the same module
614
+ - Follow the hexagonal structure strictly
615
+
616
+ ### 3. Development Workflow
617
+
618
+ 1. **Create project** with appropriate ORM
619
+ 2. **Create modules** for each business domain
620
+ 3. **Create resources** for entities requiring CRUD
621
+ 4. **Implement custom use cases** as needed
622
+ 5. **Add infrastructure adapters** for external services
623
+
624
+ ### 4. Testing
625
+
626
+ Generated projects include test setup. Always write tests for:
627
+ - Use cases (application logic)
628
+ - Repository implementations
629
+ - Controllers (integration tests)
630
+
631
+ ### 5. ORM Selection
632
+
633
+ - **TypeORM**: Best for SQL databases, mature ecosystem
634
+ - **Prisma**: Modern, type-safe, great developer experience
635
+ - **Mongoose**: Required for MongoDB, schema validation
636
+
637
+ ---
638
+
639
+ ## Contributing
640
+
641
+ Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
642
+
643
+ ## License
644
+
645
+ MIT License - see LICENSE file for details
646
+
647
+ ---
648
+
649
+ ## Support
650
+
651
+ For issues, questions, or contributions:
652
+ - Open an issue on GitHub
653
+ - Check existing documentation
654
+ - Review examples in this guide
655
+
656
+ ---
657
+
658
+ **Happy coding with nest-hex! 🚀**