@dawudesign/node-hexa-cli 0.1.3 → 0.1.4
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.
- package/README.md +282 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# @dawudesign/node-hexa-cli
|
|
2
|
+
|
|
3
|
+
> Scaffold and enforce **NestJS Hexagonal DDD** architecture from the command line.
|
|
4
|
+
|
|
5
|
+
**node-hexa** automates the repetitive parts of clean architecture in NestJS:
|
|
6
|
+
|
|
7
|
+
- **Scaffold** — generates a full bounded context with dependency injection pre-wired, in one command
|
|
8
|
+
- **Enforce** — statically analyzes your TypeScript source and reports architecture violations
|
|
9
|
+
- **Document** — exports a Mermaid diagram and architecture report as Markdown or SVG
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- **Node.js ≥ 20**
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g @dawudesign/node-hexa-cli
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Verify:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
node-hexa --version
|
|
29
|
+
node-hexa --help
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Quickstart
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 1. Create a new NestJS Hexagonal DDD project
|
|
38
|
+
node-hexa init my-app
|
|
39
|
+
cd my-app
|
|
40
|
+
|
|
41
|
+
# 2. Start the server
|
|
42
|
+
pnpm start:dev
|
|
43
|
+
|
|
44
|
+
# 3. Verify architecture is clean
|
|
45
|
+
node-hexa check .
|
|
46
|
+
# ✓ Architecture check passed
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Commands
|
|
52
|
+
|
|
53
|
+
### `init`
|
|
54
|
+
|
|
55
|
+
Creates a new NestJS project with the complete Hexagonal DDD structure.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
node-hexa init <name>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
node-hexa init my-app
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Generates:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
my-app/
|
|
69
|
+
├── src/
|
|
70
|
+
│ ├── main.ts
|
|
71
|
+
│ ├── app.module.ts
|
|
72
|
+
│ └── contexts/
|
|
73
|
+
│ └── iam/
|
|
74
|
+
│ ├── iam.module.ts
|
|
75
|
+
│ ├── domain/
|
|
76
|
+
│ │ ├── entities/user.entity.ts
|
|
77
|
+
│ │ └── ports/user.repository.port.ts
|
|
78
|
+
│ ├── application/
|
|
79
|
+
│ │ └── use-cases/create-user.usecase.ts
|
|
80
|
+
│ └── infrastructure/
|
|
81
|
+
│ ├── http/user.controller.ts
|
|
82
|
+
│ └── persistence/in-memory-user.repository.ts
|
|
83
|
+
└── node-hexa.config.json
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### `generate context`
|
|
89
|
+
|
|
90
|
+
Generates a complete bounded context inside an existing NestJS project.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
node-hexa generate context <name>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
cd my-app
|
|
98
|
+
node-hexa generate context orders
|
|
99
|
+
# ✓ Context 'orders' generated at src/contexts/orders/
|
|
100
|
+
# → Import OrdersModule in your AppModule to activate it.
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### `generate usecase`
|
|
106
|
+
|
|
107
|
+
Generates a use case with its DTO and Vitest spec inside an existing bounded context.
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
node-hexa generate usecase <name> <context>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
node-hexa generate usecase delete-user iam
|
|
115
|
+
# ✓ Use case 'delete-user' generated in context 'iam'
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Generated files:
|
|
119
|
+
```
|
|
120
|
+
src/contexts/iam/application/use-cases/
|
|
121
|
+
├── delete-user.usecase.ts
|
|
122
|
+
├── delete-user.dto.ts
|
|
123
|
+
└── delete-user.usecase.spec.ts
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
### `generate aggregate`
|
|
129
|
+
|
|
130
|
+
Generates a full DDD aggregate (entity, value object, port, use case, in-memory repository, HTTP controller, NestJS module).
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
node-hexa generate aggregate <name> <context>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
node-hexa generate aggregate product catalog
|
|
138
|
+
# ✓ Aggregate 'product' generated in context 'catalog'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
### `check`
|
|
144
|
+
|
|
145
|
+
Checks architecture rules — exits `0` if clean, `1` if violations found. Designed for CI/CD.
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
node-hexa check <path> [--watch]
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# One-shot (CI)
|
|
153
|
+
node-hexa check .
|
|
154
|
+
|
|
155
|
+
# Watch mode (development)
|
|
156
|
+
node-hexa check . --watch
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Output:
|
|
160
|
+
```
|
|
161
|
+
✓ Architecture check passed
|
|
162
|
+
```
|
|
163
|
+
or:
|
|
164
|
+
```
|
|
165
|
+
✗ Architecture violations detected
|
|
166
|
+
|
|
167
|
+
[CRITICAL] Domain must not depend on infrastructure → UserEntity
|
|
168
|
+
[HIGH] Application must not depend on infrastructure → CreateUserUseCase
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
### `analyze`
|
|
174
|
+
|
|
175
|
+
Full analysis: layers, violations, bounded contexts, Mermaid diagram, and score.
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
node-hexa analyze <path>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
node-hexa analyze .
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
### `list`
|
|
188
|
+
|
|
189
|
+
Lists all bounded contexts and their components.
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
node-hexa list <path>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
node-hexa list .
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Output:
|
|
200
|
+
```
|
|
201
|
+
Bounded Contexts (2)
|
|
202
|
+
|
|
203
|
+
IAM
|
|
204
|
+
Entities : user.entity
|
|
205
|
+
Ports : user.repository.port
|
|
206
|
+
Use Cases : create-user.usecase
|
|
207
|
+
|
|
208
|
+
CATALOG
|
|
209
|
+
Entities : product.entity
|
|
210
|
+
Ports : product.repository.port
|
|
211
|
+
Use Cases : create-product.usecase
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
### `docs`
|
|
217
|
+
|
|
218
|
+
Generates an `architecture.md` at the project root with the Mermaid diagram, violations, and score.
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
node-hexa docs <path>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
node-hexa docs .
|
|
226
|
+
# Architecture documentation generated: ./architecture.md
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
### `graph`
|
|
232
|
+
|
|
233
|
+
Generates an `architecture.svg` dependency graph (requires `@mermaid-js/mermaid-cli`).
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
npm install -g @mermaid-js/mermaid-cli
|
|
237
|
+
node-hexa graph .
|
|
238
|
+
# Architecture graph generated: ./architecture.svg
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Configuration
|
|
244
|
+
|
|
245
|
+
`node-hexa.config.json` at the project root (created by `init`, all keys optional):
|
|
246
|
+
|
|
247
|
+
```json
|
|
248
|
+
{
|
|
249
|
+
"architecture": "hexagonal-ddd",
|
|
250
|
+
"strict": true,
|
|
251
|
+
"contextsDir": "src/contexts"
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
| Key | Type | Default | Description |
|
|
256
|
+
|---|---|---|---|
|
|
257
|
+
| `architecture` | `string` | required | Architecture type — `hexagonal-ddd` |
|
|
258
|
+
| `strict` | `boolean` | `true` | `false` silences `MEDIUM` violations |
|
|
259
|
+
| `contextsDir` | `string` | `"src/contexts"` | Path to bounded contexts directory |
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Violation rules
|
|
264
|
+
|
|
265
|
+
| Violation | Severity | Score penalty |
|
|
266
|
+
|---|---|---|
|
|
267
|
+
| Domain imports from infrastructure / adapter | `CRITICAL` | −25 pts |
|
|
268
|
+
| Domain imports from application | `CRITICAL` | −25 pts |
|
|
269
|
+
| Application imports from infrastructure / adapter | `HIGH` | −15 pts |
|
|
270
|
+
| Domain imports a framework (`@nestjs/*`, `prisma`, etc.) | `CRITICAL` | −25 pts |
|
|
271
|
+
|
|
272
|
+
Score = `100 − sum of penalties`, minimum 0.
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## License
|
|
277
|
+
|
|
278
|
+
`activate` command required for production use:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
node-hexa activate <your-license-key>
|
|
282
|
+
```
|