@forinda/kickjs-cli 1.3.1 → 1.4.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 (110) hide show
  1. package/dist/cli.d.ts +2 -0
  2. package/dist/cli.d.ts.map +1 -0
  3. package/dist/cli.js +1195 -2392
  4. package/dist/commands/add.d.ts +5 -0
  5. package/dist/commands/add.d.ts.map +1 -0
  6. package/dist/commands/custom.d.ts +56 -0
  7. package/dist/commands/custom.d.ts.map +1 -0
  8. package/dist/commands/generate.d.ts +3 -0
  9. package/dist/commands/generate.d.ts.map +1 -0
  10. package/dist/commands/info.d.ts +3 -0
  11. package/dist/commands/info.d.ts.map +1 -0
  12. package/dist/commands/init.d.ts +3 -0
  13. package/dist/commands/init.d.ts.map +1 -0
  14. package/dist/commands/inspect.d.ts +3 -0
  15. package/dist/commands/inspect.d.ts.map +1 -0
  16. package/dist/commands/remove.d.ts +3 -0
  17. package/dist/commands/remove.d.ts.map +1 -0
  18. package/dist/commands/run.d.ts +3 -0
  19. package/dist/commands/run.d.ts.map +1 -0
  20. package/dist/commands/tinker.d.ts +3 -0
  21. package/dist/commands/tinker.d.ts.map +1 -0
  22. package/dist/config-11ag0rJc.js +3097 -0
  23. package/dist/config.d.ts +131 -0
  24. package/dist/config.d.ts.map +1 -0
  25. package/dist/generators/adapter.d.ts +7 -0
  26. package/dist/generators/adapter.d.ts.map +1 -0
  27. package/dist/generators/config.d.ts +9 -0
  28. package/dist/generators/config.d.ts.map +1 -0
  29. package/dist/generators/controller.d.ts +11 -0
  30. package/dist/generators/controller.d.ts.map +1 -0
  31. package/dist/generators/dto.d.ts +11 -0
  32. package/dist/generators/dto.d.ts.map +1 -0
  33. package/dist/generators/guard.d.ts +11 -0
  34. package/dist/generators/guard.d.ts.map +1 -0
  35. package/dist/generators/job.d.ts +8 -0
  36. package/dist/generators/job.d.ts.map +1 -0
  37. package/dist/generators/middleware.d.ts +11 -0
  38. package/dist/generators/middleware.d.ts.map +1 -0
  39. package/dist/generators/module.d.ts +33 -0
  40. package/dist/generators/module.d.ts.map +1 -0
  41. package/dist/generators/patterns/cqrs.d.ts +3 -0
  42. package/dist/generators/patterns/cqrs.d.ts.map +1 -0
  43. package/dist/generators/patterns/ddd.d.ts +3 -0
  44. package/dist/generators/patterns/ddd.d.ts.map +1 -0
  45. package/dist/generators/patterns/index.d.ts +6 -0
  46. package/dist/generators/patterns/index.d.ts.map +1 -0
  47. package/dist/generators/patterns/minimal.d.ts +3 -0
  48. package/dist/generators/patterns/minimal.d.ts.map +1 -0
  49. package/dist/generators/patterns/rest.d.ts +3 -0
  50. package/dist/generators/patterns/rest.d.ts.map +1 -0
  51. package/dist/generators/patterns/types.d.ts +15 -0
  52. package/dist/generators/patterns/types.d.ts.map +1 -0
  53. package/dist/generators/project.d.ts +14 -0
  54. package/dist/generators/project.d.ts.map +1 -0
  55. package/dist/generators/remove-module.d.ts +12 -0
  56. package/dist/generators/remove-module.d.ts.map +1 -0
  57. package/dist/generators/resolver.d.ts +7 -0
  58. package/dist/generators/resolver.d.ts.map +1 -0
  59. package/dist/generators/scaffold.d.ts +20 -0
  60. package/dist/generators/scaffold.d.ts.map +1 -0
  61. package/dist/generators/service.d.ts +11 -0
  62. package/dist/generators/service.d.ts.map +1 -0
  63. package/dist/generators/templates/constants.d.ts +3 -0
  64. package/dist/generators/templates/constants.d.ts.map +1 -0
  65. package/dist/generators/templates/controller.d.ts +6 -0
  66. package/dist/generators/templates/controller.d.ts.map +1 -0
  67. package/dist/generators/templates/cqrs.d.ts +23 -0
  68. package/dist/generators/templates/cqrs.d.ts.map +1 -0
  69. package/dist/generators/templates/domain.d.ts +5 -0
  70. package/dist/generators/templates/domain.d.ts.map +1 -0
  71. package/dist/generators/templates/drizzle/index.d.ts +4 -0
  72. package/dist/generators/templates/drizzle/index.d.ts.map +1 -0
  73. package/dist/generators/templates/dtos.d.ts +5 -0
  74. package/dist/generators/templates/dtos.d.ts.map +1 -0
  75. package/dist/generators/templates/index.d.ts +14 -0
  76. package/dist/generators/templates/index.d.ts.map +1 -0
  77. package/dist/generators/templates/module-index.d.ts +13 -0
  78. package/dist/generators/templates/module-index.d.ts.map +1 -0
  79. package/dist/generators/templates/prisma/index.d.ts +3 -0
  80. package/dist/generators/templates/prisma/index.d.ts.map +1 -0
  81. package/dist/generators/templates/project-app.d.ts +9 -0
  82. package/dist/generators/templates/project-app.d.ts.map +1 -0
  83. package/dist/generators/templates/project-config.d.ts +23 -0
  84. package/dist/generators/templates/project-config.d.ts.map +1 -0
  85. package/dist/generators/templates/project-docs.d.ts +9 -0
  86. package/dist/generators/templates/project-docs.d.ts.map +1 -0
  87. package/dist/generators/templates/repository.d.ts +5 -0
  88. package/dist/generators/templates/repository.d.ts.map +1 -0
  89. package/dist/generators/templates/rest-service.d.ts +6 -0
  90. package/dist/generators/templates/rest-service.d.ts.map +1 -0
  91. package/dist/generators/templates/tests.d.ts +4 -0
  92. package/dist/generators/templates/tests.d.ts.map +1 -0
  93. package/dist/generators/templates/types.d.ts +20 -0
  94. package/dist/generators/templates/types.d.ts.map +1 -0
  95. package/dist/generators/templates/use-cases.d.ts +6 -0
  96. package/dist/generators/templates/use-cases.d.ts.map +1 -0
  97. package/dist/generators/test.d.ts +9 -0
  98. package/dist/generators/test.d.ts.map +1 -0
  99. package/dist/index.d.ts +12 -234
  100. package/dist/index.d.ts.map +1 -0
  101. package/dist/index.js +17 -2184
  102. package/dist/utils/fs.d.ts +11 -0
  103. package/dist/utils/fs.d.ts.map +1 -0
  104. package/dist/utils/naming.d.ts +18 -0
  105. package/dist/utils/naming.d.ts.map +1 -0
  106. package/dist/utils/resolve-out-dir.d.ts +25 -0
  107. package/dist/utils/resolve-out-dir.d.ts.map +1 -0
  108. package/dist/utils/shell.d.ts +3 -0
  109. package/dist/utils/shell.d.ts.map +1 -0
  110. package/package.json +6 -5
@@ -0,0 +1,3097 @@
1
+ import { dirname as Q, join as p, resolve as x } from "node:path";
2
+ import { createInterface as ee } from "node:readline";
3
+ import { access as F, mkdir as te, readFile as L, writeFile as N } from "node:fs/promises";
4
+ import { execSync as w } from "node:child_process";
5
+ import { readFileSync as re } from "node:fs";
6
+ import { fileURLToPath as oe } from "node:url";
7
+ var W = !1;
8
+ function st(r) {
9
+ W = r;
10
+ }
11
+ async function l(r, e) {
12
+ W || (await te(Q(r), { recursive: !0 }), await N(r, e, "utf-8"));
13
+ }
14
+ async function B(r) {
15
+ try {
16
+ return await F(r), !0;
17
+ } catch {
18
+ return !1;
19
+ }
20
+ }
21
+ function h(r) {
22
+ return r.replace(/[-_\s]+(.)?/g, (e, t) => t ? t.toUpperCase() : "").replace(/^(.)/, (e) => e.toUpperCase());
23
+ }
24
+ function P(r) {
25
+ const e = h(r);
26
+ return e.charAt(0).toLowerCase() + e.slice(1);
27
+ }
28
+ function y(r) {
29
+ return r.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
30
+ }
31
+ function Y(r) {
32
+ return r.endsWith("s") ? r : r.endsWith("x") || r.endsWith("z") || r.endsWith("sh") || r.endsWith("ch") ? r + "es" : r.endsWith("y") && !/[aeiou]y$/.test(r) ? r.slice(0, -1) + "ies" : r + "s";
33
+ }
34
+ function se(r) {
35
+ return r.endsWith("s") ? r : r.endsWith("x") || r.endsWith("z") || r.endsWith("sh") || r.endsWith("ch") ? r + "es" : r.endsWith("y") && !/[aeiou]y$/i.test(r) ? r.slice(0, -1) + "ies" : r + "s";
36
+ }
37
+ var ie = {
38
+ inmemory: "in-memory",
39
+ drizzle: "Drizzle",
40
+ prisma: "Prisma"
41
+ };
42
+ function H(r) {
43
+ return r.charAt(0).toUpperCase() + r.slice(1).replace(/-([a-z])/g, (e, t) => t.toUpperCase());
44
+ }
45
+ function ae(r) {
46
+ return r.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
47
+ }
48
+ function _(r) {
49
+ return ie[r] ?? H(r);
50
+ }
51
+ function K(r, e, t) {
52
+ const o = {
53
+ inmemory: `InMemory${r}Repository`,
54
+ drizzle: `Drizzle${r}Repository`,
55
+ prisma: `Prisma${r}Repository`
56
+ }, s = {
57
+ inmemory: `in-memory-${e}`,
58
+ drizzle: `drizzle-${e}`,
59
+ prisma: `prisma-${e}`
60
+ };
61
+ return {
62
+ repoClass: o[t] ?? `${H(t)}${r}Repository`,
63
+ repoFile: s[t] ?? `${ae(t)}-${e}`
64
+ };
65
+ }
66
+ function ne(r) {
67
+ const { pascal: e, kebab: t, plural: o = "", repo: s } = r, { repoClass: i, repoFile: n } = K(e, t, s);
68
+ return `/**
69
+ * ${e} Module
70
+ *
71
+ * Self-contained feature module following Domain-Driven Design (DDD).
72
+ * Registers dependencies in the DI container and declares HTTP routes.
73
+ *
74
+ * Structure:
75
+ * presentation/ — HTTP controllers (entry points)
76
+ * application/ — Use cases (orchestration) and DTOs (validation)
77
+ * domain/ — Entities, value objects, repository interfaces, domain services
78
+ * infrastructure/ — Repository implementations (currently ${_(s)})
79
+ */
80
+ import { Container, type AppModule, type ModuleRoutes } from '@forinda/kickjs-core'
81
+ import { buildRoutes } from '@forinda/kickjs-http'
82
+ import { ${e.toUpperCase()}_REPOSITORY } from './domain/repositories/${t}.repository'
83
+ import { ${i} } from './infrastructure/repositories/${n}.repository'
84
+ import { ${e}Controller } from './presentation/${t}.controller'
85
+
86
+ // Eagerly load decorated classes so @Service()/@Repository() decorators register in the DI container
87
+ import.meta.glob(
88
+ ['./domain/services/**/*.ts', './application/use-cases/**/*.ts', '!./**/*.test.ts'],
89
+ { eager: true },
90
+ )
91
+
92
+ export class ${e}Module implements AppModule {
93
+ /**
94
+ * Register module dependencies in the DI container.
95
+ * Bind repository interface tokens to their implementations here.
96
+ * Currently wired to ${_(s)}. To swap implementations, change the factory target.
97
+ */
98
+ register(container: Container): void {
99
+ container.registerFactory(${e.toUpperCase()}_REPOSITORY, () =>
100
+ container.resolve(${i}),
101
+ )
102
+ }
103
+
104
+ /**
105
+ * Declare HTTP routes for this module.
106
+ * The path is prefixed with the global apiPrefix and version (e.g. /api/v1/${o}).
107
+ * Passing 'controller' enables automatic OpenAPI spec generation via SwaggerAdapter.
108
+ */
109
+ routes(): ModuleRoutes {
110
+ return {
111
+ path: '/${o}',
112
+ router: buildRoutes(${e}Controller),
113
+ controller: ${e}Controller,
114
+ }
115
+ }
116
+ }
117
+ `;
118
+ }
119
+ function ce(r) {
120
+ const { pascal: e, kebab: t, plural: o = "", repo: s } = r, { repoClass: i, repoFile: n } = K(e, t, s);
121
+ return `/**
122
+ * ${e} Module
123
+ *
124
+ * REST module with a flat folder structure.
125
+ * Controller delegates to service, service wraps the repository.
126
+ *
127
+ * Structure:
128
+ * ${t}.controller.ts — HTTP routes (CRUD)
129
+ * ${t}.service.ts — Business logic
130
+ * ${t}.repository.ts — Repository interface
131
+ * ${n}.repository.ts — Repository implementation
132
+ * dtos/ — Request/response schemas
133
+ */
134
+ import { Container, type AppModule, type ModuleRoutes } from '@forinda/kickjs-core'
135
+ import { buildRoutes } from '@forinda/kickjs-http'
136
+ import { ${e.toUpperCase()}_REPOSITORY } from './${t}.repository'
137
+ import { ${i} } from './${n}.repository'
138
+ import { ${e}Controller } from './${t}.controller'
139
+
140
+ // Eagerly load decorated classes so @Service()/@Repository() decorators register in the DI container
141
+ import.meta.glob(['./**/*.service.ts', './**/*.repository.ts', '!./**/*.test.ts'], { eager: true })
142
+
143
+ export class ${e}Module implements AppModule {
144
+ register(container: Container): void {
145
+ container.registerFactory(${e.toUpperCase()}_REPOSITORY, () =>
146
+ container.resolve(${i}),
147
+ )
148
+ }
149
+
150
+ routes(): ModuleRoutes {
151
+ return {
152
+ path: '/${o}',
153
+ router: buildRoutes(${e}Controller),
154
+ controller: ${e}Controller,
155
+ }
156
+ }
157
+ }
158
+ `;
159
+ }
160
+ function de(r) {
161
+ const { pascal: e, kebab: t, plural: o = "" } = r;
162
+ return `import { type AppModule, type ModuleRoutes } from '@forinda/kickjs-core'
163
+ import { buildRoutes } from '@forinda/kickjs-http'
164
+ import { ${e}Controller } from './${t}.controller'
165
+
166
+ export class ${e}Module implements AppModule {
167
+ routes(): ModuleRoutes {
168
+ return {
169
+ path: '/${o}',
170
+ router: buildRoutes(${e}Controller),
171
+ controller: ${e}Controller,
172
+ }
173
+ }
174
+ }
175
+ `;
176
+ }
177
+ function pe(r) {
178
+ const { pascal: e, kebab: t, plural: o = "", pluralPascal: s = "" } = r;
179
+ return `import { Controller, Get, Post, Put, Delete, Autowired, ApiQueryParams } from '@forinda/kickjs-core'
180
+ import type { RequestContext } from '@forinda/kickjs-http'
181
+ import { ApiTags } from '@forinda/kickjs-swagger'
182
+ import { Create${e}UseCase } from '../application/use-cases/create-${t}.use-case'
183
+ import { Get${e}UseCase } from '../application/use-cases/get-${t}.use-case'
184
+ import { List${s}UseCase } from '../application/use-cases/list-${o}.use-case'
185
+ import { Update${e}UseCase } from '../application/use-cases/update-${t}.use-case'
186
+ import { Delete${e}UseCase } from '../application/use-cases/delete-${t}.use-case'
187
+ import { create${e}Schema } from '../application/dtos/create-${t}.dto'
188
+ import { update${e}Schema } from '../application/dtos/update-${t}.dto'
189
+ import { ${e.toUpperCase()}_QUERY_CONFIG } from '../constants'
190
+
191
+ @Controller()
192
+ export class ${e}Controller {
193
+ @Autowired() private create${e}UseCase!: Create${e}UseCase
194
+ @Autowired() private get${e}UseCase!: Get${e}UseCase
195
+ @Autowired() private list${s}UseCase!: List${s}UseCase
196
+ @Autowired() private update${e}UseCase!: Update${e}UseCase
197
+ @Autowired() private delete${e}UseCase!: Delete${e}UseCase
198
+
199
+ @Get('/')
200
+ @ApiTags('${e}')
201
+ @ApiQueryParams(${e.toUpperCase()}_QUERY_CONFIG)
202
+ async list(ctx: RequestContext) {
203
+ return ctx.paginate(
204
+ (parsed) => this.list${s}UseCase.execute(parsed),
205
+ ${e.toUpperCase()}_QUERY_CONFIG,
206
+ )
207
+ }
208
+
209
+ @Get('/:id')
210
+ @ApiTags('${e}')
211
+ async getById(ctx: RequestContext) {
212
+ const result = await this.get${e}UseCase.execute(ctx.params.id)
213
+ if (!result) return ctx.notFound('${e} not found')
214
+ ctx.json(result)
215
+ }
216
+
217
+ @Post('/', { body: create${e}Schema, name: 'Create${e}' })
218
+ @ApiTags('${e}')
219
+ async create(ctx: RequestContext) {
220
+ const result = await this.create${e}UseCase.execute(ctx.body)
221
+ ctx.created(result)
222
+ }
223
+
224
+ @Put('/:id', { body: update${e}Schema, name: 'Update${e}' })
225
+ @ApiTags('${e}')
226
+ async update(ctx: RequestContext) {
227
+ const result = await this.update${e}UseCase.execute(ctx.params.id, ctx.body)
228
+ ctx.json(result)
229
+ }
230
+
231
+ @Delete('/:id')
232
+ @ApiTags('${e}')
233
+ async remove(ctx: RequestContext) {
234
+ await this.delete${e}UseCase.execute(ctx.params.id)
235
+ ctx.noContent()
236
+ }
237
+ }
238
+ `;
239
+ }
240
+ function le(r) {
241
+ const { pascal: e, kebab: t, plural: o = "", pluralPascal: s = "" } = r, i = e.charAt(0).toLowerCase() + e.slice(1);
242
+ return `import { Controller, Get, Post, Put, Delete, Autowired, ApiQueryParams } from '@forinda/kickjs-core'
243
+ import type { RequestContext } from '@forinda/kickjs-http'
244
+ import { ApiTags } from '@forinda/kickjs-swagger'
245
+ import { ${e}Service } from './${t}.service'
246
+ import { create${e}Schema } from './dtos/create-${t}.dto'
247
+ import { update${e}Schema } from './dtos/update-${t}.dto'
248
+ import { ${e.toUpperCase()}_QUERY_CONFIG } from './${t}.constants'
249
+
250
+ @Controller()
251
+ export class ${e}Controller {
252
+ @Autowired() private ${i}Service!: ${e}Service
253
+
254
+ @Get('/')
255
+ @ApiTags('${e}')
256
+ @ApiQueryParams(${e.toUpperCase()}_QUERY_CONFIG)
257
+ async list(ctx: RequestContext) {
258
+ return ctx.paginate(
259
+ (parsed) => this.${i}Service.findPaginated(parsed),
260
+ ${e.toUpperCase()}_QUERY_CONFIG,
261
+ )
262
+ }
263
+
264
+ @Get('/:id')
265
+ @ApiTags('${e}')
266
+ async getById(ctx: RequestContext) {
267
+ const result = await this.${i}Service.findById(ctx.params.id)
268
+ if (!result) return ctx.notFound('${e} not found')
269
+ ctx.json(result)
270
+ }
271
+
272
+ @Post('/', { body: create${e}Schema, name: 'Create${e}' })
273
+ @ApiTags('${e}')
274
+ async create(ctx: RequestContext) {
275
+ const result = await this.${i}Service.create(ctx.body)
276
+ ctx.created(result)
277
+ }
278
+
279
+ @Put('/:id', { body: update${e}Schema, name: 'Update${e}' })
280
+ @ApiTags('${e}')
281
+ async update(ctx: RequestContext) {
282
+ const result = await this.${i}Service.update(ctx.params.id, ctx.body)
283
+ ctx.json(result)
284
+ }
285
+
286
+ @Delete('/:id')
287
+ @ApiTags('${e}')
288
+ async remove(ctx: RequestContext) {
289
+ await this.${i}Service.delete(ctx.params.id)
290
+ ctx.noContent()
291
+ }
292
+ }
293
+ `;
294
+ }
295
+ function ue(r) {
296
+ const { pascal: e } = r;
297
+ return `import type { QueryParamsConfig } from '@forinda/kickjs-core'
298
+
299
+ export const ${e.toUpperCase()}_QUERY_CONFIG: QueryParamsConfig = {
300
+ filterable: ['name'],
301
+ sortable: ['name', 'createdAt'],
302
+ searchable: ['name'],
303
+ }
304
+ `;
305
+ }
306
+ function T(r) {
307
+ const { pascal: e, kebab: t } = r;
308
+ return `import { z } from 'zod'
309
+
310
+ /**
311
+ * Create ${e} DTO — Zod schema for validating POST request bodies.
312
+ * This schema is passed to @Post('/', { body: create${e}Schema }) for automatic validation.
313
+ * It also generates OpenAPI request body docs when SwaggerAdapter is used.
314
+ *
315
+ * Add more fields as needed. Supported Zod types:
316
+ * z.string(), z.number(), z.boolean(), z.enum([...]),
317
+ * z.array(), z.object(), .optional(), .default(), .transform()
318
+ */
319
+ export const create${e}Schema = z.object({
320
+ name: z.string().min(1, 'Name is required').max(200),
321
+ })
322
+
323
+ export type Create${e}DTO = z.infer<typeof create${e}Schema>
324
+ `;
325
+ }
326
+ function O(r) {
327
+ const { pascal: e, kebab: t } = r;
328
+ return `import { z } from 'zod'
329
+
330
+ export const update${e}Schema = z.object({
331
+ name: z.string().min(1).max(200).optional(),
332
+ })
333
+
334
+ export type Update${e}DTO = z.infer<typeof update${e}Schema>
335
+ `;
336
+ }
337
+ function I(r) {
338
+ const { pascal: e, kebab: t } = r;
339
+ return `export interface ${e}ResponseDTO {
340
+ id: string
341
+ name: string
342
+ createdAt: string
343
+ updatedAt: string
344
+ }
345
+ `;
346
+ }
347
+ function me(r) {
348
+ const { pascal: e, kebab: t, plural: o = "", pluralPascal: s = "" } = r;
349
+ return [
350
+ {
351
+ file: `create-${t}.use-case.ts`,
352
+ content: `/**
353
+ * Create ${e} Use Case
354
+ *
355
+ * Application layer — orchestrates a single business operation.
356
+ * Use cases are thin: validate input (via DTO), call domain/repo, return response.
357
+ * Keep business rules in the domain service, not here.
358
+ */
359
+ import { Service, Inject } from '@forinda/kickjs-core'
360
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../../domain/repositories/${t}.repository'
361
+ import type { Create${e}DTO } from '../dtos/create-${t}.dto'
362
+ import type { ${e}ResponseDTO } from '../dtos/${t}-response.dto'
363
+
364
+ @Service()
365
+ export class Create${e}UseCase {
366
+ constructor(
367
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
368
+ ) {}
369
+
370
+ async execute(dto: Create${e}DTO): Promise<${e}ResponseDTO> {
371
+ return this.repo.create(dto)
372
+ }
373
+ }
374
+ `
375
+ },
376
+ {
377
+ file: `get-${t}.use-case.ts`,
378
+ content: `import { Service, Inject } from '@forinda/kickjs-core'
379
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../../domain/repositories/${t}.repository'
380
+ import type { ${e}ResponseDTO } from '../dtos/${t}-response.dto'
381
+
382
+ @Service()
383
+ export class Get${e}UseCase {
384
+ constructor(
385
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
386
+ ) {}
387
+
388
+ async execute(id: string): Promise<${e}ResponseDTO | null> {
389
+ return this.repo.findById(id)
390
+ }
391
+ }
392
+ `
393
+ },
394
+ {
395
+ file: `list-${o}.use-case.ts`,
396
+ content: `import { Service, Inject } from '@forinda/kickjs-core'
397
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../../domain/repositories/${t}.repository'
398
+ import type { ParsedQuery } from '@forinda/kickjs-http'
399
+
400
+ @Service()
401
+ export class List${s}UseCase {
402
+ constructor(
403
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
404
+ ) {}
405
+
406
+ async execute(parsed: ParsedQuery) {
407
+ return this.repo.findPaginated(parsed)
408
+ }
409
+ }
410
+ `
411
+ },
412
+ {
413
+ file: `update-${t}.use-case.ts`,
414
+ content: `import { Service, Inject } from '@forinda/kickjs-core'
415
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../../domain/repositories/${t}.repository'
416
+ import type { Update${e}DTO } from '../dtos/update-${t}.dto'
417
+ import type { ${e}ResponseDTO } from '../dtos/${t}-response.dto'
418
+
419
+ @Service()
420
+ export class Update${e}UseCase {
421
+ constructor(
422
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
423
+ ) {}
424
+
425
+ async execute(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO> {
426
+ return this.repo.update(id, dto)
427
+ }
428
+ }
429
+ `
430
+ },
431
+ {
432
+ file: `delete-${t}.use-case.ts`,
433
+ content: `import { Service, Inject } from '@forinda/kickjs-core'
434
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../../domain/repositories/${t}.repository'
435
+
436
+ @Service()
437
+ export class Delete${e}UseCase {
438
+ constructor(
439
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
440
+ ) {}
441
+
442
+ async execute(id: string): Promise<void> {
443
+ await this.repo.delete(id)
444
+ }
445
+ }
446
+ `
447
+ }
448
+ ];
449
+ }
450
+ function S(r) {
451
+ const { pascal: e, kebab: t, dtoPrefix: o = "../../application/dtos" } = r;
452
+ return `/**
453
+ * ${e} Repository Interface
454
+ *
455
+ * Defines the contract for data access.
456
+ * The interface declares what operations are available;
457
+ * implementations (in-memory, Drizzle, Prisma) fulfill the contract.
458
+ *
459
+ * To swap implementations, change the factory in the module's register() method.
460
+ */
461
+ import type { ${e}ResponseDTO } from '${o}/${t}-response.dto'
462
+ import type { Create${e}DTO } from '${o}/create-${t}.dto'
463
+ import type { Update${e}DTO } from '${o}/update-${t}.dto'
464
+ import type { ParsedQuery } from '@forinda/kickjs-http'
465
+
466
+ export interface I${e}Repository {
467
+ findById(id: string): Promise<${e}ResponseDTO | null>
468
+ findAll(): Promise<${e}ResponseDTO[]>
469
+ findPaginated(parsed: ParsedQuery): Promise<{ data: ${e}ResponseDTO[]; total: number }>
470
+ create(dto: Create${e}DTO): Promise<${e}ResponseDTO>
471
+ update(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO>
472
+ delete(id: string): Promise<void>
473
+ }
474
+
475
+ export const ${e.toUpperCase()}_REPOSITORY = Symbol('I${e}Repository')
476
+ `;
477
+ }
478
+ function A(r) {
479
+ const { pascal: e, kebab: t, repoPrefix: o = "../../domain/repositories", dtoPrefix: s = "../../application/dtos" } = r;
480
+ return `/**
481
+ * In-Memory ${e} Repository
482
+ *
483
+ * Implements the repository interface using a Map.
484
+ * Useful for prototyping and testing. Replace with a database implementation
485
+ * (Drizzle, Prisma, etc.) for production use.
486
+ *
487
+ * @Repository() registers this class in the DI container as a singleton.
488
+ */
489
+ import { randomUUID } from 'node:crypto'
490
+ import { Repository, HttpException } from '@forinda/kickjs-core'
491
+ import type { ParsedQuery } from '@forinda/kickjs-http'
492
+ import type { I${e}Repository } from '${o}/${t}.repository'
493
+ import type { ${e}ResponseDTO } from '${s}/${t}-response.dto'
494
+ import type { Create${e}DTO } from '${s}/create-${t}.dto'
495
+ import type { Update${e}DTO } from '${s}/update-${t}.dto'
496
+
497
+ @Repository()
498
+ export class InMemory${e}Repository implements I${e}Repository {
499
+ private store = new Map<string, ${e}ResponseDTO>()
500
+
501
+ async findById(id: string): Promise<${e}ResponseDTO | null> {
502
+ return this.store.get(id) ?? null
503
+ }
504
+
505
+ async findAll(): Promise<${e}ResponseDTO[]> {
506
+ return Array.from(this.store.values())
507
+ }
508
+
509
+ async findPaginated(parsed: ParsedQuery): Promise<{ data: ${e}ResponseDTO[]; total: number }> {
510
+ const all = Array.from(this.store.values())
511
+ const data = all.slice(parsed.pagination.offset, parsed.pagination.offset + parsed.pagination.limit)
512
+ return { data, total: all.length }
513
+ }
514
+
515
+ async create(dto: Create${e}DTO): Promise<${e}ResponseDTO> {
516
+ const now = new Date().toISOString()
517
+ const entity: ${e}ResponseDTO = {
518
+ id: randomUUID(),
519
+ name: dto.name,
520
+ createdAt: now,
521
+ updatedAt: now,
522
+ }
523
+ this.store.set(entity.id, entity)
524
+ return entity
525
+ }
526
+
527
+ async update(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO> {
528
+ const existing = this.store.get(id)
529
+ if (!existing) throw HttpException.notFound('${e} not found')
530
+ const updated = { ...existing, ...dto, updatedAt: new Date().toISOString() }
531
+ this.store.set(id, updated)
532
+ return updated
533
+ }
534
+
535
+ async delete(id: string): Promise<void> {
536
+ if (!this.store.has(id)) throw HttpException.notFound('${e} not found')
537
+ this.store.delete(id)
538
+ }
539
+ }
540
+ `;
541
+ }
542
+ function j(r) {
543
+ const { pascal: e, kebab: t, repoType: o = "", repoPrefix: s = "../../domain/repositories", dtoPrefix: i = "../../application/dtos" } = r, n = o.charAt(0).toUpperCase() + o.slice(1).replace(/-([a-z])/g, (a, c) => c.toUpperCase());
544
+ return `/**
545
+ * ${n} ${e} Repository
546
+ *
547
+ * Stub implementation for a custom '${o}' repository.
548
+ * Implements the repository interface using an in-memory Map as a placeholder.
549
+ *
550
+ * TODO: Replace the in-memory Map with your ${o} data-access logic.
551
+ * See I${e}Repository for the interface contract.
552
+ *
553
+ * @Repository() registers this class in the DI container as a singleton.
554
+ */
555
+ import { randomUUID } from 'node:crypto'
556
+ import { Repository, HttpException } from '@forinda/kickjs-core'
557
+ import type { ParsedQuery } from '@forinda/kickjs-http'
558
+ import type { I${e}Repository } from '${s}/${t}.repository'
559
+ import type { ${e}ResponseDTO } from '${i}/${t}-response.dto'
560
+ import type { Create${e}DTO } from '${i}/create-${t}.dto'
561
+ import type { Update${e}DTO } from '${i}/update-${t}.dto'
562
+
563
+ @Repository()
564
+ export class ${n}${e}Repository implements I${e}Repository {
565
+ // TODO: Replace with your ${o} client/connection
566
+ private store = new Map<string, ${e}ResponseDTO>()
567
+
568
+ async findById(id: string): Promise<${e}ResponseDTO | null> {
569
+ // TODO: Implement with ${o}
570
+ return this.store.get(id) ?? null
571
+ }
572
+
573
+ async findAll(): Promise<${e}ResponseDTO[]> {
574
+ // TODO: Implement with ${o}
575
+ return Array.from(this.store.values())
576
+ }
577
+
578
+ async findPaginated(parsed: ParsedQuery): Promise<{ data: ${e}ResponseDTO[]; total: number }> {
579
+ // TODO: Implement with ${o}
580
+ const all = Array.from(this.store.values())
581
+ const data = all.slice(parsed.pagination.offset, parsed.pagination.offset + parsed.pagination.limit)
582
+ return { data, total: all.length }
583
+ }
584
+
585
+ async create(dto: Create${e}DTO): Promise<${e}ResponseDTO> {
586
+ // TODO: Implement with ${o}
587
+ const now = new Date().toISOString()
588
+ const entity: ${e}ResponseDTO = {
589
+ id: randomUUID(),
590
+ name: dto.name,
591
+ createdAt: now,
592
+ updatedAt: now,
593
+ }
594
+ this.store.set(entity.id, entity)
595
+ return entity
596
+ }
597
+
598
+ async update(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO> {
599
+ // TODO: Implement with ${o}
600
+ const existing = this.store.get(id)
601
+ if (!existing) throw HttpException.notFound('${e} not found')
602
+ const updated = { ...existing, ...dto, updatedAt: new Date().toISOString() }
603
+ this.store.set(id, updated)
604
+ return updated
605
+ }
606
+
607
+ async delete(id: string): Promise<void> {
608
+ // TODO: Implement with ${o}
609
+ if (!this.store.has(id)) throw HttpException.notFound('${e} not found')
610
+ this.store.delete(id)
611
+ }
612
+ }
613
+ `;
614
+ }
615
+ function fe(r) {
616
+ const { pascal: e, kebab: t } = r;
617
+ return `/**
618
+ * ${e} Domain Service
619
+ *
620
+ * Domain layer — contains business rules that don't belong to a single entity.
621
+ * Use this for cross-entity logic, validation rules, and domain invariants.
622
+ * Keep it free of HTTP/framework concerns.
623
+ */
624
+ import { Service, Inject, HttpException } from '@forinda/kickjs-core'
625
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../repositories/${t}.repository'
626
+
627
+ @Service()
628
+ export class ${e}DomainService {
629
+ constructor(
630
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
631
+ ) {}
632
+
633
+ async ensureExists(id: string): Promise<void> {
634
+ const entity = await this.repo.findById(id)
635
+ if (!entity) {
636
+ throw HttpException.notFound('${e} not found')
637
+ }
638
+ }
639
+ }
640
+ `;
641
+ }
642
+ function $e(r) {
643
+ const { pascal: e, kebab: t } = r;
644
+ return `/**
645
+ * ${e} Entity
646
+ *
647
+ * Domain layer — the core business object.
648
+ * Uses a private constructor with static factory methods (create, reconstitute)
649
+ * to enforce invariants. Properties are accessed via getters to maintain encapsulation.
650
+ *
651
+ * Patterns used:
652
+ * - Private constructor: prevents direct instantiation
653
+ * - create(): factory for new entities (generates ID, sets timestamps)
654
+ * - reconstitute(): factory for rebuilding from persistence (no side effects)
655
+ * - changeName(): mutation method that enforces business rules
656
+ */
657
+ import { ${e}Id } from '../value-objects/${t}-id.vo'
658
+
659
+ interface ${e}Props {
660
+ id: ${e}Id
661
+ name: string
662
+ createdAt: Date
663
+ updatedAt: Date
664
+ }
665
+
666
+ export class ${e} {
667
+ private constructor(private props: ${e}Props) {}
668
+
669
+ static create(params: { name: string }): ${e} {
670
+ const now = new Date()
671
+ return new ${e}({
672
+ id: ${e}Id.create(),
673
+ name: params.name,
674
+ createdAt: now,
675
+ updatedAt: now,
676
+ })
677
+ }
678
+
679
+ static reconstitute(props: ${e}Props): ${e} {
680
+ return new ${e}(props)
681
+ }
682
+
683
+ get id(): ${e}Id {
684
+ return this.props.id
685
+ }
686
+ get name(): string {
687
+ return this.props.name
688
+ }
689
+ get createdAt(): Date {
690
+ return this.props.createdAt
691
+ }
692
+ get updatedAt(): Date {
693
+ return this.props.updatedAt
694
+ }
695
+
696
+ changeName(name: string): void {
697
+ if (!name || name.trim().length === 0) {
698
+ throw new Error('Name cannot be empty')
699
+ }
700
+ this.props.name = name.trim()
701
+ this.props.updatedAt = new Date()
702
+ }
703
+
704
+ toJSON() {
705
+ return {
706
+ id: this.props.id.toString(),
707
+ name: this.props.name,
708
+ createdAt: this.props.createdAt.toISOString(),
709
+ updatedAt: this.props.updatedAt.toISOString(),
710
+ }
711
+ }
712
+ }
713
+ `;
714
+ }
715
+ function ye(r) {
716
+ const { pascal: e, kebab: t } = r;
717
+ return `/**
718
+ * ${e} ID Value Object
719
+ *
720
+ * Domain layer — wraps a primitive ID with type safety and validation.
721
+ * Value objects are immutable and compared by value, not reference.
722
+ *
723
+ * ${e}Id.create() — generate a new UUID
724
+ * ${e}Id.from(id) — wrap an existing ID string (validates non-empty)
725
+ * id.equals(other) — compare two IDs by value
726
+ */
727
+ import { randomUUID } from 'node:crypto'
728
+
729
+ export class ${e}Id {
730
+ private constructor(private readonly value: string) {}
731
+
732
+ static create(): ${e}Id {
733
+ return new ${e}Id(randomUUID())
734
+ }
735
+
736
+ static from(id: string): ${e}Id {
737
+ if (!id || id.trim().length === 0) {
738
+ throw new Error('${e}Id cannot be empty')
739
+ }
740
+ return new ${e}Id(id)
741
+ }
742
+
743
+ toString(): string {
744
+ return this.value
745
+ }
746
+
747
+ equals(other: ${e}Id): boolean {
748
+ return this.value === other.value
749
+ }
750
+ }
751
+ `;
752
+ }
753
+ function E(r) {
754
+ const { pascal: e, kebab: t, plural: o = "" } = r;
755
+ return `import { describe, it, expect, beforeEach } from 'vitest'
756
+ import { Container } from '@forinda/kickjs-core'
757
+
758
+ describe('${e}Controller', () => {
759
+ beforeEach(() => {
760
+ Container.reset()
761
+ })
762
+
763
+ it('should be defined', () => {
764
+ expect(true).toBe(true)
765
+ })
766
+
767
+ describe('POST /${o}', () => {
768
+ it('should create a new ${t}', async () => {
769
+ // TODO: Set up test module, call create endpoint, assert 201
770
+ expect(true).toBe(true)
771
+ })
772
+ })
773
+
774
+ describe('GET /${o}', () => {
775
+ it('should return paginated ${o}', async () => {
776
+ // TODO: Set up test module, call list endpoint, assert { data, meta }
777
+ expect(true).toBe(true)
778
+ })
779
+ })
780
+
781
+ describe('GET /${o}/:id', () => {
782
+ it('should return a ${t} by id', async () => {
783
+ // TODO: Create a ${t}, then fetch by id, assert match
784
+ expect(true).toBe(true)
785
+ })
786
+
787
+ it('should return 404 for non-existent ${t}', async () => {
788
+ // TODO: Fetch non-existent id, assert 404
789
+ expect(true).toBe(true)
790
+ })
791
+ })
792
+
793
+ describe('PUT /${o}/:id', () => {
794
+ it('should update an existing ${t}', async () => {
795
+ // TODO: Create, update, assert changes
796
+ expect(true).toBe(true)
797
+ })
798
+ })
799
+
800
+ describe('DELETE /${o}/:id', () => {
801
+ it('should delete a ${t}', async () => {
802
+ // TODO: Create, delete, assert gone
803
+ expect(true).toBe(true)
804
+ })
805
+ })
806
+ })
807
+ `;
808
+ }
809
+ function U(r) {
810
+ const { pascal: e, kebab: t, plural: o = "", repoPrefix: s = `../infrastructure/repositories/in-memory-${t}.repository` } = r;
811
+ return `import { describe, it, expect, beforeEach } from 'vitest'
812
+ import { InMemory${e}Repository } from '${s}'
813
+
814
+ describe('InMemory${e}Repository', () => {
815
+ let repo: InMemory${e}Repository
816
+
817
+ beforeEach(() => {
818
+ repo = new InMemory${e}Repository()
819
+ })
820
+
821
+ it('should create and retrieve a ${t}', async () => {
822
+ const created = await repo.create({ name: 'Test ${e}' })
823
+ expect(created).toBeDefined()
824
+ expect(created.name).toBe('Test ${e}')
825
+ expect(created.id).toBeDefined()
826
+
827
+ const found = await repo.findById(created.id)
828
+ expect(found).toEqual(created)
829
+ })
830
+
831
+ it('should return null for non-existent id', async () => {
832
+ const found = await repo.findById('non-existent')
833
+ expect(found).toBeNull()
834
+ })
835
+
836
+ it('should list all ${o}', async () => {
837
+ await repo.create({ name: '${e} 1' })
838
+ await repo.create({ name: '${e} 2' })
839
+
840
+ const all = await repo.findAll()
841
+ expect(all).toHaveLength(2)
842
+ })
843
+
844
+ it('should return paginated results', async () => {
845
+ await repo.create({ name: '${e} 1' })
846
+ await repo.create({ name: '${e} 2' })
847
+ await repo.create({ name: '${e} 3' })
848
+
849
+ const result = await repo.findPaginated({
850
+ filters: [],
851
+ sort: [],
852
+ search: '',
853
+ pagination: { page: 1, limit: 2, offset: 0 },
854
+ })
855
+
856
+ expect(result.data).toHaveLength(2)
857
+ expect(result.total).toBe(3)
858
+ })
859
+
860
+ it('should update a ${t}', async () => {
861
+ const created = await repo.create({ name: 'Original' })
862
+ const updated = await repo.update(created.id, { name: 'Updated' })
863
+ expect(updated.name).toBe('Updated')
864
+ })
865
+
866
+ it('should delete a ${t}', async () => {
867
+ const created = await repo.create({ name: 'To Delete' })
868
+ await repo.delete(created.id)
869
+ const found = await repo.findById(created.id)
870
+ expect(found).toBeNull()
871
+ })
872
+ })
873
+ `;
874
+ }
875
+ function he(r) {
876
+ const { pascal: e, kebab: t } = r;
877
+ return `import { Service, Inject, HttpException } from '@forinda/kickjs-core'
878
+ import type { ParsedQuery } from '@forinda/kickjs-http'
879
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from './${t}.repository'
880
+ import type { ${e}ResponseDTO } from './dtos/${t}-response.dto'
881
+ import type { Create${e}DTO } from './dtos/create-${t}.dto'
882
+ import type { Update${e}DTO } from './dtos/update-${t}.dto'
883
+
884
+ @Service()
885
+ export class ${e}Service {
886
+ constructor(
887
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
888
+ ) {}
889
+
890
+ async findById(id: string): Promise<${e}ResponseDTO | null> {
891
+ return this.repo.findById(id)
892
+ }
893
+
894
+ async findAll(): Promise<${e}ResponseDTO[]> {
895
+ return this.repo.findAll()
896
+ }
897
+
898
+ async findPaginated(parsed: ParsedQuery) {
899
+ return this.repo.findPaginated(parsed)
900
+ }
901
+
902
+ async create(dto: Create${e}DTO): Promise<${e}ResponseDTO> {
903
+ return this.repo.create(dto)
904
+ }
905
+
906
+ async update(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO> {
907
+ return this.repo.update(id, dto)
908
+ }
909
+
910
+ async delete(id: string): Promise<void> {
911
+ await this.repo.delete(id)
912
+ }
913
+ }
914
+ `;
915
+ }
916
+ function J(r) {
917
+ const { pascal: e } = r;
918
+ return `import type { QueryFieldConfig } from '@forinda/kickjs-http'
919
+
920
+ export const ${e.toUpperCase()}_QUERY_CONFIG: QueryFieldConfig = {
921
+ filterable: ['name'],
922
+ sortable: ['name', 'createdAt'],
923
+ searchable: ['name'],
924
+ }
925
+ `;
926
+ }
927
+ function ge(r) {
928
+ const { pascal: e, kebab: t, plural: o = "", repo: s } = r, i = {
929
+ inmemory: `InMemory${e}Repository`,
930
+ drizzle: `Drizzle${e}Repository`,
931
+ prisma: `Prisma${e}Repository`
932
+ }, n = {
933
+ inmemory: `in-memory-${t}`,
934
+ drizzle: `drizzle-${t}`,
935
+ prisma: `prisma-${t}`
936
+ }, a = i[s] ?? i.inmemory, c = n[s] ?? n.inmemory;
937
+ return `/**
938
+ * ${e} Module — CQRS Pattern
939
+ *
940
+ * Separates read (queries) and write (commands) operations.
941
+ * Events are emitted after state changes and can be handled via
942
+ * WebSocket broadcasts, queue jobs, or ETL pipelines.
943
+ *
944
+ * Structure:
945
+ * commands/ — Write operations (create, update, delete)
946
+ * queries/ — Read operations (get, list)
947
+ * events/ — Domain events + handlers (WS broadcast, queue dispatch)
948
+ * dtos/ — Request/response schemas
949
+ */
950
+ import { Container, type AppModule, type ModuleRoutes } from '@forinda/kickjs-core'
951
+ import { buildRoutes } from '@forinda/kickjs-http'
952
+ import { ${e.toUpperCase()}_REPOSITORY } from './${t}.repository'
953
+ import { ${a} } from './${c}.repository'
954
+ import { ${e}Controller } from './${t}.controller'
955
+
956
+ // Eagerly load decorated classes
957
+ import.meta.glob(
958
+ [
959
+ './commands/**/*.ts',
960
+ './queries/**/*.ts',
961
+ './events/**/*.ts',
962
+ '!./**/*.test.ts',
963
+ ],
964
+ { eager: true },
965
+ )
966
+
967
+ export class ${e}Module implements AppModule {
968
+ register(container: Container): void {
969
+ container.registerFactory(${e.toUpperCase()}_REPOSITORY, () =>
970
+ container.resolve(${a}),
971
+ )
972
+ }
973
+
974
+ routes(): ModuleRoutes {
975
+ return {
976
+ path: '/${o}',
977
+ router: buildRoutes(${e}Controller),
978
+ controller: ${e}Controller,
979
+ }
980
+ }
981
+ }
982
+ `;
983
+ }
984
+ function ke(r) {
985
+ const { pascal: e, kebab: t, plural: o = "", pluralPascal: s = "" } = r;
986
+ return `import { Controller, Get, Post, Put, Delete, Autowired, ApiQueryParams } from '@forinda/kickjs-core'
987
+ import type { RequestContext } from '@forinda/kickjs-http'
988
+ import { ApiTags } from '@forinda/kickjs-swagger'
989
+ import { Create${e}Command } from './commands/create-${t}.command'
990
+ import { Update${e}Command } from './commands/update-${t}.command'
991
+ import { Delete${e}Command } from './commands/delete-${t}.command'
992
+ import { Get${e}Query } from './queries/get-${t}.query'
993
+ import { List${s}Query } from './queries/list-${o}.query'
994
+ import { create${e}Schema } from './dtos/create-${t}.dto'
995
+ import { update${e}Schema } from './dtos/update-${t}.dto'
996
+ import { ${e.toUpperCase()}_QUERY_CONFIG } from './${t}.constants'
997
+
998
+ @Controller()
999
+ export class ${e}Controller {
1000
+ @Autowired() private create${e}Command!: Create${e}Command
1001
+ @Autowired() private update${e}Command!: Update${e}Command
1002
+ @Autowired() private delete${e}Command!: Delete${e}Command
1003
+ @Autowired() private get${e}Query!: Get${e}Query
1004
+ @Autowired() private list${s}Query!: List${s}Query
1005
+
1006
+ @Get('/')
1007
+ @ApiTags('${e}')
1008
+ @ApiQueryParams(${e.toUpperCase()}_QUERY_CONFIG)
1009
+ async list(ctx: RequestContext) {
1010
+ return ctx.paginate(
1011
+ (parsed) => this.list${s}Query.execute(parsed),
1012
+ ${e.toUpperCase()}_QUERY_CONFIG,
1013
+ )
1014
+ }
1015
+
1016
+ @Get('/:id')
1017
+ @ApiTags('${e}')
1018
+ async getById(ctx: RequestContext) {
1019
+ const result = await this.get${e}Query.execute(ctx.params.id)
1020
+ if (!result) return ctx.notFound('${e} not found')
1021
+ ctx.json(result)
1022
+ }
1023
+
1024
+ @Post('/', { body: create${e}Schema, name: 'Create${e}' })
1025
+ @ApiTags('${e}')
1026
+ async create(ctx: RequestContext) {
1027
+ const result = await this.create${e}Command.execute(ctx.body)
1028
+ ctx.created(result)
1029
+ }
1030
+
1031
+ @Put('/:id', { body: update${e}Schema, name: 'Update${e}' })
1032
+ @ApiTags('${e}')
1033
+ async update(ctx: RequestContext) {
1034
+ const result = await this.update${e}Command.execute(ctx.params.id, ctx.body)
1035
+ ctx.json(result)
1036
+ }
1037
+
1038
+ @Delete('/:id')
1039
+ @ApiTags('${e}')
1040
+ async remove(ctx: RequestContext) {
1041
+ await this.delete${e}Command.execute(ctx.params.id)
1042
+ ctx.noContent()
1043
+ }
1044
+ }
1045
+ `;
1046
+ }
1047
+ function ve(r) {
1048
+ const { pascal: e, kebab: t } = r;
1049
+ return [
1050
+ {
1051
+ file: `create-${t}.command.ts`,
1052
+ content: `import { Service, Inject } from '@forinda/kickjs-core'
1053
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../${t}.repository'
1054
+ import type { Create${e}DTO } from '../dtos/create-${t}.dto'
1055
+ import type { ${e}ResponseDTO } from '../dtos/${t}-response.dto'
1056
+ import { ${e}Events } from '../events/${t}.events'
1057
+
1058
+ @Service()
1059
+ export class Create${e}Command {
1060
+ constructor(
1061
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
1062
+ @Inject(${e}Events) private readonly events: ${e}Events,
1063
+ ) {}
1064
+
1065
+ async execute(dto: Create${e}DTO): Promise<${e}ResponseDTO> {
1066
+ const result = await this.repo.create(dto)
1067
+ this.events.emit('${t}.created', result)
1068
+ return result
1069
+ }
1070
+ }
1071
+ `
1072
+ },
1073
+ {
1074
+ file: `update-${t}.command.ts`,
1075
+ content: `import { Service, Inject } from '@forinda/kickjs-core'
1076
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../${t}.repository'
1077
+ import type { Update${e}DTO } from '../dtos/update-${t}.dto'
1078
+ import type { ${e}ResponseDTO } from '../dtos/${t}-response.dto'
1079
+ import { ${e}Events } from '../events/${t}.events'
1080
+
1081
+ @Service()
1082
+ export class Update${e}Command {
1083
+ constructor(
1084
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
1085
+ @Inject(${e}Events) private readonly events: ${e}Events,
1086
+ ) {}
1087
+
1088
+ async execute(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO> {
1089
+ const result = await this.repo.update(id, dto)
1090
+ this.events.emit('${t}.updated', result)
1091
+ return result
1092
+ }
1093
+ }
1094
+ `
1095
+ },
1096
+ {
1097
+ file: `delete-${t}.command.ts`,
1098
+ content: `import { Service, Inject } from '@forinda/kickjs-core'
1099
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../${t}.repository'
1100
+ import { ${e}Events } from '../events/${t}.events'
1101
+
1102
+ @Service()
1103
+ export class Delete${e}Command {
1104
+ constructor(
1105
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
1106
+ @Inject(${e}Events) private readonly events: ${e}Events,
1107
+ ) {}
1108
+
1109
+ async execute(id: string): Promise<void> {
1110
+ await this.repo.delete(id)
1111
+ this.events.emit('${t}.deleted', { id })
1112
+ }
1113
+ }
1114
+ `
1115
+ }
1116
+ ];
1117
+ }
1118
+ function we(r) {
1119
+ const { pascal: e, kebab: t, plural: o = "", pluralPascal: s = "" } = r;
1120
+ return [{
1121
+ file: `get-${t}.query.ts`,
1122
+ content: `import { Service, Inject } from '@forinda/kickjs-core'
1123
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../${t}.repository'
1124
+ import type { ${e}ResponseDTO } from '../dtos/${t}-response.dto'
1125
+
1126
+ @Service()
1127
+ export class Get${e}Query {
1128
+ constructor(
1129
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
1130
+ ) {}
1131
+
1132
+ async execute(id: string): Promise<${e}ResponseDTO | null> {
1133
+ return this.repo.findById(id)
1134
+ }
1135
+ }
1136
+ `
1137
+ }, {
1138
+ file: `list-${o}.query.ts`,
1139
+ content: `import { Service, Inject } from '@forinda/kickjs-core'
1140
+ import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../${t}.repository'
1141
+ import type { ParsedQuery } from '@forinda/kickjs-http'
1142
+
1143
+ @Service()
1144
+ export class List${s}Query {
1145
+ constructor(
1146
+ @Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
1147
+ ) {}
1148
+
1149
+ async execute(parsed: ParsedQuery) {
1150
+ return this.repo.findPaginated(parsed)
1151
+ }
1152
+ }
1153
+ `
1154
+ }];
1155
+ }
1156
+ function Re(r) {
1157
+ const { pascal: e, kebab: t } = r;
1158
+ return [{
1159
+ file: `${t}.events.ts`,
1160
+ content: `import { Service } from '@forinda/kickjs-core'
1161
+ import { EventEmitter } from 'node:events'
1162
+ import type { ${e}ResponseDTO } from '../dtos/${t}-response.dto'
1163
+
1164
+ /**
1165
+ * ${e} domain event types.
1166
+ *
1167
+ * These events are emitted by commands after state changes.
1168
+ * Subscribe to them in event handlers for side effects:
1169
+ * - WebSocket broadcasts (real-time UI updates)
1170
+ * - Queue jobs (async processing, ETL pipelines)
1171
+ * - Audit logging
1172
+ * - Cache invalidation
1173
+ */
1174
+ export interface ${e}EventMap {
1175
+ '${t}.created': ${e}ResponseDTO
1176
+ '${t}.updated': ${e}ResponseDTO
1177
+ '${t}.deleted': { id: string }
1178
+ }
1179
+
1180
+ @Service()
1181
+ export class ${e}Events {
1182
+ private emitter = new EventEmitter()
1183
+
1184
+ emit<K extends keyof ${e}EventMap>(event: K, data: ${e}EventMap[K]): void {
1185
+ this.emitter.emit(event, data)
1186
+ }
1187
+
1188
+ on<K extends keyof ${e}EventMap>(event: K, handler: (data: ${e}EventMap[K]) => void): void {
1189
+ this.emitter.on(event, handler)
1190
+ }
1191
+
1192
+ off<K extends keyof ${e}EventMap>(event: K, handler: (data: ${e}EventMap[K]) => void): void {
1193
+ this.emitter.off(event, handler)
1194
+ }
1195
+ }
1196
+ `
1197
+ }, {
1198
+ file: `on-${t}-change.handler.ts`,
1199
+ content: `import { Service, Autowired } from '@forinda/kickjs-core'
1200
+ import { ${e}Events } from './${t}.events'
1201
+
1202
+ /**
1203
+ * ${e} Change Event Handler
1204
+ *
1205
+ * Reacts to domain events emitted by commands.
1206
+ * Wire up side effects here:
1207
+ *
1208
+ * 1. WebSocket broadcast — notify connected clients in real-time
1209
+ * import { WsGateway } from '@forinda/kickjs-ws'
1210
+ * this.ws.broadcast('${t}-channel', { event, data })
1211
+ *
1212
+ * 2. Queue dispatch — offload heavy processing to background workers
1213
+ * import { QueueService } from '@forinda/kickjs-queue'
1214
+ * this.queue.add('${t}-etl', { action: event, payload: data })
1215
+ *
1216
+ * 3. ETL pipeline — transform and load data to external systems
1217
+ * await this.etlPipeline.process(data)
1218
+ */
1219
+ @Service()
1220
+ export class On${e}ChangeHandler {
1221
+ @Autowired() private events!: ${e}Events
1222
+
1223
+ // Uncomment to inject WebSocket and Queue services:
1224
+ // @Autowired() private ws!: WsGateway
1225
+ // @Autowired() private queue!: QueueService
1226
+
1227
+ onInit(): void {
1228
+ this.events.on('${t}.created', (data) => {
1229
+ console.log('[${e}] Created:', data.id)
1230
+ // TODO: Broadcast via WebSocket
1231
+ // this.ws.broadcast('${t}-channel', { event: '${t}.created', data })
1232
+ // TODO: Dispatch to queue for async processing / ETL
1233
+ // this.queue.add('${t}-etl', { action: 'create', payload: data })
1234
+ })
1235
+
1236
+ this.events.on('${t}.updated', (data) => {
1237
+ console.log('[${e}] Updated:', data.id)
1238
+ // TODO: Broadcast via WebSocket
1239
+ // this.ws.broadcast('${t}-channel', { event: '${t}.updated', data })
1240
+ })
1241
+
1242
+ this.events.on('${t}.deleted', (data) => {
1243
+ console.log('[${e}] Deleted:', data.id)
1244
+ // TODO: Broadcast via WebSocket
1245
+ // this.ws.broadcast('${t}-channel', { event: '${t}.deleted', data })
1246
+ })
1247
+ }
1248
+ }
1249
+ `
1250
+ }];
1251
+ }
1252
+ function M(r) {
1253
+ const { pascal: e, kebab: t, repoPrefix: o = "../../domain/repositories", dtoPrefix: s = "../../application/dtos" } = r;
1254
+ return `/**
1255
+ * Drizzle ${e} Repository
1256
+ *
1257
+ * Implements the repository interface using Drizzle ORM.
1258
+ * Uses buildFromColumns() with Column objects for type-safe query building.
1259
+ *
1260
+ * TODO: Update the schema import to match your Drizzle schema file.
1261
+ * TODO: Replace DRIZZLE_DB injection token with your actual database token.
1262
+ *
1263
+ * @Repository() registers this class in the DI container as a singleton.
1264
+ */
1265
+ import { eq, ne, gt, gte, lt, lte, ilike, inArray, between, and, or, asc, desc, count, sql } from 'drizzle-orm'
1266
+ import { Repository, HttpException, Inject } from '@forinda/kickjs-core'
1267
+ import { DRIZZLE_DB, DrizzleQueryAdapter } from '@forinda/kickjs-drizzle'
1268
+ import type { ParsedQuery } from '@forinda/kickjs-http'
1269
+ import type { I${e}Repository } from '${o}/${t}.repository'
1270
+ import type { ${e}ResponseDTO } from '${s}/${t}-response.dto'
1271
+ import type { Create${e}DTO } from '${s}/create-${t}.dto'
1272
+ import type { Update${e}DTO } from '${s}/update-${t}.dto'
1273
+ import { ${e.toUpperCase()}_QUERY_CONFIG } from '../../constants'
1274
+
1275
+ // TODO: Import your Drizzle schema table — e.g.:
1276
+ // import { ${t}s } from '@/db/schema'
1277
+
1278
+ const queryAdapter = new DrizzleQueryAdapter({
1279
+ eq, ne, gt, gte, lt, lte, ilike, inArray, between, and, or, asc, desc,
1280
+ })
1281
+
1282
+ @Repository()
1283
+ export class Drizzle${e}Repository implements I${e}Repository {
1284
+ constructor(@Inject(DRIZZLE_DB) private db: any) {}
1285
+
1286
+ async findById(id: string): Promise<${e}ResponseDTO | null> {
1287
+ // TODO: Implement with Drizzle
1288
+ // const row = this.db.select().from(${t}s).where(eq(${t}s.id, id)).get()
1289
+ // return row ?? null
1290
+ throw new Error('Drizzle ${e} repository not yet implemented — update schema imports and queries')
1291
+ }
1292
+
1293
+ async findAll(): Promise<${e}ResponseDTO[]> {
1294
+ // TODO: Implement with Drizzle
1295
+ // return this.db.select().from(${t}s).all()
1296
+ throw new Error('Drizzle ${e} repository not yet implemented')
1297
+ }
1298
+
1299
+ async findPaginated(parsed: ParsedQuery): Promise<{ data: ${e}ResponseDTO[]; total: number }> {
1300
+ // TODO: Use buildFromColumns() with your query config for type-safe filtering
1301
+ // const query = queryAdapter.buildFromColumns(parsed, ${e.toUpperCase()}_QUERY_CONFIG)
1302
+ //
1303
+ // const data = this.db
1304
+ // .select().from(${t}s).$dynamic()
1305
+ // .where(query.where).orderBy(...query.orderBy)
1306
+ // .limit(query.limit).offset(query.offset).all()
1307
+ //
1308
+ // const totalResult = this.db
1309
+ // .select({ count: count() }).from(${t}s)
1310
+ // .$dynamic().where(query.where).get()
1311
+ //
1312
+ // return { data, total: totalResult?.count ?? 0 }
1313
+ throw new Error('Drizzle ${e} repository not yet implemented')
1314
+ }
1315
+
1316
+ async create(dto: Create${e}DTO): Promise<${e}ResponseDTO> {
1317
+ // TODO: Implement with Drizzle
1318
+ // return this.db.insert(${t}s).values(dto).returning().get()
1319
+ throw new Error('Drizzle ${e} repository not yet implemented')
1320
+ }
1321
+
1322
+ async update(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO> {
1323
+ // TODO: Implement with Drizzle
1324
+ // const row = this.db.update(${t}s).set(dto).where(eq(${t}s.id, id)).returning().get()
1325
+ // if (!row) throw HttpException.notFound('${e} not found')
1326
+ // return row
1327
+ throw new Error('Drizzle ${e} repository not yet implemented')
1328
+ }
1329
+
1330
+ async delete(id: string): Promise<void> {
1331
+ // TODO: Implement with Drizzle
1332
+ // this.db.delete(${t}s).where(eq(${t}s.id, id)).run()
1333
+ throw new Error('Drizzle ${e} repository not yet implemented')
1334
+ }
1335
+ }
1336
+ `;
1337
+ }
1338
+ function Ce(r) {
1339
+ const { pascal: e, kebab: t } = r;
1340
+ return `import type { DrizzleQueryParamsConfig } from '@forinda/kickjs-drizzle'
1341
+ // TODO: Import your schema table and reference actual columns for type safety
1342
+ // import { ${t}s } from '@/db/schema'
1343
+
1344
+ export const ${e.toUpperCase()}_QUERY_CONFIG: DrizzleQueryParamsConfig = {
1345
+ columns: {
1346
+ // Replace with actual Drizzle Column references for type-safe filtering:
1347
+ // name: ${t}s.name,
1348
+ // status: ${t}s.status,
1349
+ },
1350
+ sortable: {
1351
+ // name: ${t}s.name,
1352
+ // createdAt: ${t}s.createdAt,
1353
+ },
1354
+ searchColumns: [
1355
+ // ${t}s.name,
1356
+ ],
1357
+ }
1358
+ `;
1359
+ }
1360
+ function q(r) {
1361
+ const { pascal: e, kebab: t, repoPrefix: o = "../../domain/repositories", dtoPrefix: s = "../../application/dtos" } = r, i = t.replace(/-([a-z])/g, (n, a) => a.toUpperCase());
1362
+ return `/**
1363
+ * Prisma ${e} Repository
1364
+ *
1365
+ * Implements the repository interface using Prisma Client.
1366
+ * Requires a PrismaClient instance injected via the DI container.
1367
+ *
1368
+ * Ensure your Prisma schema has a '${e}' model defined.
1369
+ *
1370
+ * For full Prisma field-level type safety, replace PrismaModelDelegate with your PrismaClient:
1371
+ * @Inject(PRISMA_CLIENT) private prisma!: PrismaClient
1372
+ *
1373
+ * @Repository() registers this class in the DI container as a singleton.
1374
+ */
1375
+ import { Repository, HttpException, Inject } from '@forinda/kickjs-core'
1376
+ import { PRISMA_CLIENT, type PrismaModelDelegate } from '@forinda/kickjs-prisma'
1377
+ import type { ParsedQuery } from '@forinda/kickjs-http'
1378
+ import type { I${e}Repository } from '${o}/${t}.repository'
1379
+ import type { ${e}ResponseDTO } from '${s}/${t}-response.dto'
1380
+ import type { Create${e}DTO } from '${s}/create-${t}.dto'
1381
+ import type { Update${e}DTO } from '${s}/update-${t}.dto'
1382
+
1383
+ @Repository()
1384
+ export class Prisma${e}Repository implements I${e}Repository {
1385
+ @Inject(PRISMA_CLIENT) private prisma!: { ${i}: PrismaModelDelegate }
1386
+
1387
+ async findById(id: string): Promise<${e}ResponseDTO | null> {
1388
+ return this.prisma.${i}.findUnique({ where: { id } }) as Promise<${e}ResponseDTO | null>
1389
+ }
1390
+
1391
+ async findAll(): Promise<${e}ResponseDTO[]> {
1392
+ return this.prisma.${i}.findMany() as Promise<${e}ResponseDTO[]>
1393
+ }
1394
+
1395
+ async findPaginated(parsed: ParsedQuery): Promise<{ data: ${e}ResponseDTO[]; total: number }> {
1396
+ const [data, total] = await Promise.all([
1397
+ this.prisma.${i}.findMany({
1398
+ skip: parsed.pagination.offset,
1399
+ take: parsed.pagination.limit,
1400
+ }) as Promise<${e}ResponseDTO[]>,
1401
+ this.prisma.${i}.count(),
1402
+ ])
1403
+ return { data, total }
1404
+ }
1405
+
1406
+ async create(dto: Create${e}DTO): Promise<${e}ResponseDTO> {
1407
+ return this.prisma.${i}.create({ data: dto as Record<string, unknown> }) as Promise<${e}ResponseDTO>
1408
+ }
1409
+
1410
+ async update(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO> {
1411
+ const existing = await this.prisma.${i}.findUnique({ where: { id } })
1412
+ if (!existing) throw HttpException.notFound('${e} not found')
1413
+ return this.prisma.${i}.update({ where: { id }, data: dto as Record<string, unknown> }) as Promise<${e}ResponseDTO>
1414
+ }
1415
+
1416
+ async delete(id: string): Promise<void> {
1417
+ await this.prisma.${i}.deleteMany({ where: { id } })
1418
+ }
1419
+ }
1420
+ `;
1421
+ }
1422
+ async function be(r) {
1423
+ const { pascal: e, kebab: t, plural: o, write: s } = r;
1424
+ await s("index.ts", de({
1425
+ pascal: e,
1426
+ kebab: t,
1427
+ plural: o
1428
+ })), await s(`${t}.controller.ts`, `import { Controller, Get } from '@forinda/kickjs-core'
1429
+ import type { RequestContext } from '@forinda/kickjs-http'
1430
+
1431
+ @Controller()
1432
+ export class ${e}Controller {
1433
+ @Get('/')
1434
+ async list(ctx: RequestContext) {
1435
+ ctx.json({ message: '${e} list' })
1436
+ }
1437
+ }
1438
+ `);
1439
+ }
1440
+ async function De(r) {
1441
+ const { pascal: e, kebab: t, plural: o, pluralPascal: s, repo: i, noTests: n, prismaClientPath: a, write: c } = r;
1442
+ await c("index.ts", ce({
1443
+ pascal: e,
1444
+ kebab: t,
1445
+ plural: o,
1446
+ repo: i
1447
+ })), await c(`${t}.constants.ts`, J({
1448
+ pascal: e,
1449
+ kebab: t
1450
+ })), await c(`${t}.controller.ts`, le({
1451
+ pascal: e,
1452
+ kebab: t,
1453
+ plural: o,
1454
+ pluralPascal: s
1455
+ })), await c(`${t}.service.ts`, he({
1456
+ pascal: e,
1457
+ kebab: t
1458
+ })), await c(`dtos/create-${t}.dto.ts`, T({
1459
+ pascal: e,
1460
+ kebab: t
1461
+ })), await c(`dtos/update-${t}.dto.ts`, O({
1462
+ pascal: e,
1463
+ kebab: t
1464
+ })), await c(`dtos/${t}-response.dto.ts`, I({
1465
+ pascal: e,
1466
+ kebab: t
1467
+ })), await c(`${t}.repository.ts`, S({
1468
+ pascal: e,
1469
+ kebab: t,
1470
+ dtoPrefix: "./dtos"
1471
+ }));
1472
+ const d = {
1473
+ inmemory: `in-memory-${t}`,
1474
+ drizzle: `drizzle-${t}`,
1475
+ prisma: `prisma-${t}`
1476
+ }, u = {
1477
+ inmemory: () => A({
1478
+ pascal: e,
1479
+ kebab: t,
1480
+ repoPrefix: ".",
1481
+ dtoPrefix: "./dtos"
1482
+ }),
1483
+ drizzle: () => M({
1484
+ pascal: e,
1485
+ kebab: t,
1486
+ repoPrefix: ".",
1487
+ dtoPrefix: "./dtos"
1488
+ }),
1489
+ prisma: () => q({
1490
+ pascal: e,
1491
+ kebab: t,
1492
+ repoPrefix: ".",
1493
+ dtoPrefix: "./dtos",
1494
+ prismaClientPath: a
1495
+ })
1496
+ }, m = d[i] ?? `${y(i)}-${t}`, f = u[i] ?? (() => j({
1497
+ pascal: e,
1498
+ kebab: t,
1499
+ repoType: i,
1500
+ repoPrefix: ".",
1501
+ dtoPrefix: "./dtos"
1502
+ }));
1503
+ await c(`${m}.repository.ts`, f()), n || (await c(`__tests__/${t}.controller.test.ts`, E({
1504
+ pascal: e,
1505
+ kebab: t,
1506
+ plural: o
1507
+ })), await c(`__tests__/${t}.repository.test.ts`, U({
1508
+ pascal: e,
1509
+ kebab: t,
1510
+ plural: o,
1511
+ repoPrefix: `../${d.inmemory ?? `in-memory-${t}`}.repository`
1512
+ })));
1513
+ }
1514
+ async function xe(r) {
1515
+ const { pascal: e, kebab: t, plural: o, pluralPascal: s, repo: i, noTests: n, prismaClientPath: a, write: c } = r;
1516
+ await c("index.ts", ge({
1517
+ pascal: e,
1518
+ kebab: t,
1519
+ plural: o,
1520
+ repo: i
1521
+ })), await c(`${t}.constants.ts`, J({
1522
+ pascal: e,
1523
+ kebab: t
1524
+ })), await c(`${t}.controller.ts`, ke({
1525
+ pascal: e,
1526
+ kebab: t,
1527
+ plural: o,
1528
+ pluralPascal: s
1529
+ })), await c(`dtos/create-${t}.dto.ts`, T({
1530
+ pascal: e,
1531
+ kebab: t
1532
+ })), await c(`dtos/update-${t}.dto.ts`, O({
1533
+ pascal: e,
1534
+ kebab: t
1535
+ })), await c(`dtos/${t}-response.dto.ts`, I({
1536
+ pascal: e,
1537
+ kebab: t
1538
+ }));
1539
+ const d = ve({
1540
+ pascal: e,
1541
+ kebab: t
1542
+ });
1543
+ for (const $ of d) await c(`commands/${$.file}`, $.content);
1544
+ const u = we({
1545
+ pascal: e,
1546
+ kebab: t,
1547
+ plural: o,
1548
+ pluralPascal: s
1549
+ });
1550
+ for (const $ of u) await c(`queries/${$.file}`, $.content);
1551
+ const m = Re({
1552
+ pascal: e,
1553
+ kebab: t
1554
+ });
1555
+ for (const $ of m) await c(`events/${$.file}`, $.content);
1556
+ await c(`${t}.repository.ts`, S({
1557
+ pascal: e,
1558
+ kebab: t,
1559
+ dtoPrefix: "./dtos"
1560
+ }));
1561
+ const f = {
1562
+ inmemory: `in-memory-${t}`,
1563
+ drizzle: `drizzle-${t}`,
1564
+ prisma: `prisma-${t}`
1565
+ }, v = {
1566
+ inmemory: () => A({
1567
+ pascal: e,
1568
+ kebab: t,
1569
+ repoPrefix: ".",
1570
+ dtoPrefix: "./dtos"
1571
+ }),
1572
+ drizzle: () => M({
1573
+ pascal: e,
1574
+ kebab: t,
1575
+ repoPrefix: ".",
1576
+ dtoPrefix: "./dtos"
1577
+ }),
1578
+ prisma: () => q({
1579
+ pascal: e,
1580
+ kebab: t,
1581
+ repoPrefix: ".",
1582
+ dtoPrefix: "./dtos",
1583
+ prismaClientPath: a
1584
+ })
1585
+ }, k = f[i] ?? `${y(i)}-${t}`, g = v[i] ?? (() => j({
1586
+ pascal: e,
1587
+ kebab: t,
1588
+ repoType: i,
1589
+ repoPrefix: ".",
1590
+ dtoPrefix: "./dtos"
1591
+ }));
1592
+ await c(`${k}.repository.ts`, g()), n || (await c(`__tests__/${t}.controller.test.ts`, E({
1593
+ pascal: e,
1594
+ kebab: t,
1595
+ plural: o
1596
+ })), await c(`__tests__/${t}.repository.test.ts`, U({
1597
+ pascal: e,
1598
+ kebab: t,
1599
+ plural: o,
1600
+ repoPrefix: `../${f.inmemory ?? `in-memory-${t}`}.repository`
1601
+ })));
1602
+ }
1603
+ async function Pe(r) {
1604
+ const { pascal: e, kebab: t, plural: o, pluralPascal: s, repo: i, noEntity: n, noTests: a, prismaClientPath: c, write: d } = r;
1605
+ await d("index.ts", ne({
1606
+ pascal: e,
1607
+ kebab: t,
1608
+ plural: o,
1609
+ repo: i
1610
+ })), await d("constants.ts", i === "drizzle" ? Ce({
1611
+ pascal: e,
1612
+ kebab: t
1613
+ }) : ue({
1614
+ pascal: e,
1615
+ kebab: t
1616
+ })), await d(`presentation/${t}.controller.ts`, pe({
1617
+ pascal: e,
1618
+ kebab: t,
1619
+ plural: o,
1620
+ pluralPascal: s
1621
+ })), await d(`application/dtos/create-${t}.dto.ts`, T({
1622
+ pascal: e,
1623
+ kebab: t
1624
+ })), await d(`application/dtos/update-${t}.dto.ts`, O({
1625
+ pascal: e,
1626
+ kebab: t
1627
+ })), await d(`application/dtos/${t}-response.dto.ts`, I({
1628
+ pascal: e,
1629
+ kebab: t
1630
+ }));
1631
+ const u = me({
1632
+ pascal: e,
1633
+ kebab: t,
1634
+ plural: o,
1635
+ pluralPascal: s
1636
+ });
1637
+ for (const g of u) await d(`application/use-cases/${g.file}`, g.content);
1638
+ await d(`domain/repositories/${t}.repository.ts`, S({
1639
+ pascal: e,
1640
+ kebab: t
1641
+ })), await d(`domain/services/${t}-domain.service.ts`, fe({
1642
+ pascal: e,
1643
+ kebab: t
1644
+ }));
1645
+ const m = {
1646
+ inmemory: `in-memory-${t}`,
1647
+ drizzle: `drizzle-${t}`,
1648
+ prisma: `prisma-${t}`
1649
+ }, f = {
1650
+ inmemory: () => A({
1651
+ pascal: e,
1652
+ kebab: t
1653
+ }),
1654
+ drizzle: () => M({
1655
+ pascal: e,
1656
+ kebab: t
1657
+ }),
1658
+ prisma: () => q({
1659
+ pascal: e,
1660
+ kebab: t,
1661
+ prismaClientPath: c
1662
+ })
1663
+ }, v = m[i] ?? `${y(i)}-${t}`, k = f[i] ?? (() => j({
1664
+ pascal: e,
1665
+ kebab: t,
1666
+ repoType: i
1667
+ }));
1668
+ await d(`infrastructure/repositories/${v}.repository.ts`, k()), n || (await d(`domain/entities/${t}.entity.ts`, $e({
1669
+ pascal: e,
1670
+ kebab: t
1671
+ })), await d(`domain/value-objects/${t}-id.vo.ts`, ye({
1672
+ pascal: e,
1673
+ kebab: t
1674
+ }))), a || (await d(`__tests__/${t}.controller.test.ts`, E({
1675
+ pascal: e,
1676
+ kebab: t,
1677
+ plural: o
1678
+ })), await d(`__tests__/${t}.repository.test.ts`, U({
1679
+ pascal: e,
1680
+ kebab: t,
1681
+ plural: o
1682
+ })));
1683
+ }
1684
+ function it(r) {
1685
+ return r ? typeof r == "string" ? r : r.name : "inmemory";
1686
+ }
1687
+ function Te(r) {
1688
+ const e = ee({
1689
+ input: process.stdin,
1690
+ output: process.stdout
1691
+ });
1692
+ return new Promise((t) => {
1693
+ e.question(r, (o) => {
1694
+ e.close(), t(o.trim().toLowerCase());
1695
+ });
1696
+ });
1697
+ }
1698
+ async function at(r) {
1699
+ const { name: e, modulesDir: t, noEntity: o, noTests: s, repo: i = "inmemory", force: n, dryRun: a } = r, c = r.pluralize !== !1;
1700
+ let d = r.pattern ?? "ddd";
1701
+ r.minimal && (d = "minimal");
1702
+ const u = y(e), m = h(e), f = c ? Y(u) : u, v = c ? se(m) : m, k = p(t, f), g = [];
1703
+ let $ = n ?? !1;
1704
+ const Z = async (D, X) => {
1705
+ const b = p(k, D);
1706
+ if (a) {
1707
+ g.push(b);
1708
+ return;
1709
+ }
1710
+ if (!$ && await B(b)) {
1711
+ const z = await Te(` File already exists: ${D}
1712
+ Overwrite? (y/n/a = yes/no/all) `);
1713
+ if (z === "a") $ = !0;
1714
+ else if (z !== "y") {
1715
+ console.log(` Skipped: ${D}`);
1716
+ return;
1717
+ }
1718
+ }
1719
+ await l(b, X), g.push(b);
1720
+ }, C = {
1721
+ kebab: u,
1722
+ pascal: m,
1723
+ plural: f,
1724
+ pluralPascal: v,
1725
+ moduleDir: k,
1726
+ repo: i,
1727
+ noEntity: o ?? !1,
1728
+ noTests: s ?? !1,
1729
+ prismaClientPath: r.prismaClientPath ?? "@prisma/client",
1730
+ write: Z,
1731
+ files: g
1732
+ };
1733
+ switch (d) {
1734
+ case "minimal":
1735
+ await be(C);
1736
+ break;
1737
+ case "rest":
1738
+ await De(C);
1739
+ break;
1740
+ case "cqrs":
1741
+ await xe(C);
1742
+ break;
1743
+ default:
1744
+ await Pe(C);
1745
+ break;
1746
+ }
1747
+ return a || await Oe(t, m, f), g;
1748
+ }
1749
+ async function Oe(r, e, t) {
1750
+ const o = p(r, "index.ts");
1751
+ if (!await B(o)) {
1752
+ await l(o, `import type { AppModuleClass } from '@forinda/kickjs-core'
1753
+ import { ${e}Module } from './${t}'
1754
+
1755
+ export const modules: AppModuleClass[] = [${e}Module]
1756
+ `);
1757
+ return;
1758
+ }
1759
+ let s = await L(o, "utf-8");
1760
+ const i = `import { ${e}Module } from './${t}'`;
1761
+ if (!s.includes(`${e}Module`)) {
1762
+ const n = s.lastIndexOf("import ");
1763
+ if (n !== -1) {
1764
+ const a = s.indexOf(`
1765
+ `, n);
1766
+ s = s.slice(0, a + 1) + i + `
1767
+ ` + s.slice(a + 1);
1768
+ } else s = i + `
1769
+ ` + s;
1770
+ s = s.replace(/(=\s*\[)([\s\S]*?)(])/, (a, c, d, u) => {
1771
+ const m = d.trim();
1772
+ if (!m) return `${c}${e}Module${u}`;
1773
+ const f = m.endsWith(",") ? "" : ",";
1774
+ return `${c}${d.trimEnd()}${f} ${e}Module${u}`;
1775
+ });
1776
+ }
1777
+ await N(o, s, "utf-8");
1778
+ }
1779
+ async function nt(r) {
1780
+ const { name: e, outDir: t } = r, o = y(e), s = h(e), i = [], n = p(t, `${o}.adapter.ts`);
1781
+ return await l(n, `import type { Express } from 'express'
1782
+ import type { AppAdapter, AdapterMiddleware, Container } from '@forinda/kickjs-core'
1783
+
1784
+ export interface ${s}AdapterOptions {
1785
+ // Add your adapter configuration here
1786
+ }
1787
+
1788
+ /**
1789
+ * ${s} adapter.
1790
+ *
1791
+ * Hooks into the Application lifecycle to add middleware, routes,
1792
+ * or external service connections.
1793
+ *
1794
+ * Usage:
1795
+ * bootstrap({
1796
+ * adapters: [new ${s}Adapter({ ... })],
1797
+ * })
1798
+ */
1799
+ export class ${s}Adapter implements AppAdapter {
1800
+ name = '${s}Adapter'
1801
+
1802
+ constructor(private options: ${s}AdapterOptions = {}) {}
1803
+
1804
+ /**
1805
+ * Return middleware entries that the Application will mount.
1806
+ * Use \`phase\` to control where in the pipeline they run:
1807
+ * 'beforeGlobal' | 'afterGlobal' | 'beforeRoutes' | 'afterRoutes'
1808
+ */
1809
+ middleware(): AdapterMiddleware[] {
1810
+ return [
1811
+ // Example: add a custom header to all responses
1812
+ // {
1813
+ // phase: 'beforeGlobal',
1814
+ // handler: (_req: any, res: any, next: any) => {
1815
+ // res.setHeader('X-${s}', 'true')
1816
+ // next()
1817
+ // },
1818
+ // },
1819
+ // Example: scope middleware to a specific path
1820
+ // {
1821
+ // phase: 'beforeRoutes',
1822
+ // path: '/api/v1/admin',
1823
+ // handler: myAdminMiddleware(),
1824
+ // },
1825
+ ]
1826
+ }
1827
+
1828
+ /**
1829
+ * Called before global middleware.
1830
+ * Use this to mount routes that bypass the middleware stack
1831
+ * (health checks, docs UI, static assets).
1832
+ */
1833
+ beforeMount(app: Express, container: Container): void {
1834
+ // Example: mount a status route
1835
+ // app.get('/${o}/status', (_req, res) => {
1836
+ // res.json({ status: 'ok' })
1837
+ // })
1838
+ }
1839
+
1840
+ /**
1841
+ * Called after modules and routes are registered, before the server starts.
1842
+ * Use this for late-stage DI registrations or config validation.
1843
+ */
1844
+ beforeStart(app: Express, container: Container): void {
1845
+ // Example: register a service in the DI container
1846
+ // container.registerInstance(MY_TOKEN, new MyService(this.options))
1847
+ }
1848
+
1849
+ /**
1850
+ * Called after the HTTP server is listening.
1851
+ * Use this to attach to the raw http.Server (Socket.IO, gRPC, etc).
1852
+ */
1853
+ afterStart(server: any, container: Container): void {
1854
+ // Example: attach Socket.IO
1855
+ // const io = new Server(server)
1856
+ // container.registerInstance(SOCKET_IO, io)
1857
+ }
1858
+
1859
+ /**
1860
+ * Called on graceful shutdown. Clean up connections.
1861
+ */
1862
+ async shutdown(): Promise<void> {
1863
+ // Example: close a connection pool
1864
+ // await this.pool.end()
1865
+ }
1866
+ }
1867
+ `), i.push(n), i;
1868
+ }
1869
+ var Ie = {
1870
+ controller: "presentation",
1871
+ service: "domain/services",
1872
+ dto: "application/dtos",
1873
+ guard: "presentation/guards",
1874
+ middleware: "middleware"
1875
+ }, Se = {
1876
+ controller: "",
1877
+ service: "",
1878
+ dto: "dtos",
1879
+ guard: "guards",
1880
+ middleware: "middleware"
1881
+ }, Ae = {
1882
+ controller: "",
1883
+ service: "",
1884
+ dto: "dtos",
1885
+ guard: "guards",
1886
+ middleware: "middleware",
1887
+ command: "commands",
1888
+ query: "queries",
1889
+ event: "events"
1890
+ };
1891
+ function R(r) {
1892
+ const { type: e, outDir: t, moduleName: o, modulesDir: s = "src/modules", defaultDir: i, pattern: n = "ddd" } = r;
1893
+ if (t) return x(t);
1894
+ if (o) {
1895
+ const a = n === "ddd" ? Ie : n === "cqrs" ? Ae : Se, c = Y(y(o)), d = a[e] ?? "", u = p(s, c);
1896
+ return x(d ? p(u, d) : u);
1897
+ }
1898
+ return x(i);
1899
+ }
1900
+ async function ct(r) {
1901
+ const { name: e, moduleName: t, modulesDir: o, pattern: s } = r, i = R({
1902
+ type: "middleware",
1903
+ outDir: r.outDir,
1904
+ moduleName: t,
1905
+ modulesDir: o,
1906
+ defaultDir: "src/middleware",
1907
+ pattern: s
1908
+ }), n = y(e), a = P(e), c = [], d = p(i, `${n}.middleware.ts`);
1909
+ return await l(d, `import type { Request, Response, NextFunction } from 'express'
1910
+
1911
+ export interface ${h(e)}Options {
1912
+ // Add configuration options here
1913
+ }
1914
+
1915
+ /**
1916
+ * ${h(e)} middleware.
1917
+ *
1918
+ * Usage in bootstrap:
1919
+ * middleware: [${a}()]
1920
+ *
1921
+ * Usage with adapter:
1922
+ * middleware() { return [{ handler: ${a}(), phase: 'afterGlobal' }] }
1923
+ *
1924
+ * Usage with @Middleware decorator:
1925
+ * @Middleware(${a}())
1926
+ */
1927
+ export function ${a}(options: ${h(e)}Options = {}) {
1928
+ return (req: Request, res: Response, next: NextFunction) => {
1929
+ // Implement your middleware logic here
1930
+ next()
1931
+ }
1932
+ }
1933
+ `), c.push(d), c;
1934
+ }
1935
+ async function dt(r) {
1936
+ const { name: e, moduleName: t, modulesDir: o, pattern: s } = r, i = R({
1937
+ type: "guard",
1938
+ outDir: r.outDir,
1939
+ moduleName: t,
1940
+ modulesDir: o,
1941
+ defaultDir: "src/guards",
1942
+ pattern: s
1943
+ }), n = y(e), a = P(e), c = h(e), d = [], u = p(i, `${n}.guard.ts`);
1944
+ return await l(u, `import { Container, HttpException } from '@forinda/kickjs-core'
1945
+ import type { RequestContext } from '@forinda/kickjs-http'
1946
+
1947
+ /**
1948
+ * ${c} guard.
1949
+ *
1950
+ * Guards protect routes by checking conditions before the handler runs.
1951
+ * Return early with an error response to block access.
1952
+ *
1953
+ * Usage:
1954
+ * @Middleware(${a}Guard)
1955
+ * @Get('/protected')
1956
+ * async handler(ctx: RequestContext) { ... }
1957
+ */
1958
+ export async function ${a}Guard(ctx: RequestContext, next: () => void): Promise<void> {
1959
+ // Example: check for an authorization header
1960
+ const header = ctx.headers.authorization
1961
+ if (!header?.startsWith('Bearer ')) {
1962
+ ctx.res.status(401).json({ message: 'Missing or invalid authorization header' })
1963
+ return
1964
+ }
1965
+
1966
+ const token = header.slice(7)
1967
+
1968
+ try {
1969
+ // Verify the token using a service from the DI container
1970
+ // const container = Container.getInstance()
1971
+ // const authService = container.resolve(AuthService)
1972
+ // const payload = authService.verifyToken(token)
1973
+ // ctx.set('auth', payload)
1974
+
1975
+ next()
1976
+ } catch {
1977
+ ctx.res.status(401).json({ message: 'Invalid or expired token' })
1978
+ }
1979
+ }
1980
+ `), d.push(u), d;
1981
+ }
1982
+ async function pt(r) {
1983
+ const { name: e, moduleName: t, modulesDir: o, pattern: s } = r, i = R({
1984
+ type: "service",
1985
+ outDir: r.outDir,
1986
+ moduleName: t,
1987
+ modulesDir: o,
1988
+ defaultDir: "src/services",
1989
+ pattern: s
1990
+ }), n = y(e), a = h(e), c = [], d = p(i, `${n}.service.ts`);
1991
+ return await l(d, `import { Service } from '@forinda/kickjs-core'
1992
+
1993
+ @Service()
1994
+ export class ${a}Service {
1995
+ // Inject dependencies via constructor
1996
+ // constructor(
1997
+ // @Inject(MY_REPO) private readonly repo: IMyRepository,
1998
+ // ) {}
1999
+ }
2000
+ `), c.push(d), c;
2001
+ }
2002
+ async function lt(r) {
2003
+ const { name: e, moduleName: t, modulesDir: o, pattern: s } = r, i = R({
2004
+ type: "controller",
2005
+ outDir: r.outDir,
2006
+ moduleName: t,
2007
+ modulesDir: o,
2008
+ defaultDir: "src/controllers",
2009
+ pattern: s
2010
+ }), n = y(e), a = h(e), c = [], d = p(i, `${n}.controller.ts`);
2011
+ return await l(d, `import { Controller, Get, Post, Autowired } from '@forinda/kickjs-core'
2012
+ import type { RequestContext } from '@forinda/kickjs-http'
2013
+
2014
+ @Controller()
2015
+ export class ${a}Controller {
2016
+ // @Autowired() private myService!: MyService
2017
+
2018
+ @Get('/')
2019
+ async list(ctx: RequestContext) {
2020
+ ctx.json({ message: '${a} list' })
2021
+ }
2022
+
2023
+ @Post('/')
2024
+ async create(ctx: RequestContext) {
2025
+ ctx.created({ message: '${a} created', data: ctx.body })
2026
+ }
2027
+ }
2028
+ `), c.push(d), c;
2029
+ }
2030
+ async function ut(r) {
2031
+ const { name: e, moduleName: t, modulesDir: o, pattern: s } = r, i = R({
2032
+ type: "dto",
2033
+ outDir: r.outDir,
2034
+ moduleName: t,
2035
+ modulesDir: o,
2036
+ defaultDir: "src/dtos",
2037
+ pattern: s
2038
+ }), n = y(e), a = h(e), c = P(e), d = [], u = p(i, `${n}.dto.ts`);
2039
+ return await l(u, `import { z } from 'zod'
2040
+
2041
+ export const ${c}Schema = z.object({
2042
+ // Define your schema fields here
2043
+ name: z.string().min(1).max(200),
2044
+ })
2045
+
2046
+ export type ${a}DTO = z.infer<typeof ${c}Schema>
2047
+ `), d.push(u), d;
2048
+ }
2049
+ function je(r, e, t) {
2050
+ const o = {
2051
+ "@forinda/kickjs-core": t,
2052
+ "@forinda/kickjs-http": t,
2053
+ "@forinda/kickjs-config": t,
2054
+ express: "^5.1.0",
2055
+ "reflect-metadata": "^0.2.2",
2056
+ zod: "^4.3.6",
2057
+ pino: "^10.3.1",
2058
+ "pino-pretty": "^13.1.3"
2059
+ };
2060
+ return e !== "minimal" && (o["@forinda/kickjs-swagger"] = t, o["@forinda/kickjs-devtools"] = t), e === "graphql" && (o["@forinda/kickjs-graphql"] = t, o.graphql = "^16.11.0"), e === "cqrs" && (o["@forinda/kickjs-queue"] = t, o["@forinda/kickjs-ws"] = t, o["@forinda/kickjs-otel"] = t), e === "ddd" && (o["@forinda/kickjs-swagger"] = t), JSON.stringify({
2061
+ name: r,
2062
+ version: t.replace("^", ""),
2063
+ type: "module",
2064
+ scripts: {
2065
+ dev: "kick dev",
2066
+ "dev:debug": "kick dev:debug",
2067
+ build: "kick build",
2068
+ start: "kick start",
2069
+ test: "vitest run",
2070
+ "test:watch": "vitest",
2071
+ typecheck: "tsc --noEmit",
2072
+ lint: "eslint src/",
2073
+ format: "prettier --write src/"
2074
+ },
2075
+ dependencies: o,
2076
+ devDependencies: {
2077
+ "@forinda/kickjs-cli": t,
2078
+ "@swc/core": "^1.7.28",
2079
+ "@types/express": "^5.0.6",
2080
+ "@types/node": "^24.5.2",
2081
+ "unplugin-swc": "^1.5.9",
2082
+ vite: "^8.0.2",
2083
+ vitest: "^3.2.4",
2084
+ typescript: "^5.9.2",
2085
+ prettier: "^3.8.1"
2086
+ }
2087
+ }, null, 2);
2088
+ }
2089
+ function Ee() {
2090
+ return `import { defineConfig } from 'vite'
2091
+ import { resolve } from 'path'
2092
+ import swc from 'unplugin-swc'
2093
+
2094
+ export default defineConfig({
2095
+ oxc: false,
2096
+ plugins: [swc.vite()],
2097
+ resolve: {
2098
+ alias: {
2099
+ '@': resolve(__dirname, 'src'),
2100
+ },
2101
+ },
2102
+ ssr: {
2103
+ // Don't bundle pino — its worker-thread transport needs Node.js resolution
2104
+ // to find pino-pretty at runtime for colored log output
2105
+ external: ['pino', 'pino-pretty'],
2106
+ },
2107
+ server: {
2108
+ watch: { usePolling: false },
2109
+ hmr: true,
2110
+ },
2111
+ build: {
2112
+ target: 'node20',
2113
+ ssr: true,
2114
+ outDir: 'dist',
2115
+ sourcemap: true,
2116
+ rollupOptions: {
2117
+ input: resolve(__dirname, 'src/index.ts'),
2118
+ output: { format: 'esm' },
2119
+ },
2120
+ },
2121
+ })
2122
+ `;
2123
+ }
2124
+ function Ue() {
2125
+ return JSON.stringify({
2126
+ compilerOptions: {
2127
+ target: "ES2022",
2128
+ module: "ESNext",
2129
+ moduleResolution: "bundler",
2130
+ lib: ["ES2022"],
2131
+ types: ["node", "vite/client"],
2132
+ strict: !0,
2133
+ esModuleInterop: !0,
2134
+ skipLibCheck: !0,
2135
+ sourceMap: !0,
2136
+ declaration: !0,
2137
+ experimentalDecorators: !0,
2138
+ emitDecoratorMetadata: !0,
2139
+ outDir: "dist",
2140
+ rootDir: "src",
2141
+ paths: { "@/*": ["./src/*"] }
2142
+ },
2143
+ include: ["src"]
2144
+ }, null, 2);
2145
+ }
2146
+ function Me() {
2147
+ return JSON.stringify({
2148
+ semi: !1,
2149
+ singleQuote: !0,
2150
+ trailingComma: "all",
2151
+ printWidth: 100,
2152
+ tabWidth: 2
2153
+ }, null, 2);
2154
+ }
2155
+ function qe() {
2156
+ return `# https://editorconfig.org
2157
+ root = true
2158
+
2159
+ [*]
2160
+ indent_style = space
2161
+ indent_size = 2
2162
+ end_of_line = lf
2163
+ charset = utf-8
2164
+ trim_trailing_whitespace = true
2165
+ insert_final_newline = true
2166
+
2167
+ [*.md]
2168
+ trim_trailing_whitespace = false
2169
+ `;
2170
+ }
2171
+ function ze() {
2172
+ return `node_modules/
2173
+ dist/
2174
+ .env
2175
+ coverage/
2176
+ .DS_Store
2177
+ *.tsbuildinfo
2178
+ `;
2179
+ }
2180
+ function _e() {
2181
+ return `# Auto-detect text files and normalise line endings to LF
2182
+ * text=auto eol=lf
2183
+
2184
+ # Explicitly mark generated / binary files
2185
+ *.png binary
2186
+ *.jpg binary
2187
+ *.jpeg binary
2188
+ *.gif binary
2189
+ *.ico binary
2190
+ *.woff binary
2191
+ *.woff2 binary
2192
+ *.ttf binary
2193
+ *.eot binary
2194
+
2195
+ # Lock files — treat as generated
2196
+ pnpm-lock.yaml -diff linguist-generated
2197
+ yarn.lock -diff linguist-generated
2198
+ package-lock.json -diff linguist-generated
2199
+ `;
2200
+ }
2201
+ function Ge() {
2202
+ return `PORT=3000
2203
+ NODE_ENV=development
2204
+ `;
2205
+ }
2206
+ function Qe() {
2207
+ return `PORT=3000
2208
+ NODE_ENV=development
2209
+ `;
2210
+ }
2211
+ function Fe() {
2212
+ return `import { defineConfig } from 'vitest/config'
2213
+ import swc from 'unplugin-swc'
2214
+
2215
+ export default defineConfig({
2216
+ plugins: [swc.vite()],
2217
+ test: {
2218
+ globals: true,
2219
+ environment: 'node',
2220
+ include: ['src/**/*.test.ts'],
2221
+ },
2222
+ })
2223
+ `;
2224
+ }
2225
+ function Le(r, e, t) {
2226
+ switch (e) {
2227
+ case "graphql":
2228
+ return `import 'reflect-metadata'
2229
+ import { bootstrap } from '@forinda/kickjs-http'
2230
+ import { DevToolsAdapter } from '@forinda/kickjs-devtools'
2231
+ import { GraphQLAdapter } from '@forinda/kickjs-graphql'
2232
+ import { modules } from './modules'
2233
+
2234
+ // Import your resolvers here
2235
+ // import { UserResolver } from './resolvers/user.resolver'
2236
+
2237
+ bootstrap({
2238
+ modules,
2239
+ adapters: [
2240
+ new DevToolsAdapter(),
2241
+ new GraphQLAdapter({
2242
+ resolvers: [/* UserResolver */],
2243
+ // Add custom type definitions here:
2244
+ // typeDefs: userTypeDefs,
2245
+ }),
2246
+ ],
2247
+ })
2248
+ `;
2249
+ case "cqrs":
2250
+ return `import 'reflect-metadata'
2251
+ import { bootstrap } from '@forinda/kickjs-http'
2252
+ import { DevToolsAdapter } from '@forinda/kickjs-devtools'
2253
+ import { SwaggerAdapter } from '@forinda/kickjs-swagger'
2254
+ import { OtelAdapter } from '@forinda/kickjs-otel'
2255
+ // import { WsAdapter } from '@forinda/kickjs-ws'
2256
+ // import { QueueAdapter, BullMQProvider } from '@forinda/kickjs-queue'
2257
+ import { modules } from './modules'
2258
+
2259
+ bootstrap({
2260
+ modules,
2261
+ adapters: [
2262
+ new OtelAdapter({ serviceName: '${r}' }),
2263
+ new DevToolsAdapter(),
2264
+ new SwaggerAdapter({
2265
+ info: { title: '${r}', version: '${t}' },
2266
+ }),
2267
+ // Uncomment for WebSocket support:
2268
+ // new WsAdapter(),
2269
+ // Uncomment when Redis is available:
2270
+ // new QueueAdapter({
2271
+ // provider: new BullMQProvider({ host: 'localhost', port: 6379 }),
2272
+ // }),
2273
+ ],
2274
+ })
2275
+ `;
2276
+ case "minimal":
2277
+ return `import 'reflect-metadata'
2278
+ import { bootstrap } from '@forinda/kickjs-http'
2279
+ import { modules } from './modules'
2280
+
2281
+ bootstrap({ modules })
2282
+ `;
2283
+ default:
2284
+ return `import 'reflect-metadata'
2285
+ import { bootstrap } from '@forinda/kickjs-http'
2286
+ import { DevToolsAdapter } from '@forinda/kickjs-devtools'
2287
+ import { SwaggerAdapter } from '@forinda/kickjs-swagger'
2288
+ import { modules } from './modules'
2289
+
2290
+ bootstrap({
2291
+ modules,
2292
+ adapters: [
2293
+ new DevToolsAdapter(),
2294
+ new SwaggerAdapter({
2295
+ info: { title: '${r}', version: '${t}' },
2296
+ }),
2297
+ ],
2298
+ })
2299
+ `;
2300
+ }
2301
+ }
2302
+ function Ne() {
2303
+ return `import type { AppModuleClass } from '@forinda/kickjs-core'
2304
+
2305
+ export const modules: AppModuleClass[] = []
2306
+ `;
2307
+ }
2308
+ function We(r, e = "inmemory") {
2309
+ return `import { defineConfig } from '@forinda/kickjs-cli'
2310
+
2311
+ export default defineConfig({
2312
+ pattern: '${r}',
2313
+ modules: {
2314
+ dir: 'src/modules',
2315
+ repo: '${e}',
2316
+ pluralize: true,
2317
+ },
2318
+
2319
+ commands: [
2320
+ {
2321
+ name: 'test',
2322
+ description: 'Run tests with Vitest',
2323
+ steps: 'npx vitest run',
2324
+ },
2325
+ {
2326
+ name: 'format',
2327
+ description: 'Format code with Prettier',
2328
+ steps: 'npx prettier --write src/',
2329
+ },
2330
+ {
2331
+ name: 'format:check',
2332
+ description: 'Check formatting without writing',
2333
+ steps: 'npx prettier --check src/',
2334
+ },
2335
+ {
2336
+ name: 'check',
2337
+ description: 'Run typecheck + format check',
2338
+ steps: ['npx tsc --noEmit', 'npx prettier --check src/'],
2339
+ aliases: ['verify', 'ci'],
2340
+ },
2341
+ ],
2342
+ })
2343
+ `;
2344
+ }
2345
+ function Be(r, e, t) {
2346
+ const o = {
2347
+ rest: "REST API",
2348
+ graphql: "GraphQL API",
2349
+ ddd: "Domain-Driven Design",
2350
+ cqrs: "CQRS + Event-Driven",
2351
+ minimal: "Minimal"
2352
+ }, s = [
2353
+ "@forinda/kickjs-core",
2354
+ "@forinda/kickjs-http",
2355
+ "@forinda/kickjs-config"
2356
+ ];
2357
+ return e !== "minimal" && s.push("@forinda/kickjs-swagger", "@forinda/kickjs-devtools"), e === "graphql" && s.push("@forinda/kickjs-graphql"), e === "cqrs" && s.push("@forinda/kickjs-queue", "@forinda/kickjs-ws", "@forinda/kickjs-otel"), `# ${r}
2358
+
2359
+ A **${o[e] ?? "REST API"}** built with [KickJS](https://forinda.github.io/kick-js/) — a decorator-driven Node.js framework on Express 5 and TypeScript.
2360
+
2361
+ ## Getting Started
2362
+
2363
+ \`\`\`bash
2364
+ ${t} install
2365
+ kick dev
2366
+ \`\`\`
2367
+
2368
+ ## Scripts
2369
+
2370
+ | Command | Description |
2371
+ |---|---|
2372
+ | \`kick dev\` | Start dev server with Vite HMR |
2373
+ | \`kick build\` | Production build |
2374
+ | \`kick start\` | Run production build |
2375
+ | \`${t} run test\` | Run tests with Vitest |
2376
+ | \`kick g module <name>\` | Generate a DDD module |
2377
+ | \`kick g scaffold <name> <fields...>\` | Generate CRUD from field definitions |
2378
+ | \`kick add <package>\` | Add a KickJS package |
2379
+
2380
+ ## Project Structure
2381
+
2382
+ \`\`\`
2383
+ src/
2384
+ ├── index.ts # Application entry point
2385
+ ├── modules/ # Feature modules (controllers, services, repos)
2386
+ │ └── index.ts # Module registry
2387
+ └── ...
2388
+ \`\`\`
2389
+
2390
+ ## Packages
2391
+
2392
+ ${s.map((i) => `- \`${i}\``).join(`
2393
+ `)}
2394
+
2395
+ ## Adding Features
2396
+
2397
+ \`\`\`bash
2398
+ kick add auth # Authentication (JWT, API key, OAuth)
2399
+ kick add swagger # OpenAPI documentation
2400
+ kick add ws # WebSocket support
2401
+ kick add queue # Background job processing
2402
+ kick add mailer # Email sending
2403
+ kick add cron # Scheduled tasks
2404
+ kick add --list # Show all available packages
2405
+ \`\`\`
2406
+
2407
+ ## Environment Variables
2408
+
2409
+ Copy \`.env.example\` to \`.env\` and configure:
2410
+
2411
+ | Variable | Default | Description |
2412
+ |---|---|---|
2413
+ | \`PORT\` | \`3000\` | Server port |
2414
+ | \`NODE_ENV\` | \`development\` | Environment |
2415
+
2416
+ ## Learn More
2417
+
2418
+ - [KickJS Documentation](https://forinda.github.io/kick-js/)
2419
+ - [CLI Reference](https://forinda.github.io/kick-js/api/cli.html)
2420
+ `;
2421
+ }
2422
+ function Ye(r, e, t) {
2423
+ return `# CLAUDE.md — ${r} Development Guide
2424
+
2425
+ ## Project Overview
2426
+
2427
+ This is a **${{
2428
+ rest: "REST API",
2429
+ graphql: "GraphQL API",
2430
+ ddd: "Domain-Driven Design",
2431
+ cqrs: "CQRS + Event-Driven",
2432
+ minimal: "Minimal Express"
2433
+ }[e] ?? "REST API"}** application built with [KickJS](https://forinda.github.io/kick-js/) — a decorator-driven Node.js framework on Express 5 and TypeScript.
2434
+
2435
+ ## Quick Commands
2436
+
2437
+ \`\`\`bash
2438
+ ${t} install # Install dependencies
2439
+ kick dev # Start dev server with HMR
2440
+ kick build # Production build via Vite
2441
+ kick start # Run production build
2442
+ ${t} run test # Run tests with Vitest
2443
+ ${t} run typecheck # TypeScript type checking
2444
+ ${t} run format # Format code with Prettier
2445
+ \`\`\`
2446
+
2447
+ ## Project Structure
2448
+
2449
+ \`\`\`
2450
+ src/
2451
+ ├── index.ts # Application bootstrap
2452
+ ├── modules/ # Feature modules (DDD/CQRS pattern)
2453
+ │ └── index.ts # Module registry
2454
+ ${e === "graphql" ? `├── resolvers/ # GraphQL resolvers
2455
+ ` : ""}└── ...
2456
+ \`\`\`
2457
+
2458
+ ## Package Manager
2459
+
2460
+ - Always use **${t}** for this project
2461
+ - Run \`${t} install\` to sync dependencies
2462
+ - Never mix package managers (npm/yarn/pnpm)
2463
+
2464
+ ## Code Style
2465
+
2466
+ - **Prettier** — no semicolons, single quotes, trailing commas, 100 char width
2467
+ - **TypeScript strict mode** — all types required
2468
+ - Format before committing: \`${t} run format\`
2469
+ - Type check with: \`${t} run typecheck\`
2470
+
2471
+ ## Key Patterns
2472
+
2473
+ ### Controllers
2474
+
2475
+ Use decorators to define routes:
2476
+
2477
+ \`\`\`ts
2478
+ import { Controller, Get, Post, RequestContext } from '@forinda/kickjs-http'
2479
+
2480
+ @Controller('/users')
2481
+ export class UserController {
2482
+ @Get('/')
2483
+ async findAll(ctx: RequestContext) {
2484
+ return ctx.json({ users: [] })
2485
+ }
2486
+
2487
+ @Post('/')
2488
+ async create(ctx: RequestContext) {
2489
+ const data = ctx.body
2490
+ return ctx.created({ user: data })
2491
+ }
2492
+ }
2493
+ \`\`\`
2494
+
2495
+ ### Services
2496
+
2497
+ Inject dependencies with \`@Service()\` and \`@Autowired()\`:
2498
+
2499
+ \`\`\`ts
2500
+ import { Service, Autowired } from '@forinda/kickjs-core'
2501
+
2502
+ @Service()
2503
+ export class UserService {
2504
+ @Autowired()
2505
+ private userRepository!: UserRepository
2506
+
2507
+ async findAll() {
2508
+ return this.userRepository.findAll()
2509
+ }
2510
+ }
2511
+ \`\`\`
2512
+
2513
+ ### Modules
2514
+
2515
+ Register controllers and providers in modules:
2516
+
2517
+ \`\`\`ts
2518
+ import { Module } from '@forinda/kickjs-core'
2519
+ import { UserController } from './user.controller'
2520
+ import { UserService } from './user.service'
2521
+
2522
+ @Module({
2523
+ controllers: [UserController],
2524
+ providers: [UserService],
2525
+ })
2526
+ export class UserModule {}
2527
+ \`\`\`
2528
+
2529
+ ### RequestContext
2530
+
2531
+ Every controller method receives \`ctx: RequestContext\`:
2532
+
2533
+ \`\`\`ts
2534
+ ctx.body // Request body (parsed JSON)
2535
+ ctx.params // Route params
2536
+ ctx.query // Query string
2537
+ ctx.headers // Request headers
2538
+ ctx.requestId // Auto-generated request ID
2539
+ ctx.session // Session data (if session middleware enabled)
2540
+ ctx.file // Uploaded file (single)
2541
+ ctx.files // Uploaded files (multiple)
2542
+
2543
+ // Pagination helpers
2544
+ ctx.qs(config) // Parse query with filters/sort/pagination
2545
+ ctx.paginate(handler) // Auto-paginated response
2546
+
2547
+ // Response helpers
2548
+ ctx.json(data) // 200 OK with JSON
2549
+ ctx.created(data) // 201 Created
2550
+ ctx.noContent() // 204 No Content
2551
+ ctx.notFound() // 404 Not Found
2552
+ ctx.badRequest(msg) // 400 Bad Request
2553
+ \`\`\`
2554
+
2555
+ ## CLI Generators
2556
+
2557
+ Generate code with the \`kick\` CLI:
2558
+
2559
+ \`\`\`bash
2560
+ kick g module <name> # Full module (controller, service, DTOs, repo)
2561
+ kick g scaffold <name> <fields> # CRUD module from field definitions
2562
+ kick g controller <name> # Standalone controller
2563
+ kick g service <name> # Service class
2564
+ kick g middleware <name> # Express middleware
2565
+ kick g guard <name> # Route guard (auth, roles)
2566
+ kick g adapter <name> # AppAdapter with lifecycle hooks
2567
+ kick g dto <name> # Zod DTO schema
2568
+ ${e === "graphql" ? `kick g resolver <name> # GraphQL resolver
2569
+ ` : ""}${e === "cqrs" ? `kick g job <name> # Queue job processor
2570
+ ` : ""}\`\`\`
2571
+
2572
+ ## Adding Packages
2573
+
2574
+ \`\`\`bash
2575
+ kick add auth # JWT, API key, OAuth strategies
2576
+ kick add swagger # OpenAPI docs from decorators
2577
+ kick add ws # WebSocket support
2578
+ kick add queue # Background jobs (BullMQ/RabbitMQ/Kafka)
2579
+ kick add mailer # Email (SMTP, Resend, SES)
2580
+ kick add cron # Scheduled tasks
2581
+ kick add prisma # Prisma ORM adapter
2582
+ kick add drizzle # Drizzle ORM adapter
2583
+ kick add otel # OpenTelemetry tracing
2584
+ kick add --list # Show all available packages
2585
+ \`\`\`
2586
+
2587
+ ## Environment Configuration
2588
+
2589
+ Edit \`.env\` for environment variables. Access them with \`@Value()\` decorator:
2590
+
2591
+ \`\`\`ts
2592
+ import { Value } from '@forinda/kickjs-config'
2593
+
2594
+ @Service()
2595
+ export class ApiService {
2596
+ @Value('API_KEY')
2597
+ private apiKey!: string
2598
+
2599
+ @Value('PORT', 3000) // With default
2600
+ private port!: number
2601
+ }
2602
+ \`\`\`
2603
+
2604
+ Or use \`ConfigService\`:
2605
+
2606
+ \`\`\`ts
2607
+ import { ConfigService } from '@forinda/kickjs-config'
2608
+
2609
+ @Service()
2610
+ export class AppService {
2611
+ @Autowired()
2612
+ private config!: ConfigService
2613
+
2614
+ getPort() {
2615
+ return this.config.get('PORT', 3000)
2616
+ }
2617
+ }
2618
+ \`\`\`
2619
+
2620
+ ## Testing
2621
+
2622
+ Tests live in \`src/**/*.test.ts\`:
2623
+
2624
+ \`\`\`ts
2625
+ import { describe, it, expect, beforeEach } from 'vitest'
2626
+ import { Container } from '@forinda/kickjs-core'
2627
+ import { createTestApp } from '@forinda/kickjs-testing'
2628
+
2629
+ describe('UserController', () => {
2630
+ beforeEach(() => Container.reset())
2631
+
2632
+ it('should return users', async () => {
2633
+ const app = await createTestApp([UserModule])
2634
+ const res = await app.get('/users')
2635
+ expect(res.status).toBe(200)
2636
+ })
2637
+ })
2638
+ \`\`\`
2639
+
2640
+ Run tests:
2641
+ - \`${t} run test\` — run all tests
2642
+ - \`${t} run test:watch\` — watch mode
2643
+
2644
+ ## Decorators Reference
2645
+
2646
+ ### Route Decorators
2647
+ - \`@Controller('/path')\` — define controller prefix
2648
+ - \`@Get('/'), @Post('/'), @Put('/'), @Delete('/'), @Patch('/')\` — HTTP methods
2649
+ - \`@Middleware(fn)\` — attach middleware
2650
+ - \`@Public()\` — skip authentication (requires @forinda/kickjs-auth)
2651
+ - \`@Roles('admin', 'user')\` — role-based access control
2652
+
2653
+ ### DI Decorators
2654
+ - \`@Module({ controllers, providers, imports })\` — define module
2655
+ - \`@Service()\` — singleton service (DI-registered)
2656
+ - \`@Repository()\` — repository (semantic alias for @Service)
2657
+ - \`@Autowired()\` — property injection
2658
+ - \`@Inject('token')\` — token-based injection
2659
+ - \`@Value('ENV_VAR')\` — inject config value
2660
+
2661
+ ${e === "cqrs" ? "### CQRS/Event Decorators\n- `@Job('job-name')` — queue job handler\n- `@Process('queue-name')` — queue processor\n- `@Cron('0 * * * *')` — cron schedule\n- `@WsController('/path')` — WebSocket controller\n- `@Subscribe('event')` — WebSocket event handler\n\n" : ""}${e === "graphql" ? "### GraphQL Decorators\n- `@Resolver()` — GraphQL resolver\n- `@Query()` — GraphQL query\n- `@Mutation()` — GraphQL mutation\n- `@Arg('name')` — resolver argument\n\n" : ""}## Common Pitfalls
2662
+
2663
+ 1. **Decorators fire at import time** — make sure to import module classes in \`src/modules/index.ts\`
2664
+ 2. **Tests need \`Container.reset()\`** — call in \`beforeEach\` to isolate DI state
2665
+ 3. **Always use \`ctx.body\`** — never \`req.body\` directly
2666
+ 4. **DI requires \`reflect-metadata\`** — already imported in \`src/index.ts\`
2667
+ 5. **Vite HMR requires proper cleanup** — adapters should implement \`shutdown()\`
2668
+
2669
+ ## Learn More
2670
+
2671
+ - [KickJS Documentation](https://forinda.github.io/kick-js/)
2672
+ - [API Reference](https://forinda.github.io/kick-js/api/)
2673
+ - [CLI Commands](https://forinda.github.io/kick-js/guide/cli-commands.html)
2674
+ - [Decorators Guide](https://forinda.github.io/kick-js/guide/decorators.html)
2675
+ `;
2676
+ }
2677
+ function He(r, e, t) {
2678
+ return `# AGENTS.md — AI Agent Guide for ${r}
2679
+
2680
+ This guide helps AI agents (Claude, Copilot, etc.) work effectively on this KickJS application.
2681
+
2682
+ ## Before You Start
2683
+
2684
+ 1. Read \`CLAUDE.md\` for project conventions and commands
2685
+ 2. Run \`${t} install\` to install dependencies
2686
+ 3. Run \`kick dev\` to verify the app starts
2687
+ 4. Read the [KickJS documentation](https://forinda.github.io/kick-js/) for framework details
2688
+
2689
+ ## Where to Find Things
2690
+
2691
+ ### Application Structure
2692
+
2693
+ | What | Where |
2694
+ |------|-------|
2695
+ | Entry point | \`src/index.ts\` |
2696
+ | Module registry | \`src/modules/index.ts\` |
2697
+ | Feature modules | \`src/modules/<module-name>/\` |
2698
+ ${e === "graphql" ? "| GraphQL resolvers | `src/resolvers/` |\n" : ""}| Environment config | \`.env\` |
2699
+ | TypeScript config | \`tsconfig.json\` |
2700
+ | Vite config (HMR) | \`vite.config.ts\` |
2701
+ | Vitest config | \`vitest.config.ts\` |
2702
+ | Prettier config | \`.prettierrc\` |
2703
+ | CLI config | \`kick.config.ts\` |
2704
+
2705
+ ### Module Pattern (${e.toUpperCase()})
2706
+
2707
+ Each module in \`src/modules/<name>/\` typically contains:
2708
+
2709
+ ${e === "ddd" ? `\`\`\`
2710
+ <name>/
2711
+ ├── <name>.controller.ts # HTTP routes (@Controller)
2712
+ ├── <name>.service.ts # Business logic (@Service)
2713
+ ├── <name>.repository.ts # Data access (@Repository)
2714
+ ├── <name>.dto.ts # Request/response schemas (Zod)
2715
+ ├── <name>.entity.ts # Domain entity (optional)
2716
+ └── <name>.module.ts # Module definition (@Module)
2717
+ \`\`\`
2718
+ ` : e === "cqrs" ? `\`\`\`
2719
+ <name>/
2720
+ ├── commands/ # Write operations
2721
+ │ ├── create-<name>.command.ts
2722
+ │ └── create-<name>.handler.ts
2723
+ ├── queries/ # Read operations
2724
+ │ ├── get-<name>.query.ts
2725
+ │ └── get-<name>.handler.ts
2726
+ ├── events/ # Domain events
2727
+ │ └── <name>-created.event.ts
2728
+ ├── <name>.controller.ts # HTTP routes
2729
+ ├── <name>.repository.ts # Data access
2730
+ └── <name>.module.ts # Module definition
2731
+ \`\`\`
2732
+ ` : e === "graphql" ? "```\nresolvers/\n├── <name>.resolver.ts # @Resolver, @Query, @Mutation\n├── <name>.types.ts # GraphQL type definitions\n└── <name>.service.ts # Business logic\n```\n" : e === "rest" ? `\`\`\`
2733
+ <name>/
2734
+ ├── <name>.controller.ts # HTTP routes (@Controller)
2735
+ ├── <name>.service.ts # Business logic (@Service)
2736
+ ├── <name>.dto.ts # Request/response schemas (Zod)
2737
+ └── <name>.module.ts # Module definition (@Module)
2738
+ \`\`\`
2739
+ ` : "```\nsrc/\n├── index.ts # Add routes here\n└── ... # Custom structure\n```\n"}
2740
+
2741
+ ## Checklist: Adding a Feature
2742
+
2743
+ ### New Module (Recommended)
2744
+
2745
+ Use the CLI generator for consistency:
2746
+
2747
+ \`\`\`bash
2748
+ kick g module <name> # Generate full module
2749
+ # or
2750
+ kick g scaffold <name> <fields> # Generate CRUD from fields
2751
+ \`\`\`
2752
+
2753
+ Then:
2754
+ - [ ] Review generated files in \`src/modules/<name>/\`
2755
+ - [ ] Verify module is registered in \`src/modules/index.ts\`
2756
+ - [ ] Update DTOs in \`<name>.dto.ts\` if needed
2757
+ - [ ] Implement business logic in \`<name>.service.ts\`
2758
+ - [ ] Run \`kick dev\` to test with HMR
2759
+ - [ ] Write tests in \`<name>.test.ts\`
2760
+
2761
+ ### Manual Controller
2762
+
2763
+ If not using generators:
2764
+
2765
+ - [ ] Create \`src/modules/<name>/<name>.controller.ts\`
2766
+ - [ ] Add \`@Controller('/path')\` decorator
2767
+ - [ ] Add route handlers with \`@Get()\`, \`@Post()\`, etc.
2768
+ - [ ] Create module file with \`@Module({ controllers: [NameController] })\`
2769
+ - [ ] Register module in \`src/modules/index.ts\`
2770
+ - [ ] Test with \`kick dev\`
2771
+
2772
+ ### Manual Service
2773
+
2774
+ - [ ] Create \`src/modules/<name>/<name>.service.ts\`
2775
+ - [ ] Add \`@Service()\` decorator
2776
+ - [ ] Inject dependencies with \`@Autowired()\`
2777
+ - [ ] Register in module \`providers\` array
2778
+ - [ ] Write unit tests
2779
+
2780
+ ### New Middleware
2781
+
2782
+ - [ ] Create \`src/middleware/<name>.middleware.ts\`
2783
+ - [ ] Export middleware function (Express format)
2784
+ - [ ] Register in \`src/index.ts\` or attach to routes with \`@Middleware()\`
2785
+ - [ ] Test with sample requests
2786
+
2787
+ ### Adding a Package
2788
+
2789
+ Use \`kick add\` to install KickJS packages with correct peer dependencies:
2790
+
2791
+ - [ ] Run \`kick add <package>\` (e.g., \`kick add auth\`)
2792
+ - [ ] Follow package-specific setup in terminal output
2793
+ - [ ] Update \`src/index.ts\` to register adapter (if needed)
2794
+ - [ ] Configure environment variables in \`.env\`
2795
+ - [ ] Test integration with \`kick dev\`
2796
+
2797
+ ## Common Tasks
2798
+
2799
+ ### Generate CRUD Module
2800
+
2801
+ \`\`\`bash
2802
+ kick g scaffold user name:string email:string age:number
2803
+ \`\`\`
2804
+
2805
+ This creates a full CRUD module with:
2806
+ - Controller with GET, POST, PUT, DELETE routes
2807
+ - Service with business logic
2808
+ - Repository with data access
2809
+ - DTOs with Zod validation
2810
+
2811
+ ### Add Authentication
2812
+
2813
+ \`\`\`bash
2814
+ kick add auth
2815
+ \`\`\`
2816
+
2817
+ Then configure in \`src/index.ts\`:
2818
+
2819
+ \`\`\`ts
2820
+ import { AuthAdapter, JwtStrategy } from '@forinda/kickjs-auth'
2821
+
2822
+ bootstrap({
2823
+ modules,
2824
+ adapters: [
2825
+ new AuthAdapter({
2826
+ strategies: [new JwtStrategy({ secret: process.env.JWT_SECRET! })],
2827
+ }),
2828
+ ],
2829
+ })
2830
+ \`\`\`
2831
+
2832
+ ### Add Database (Prisma)
2833
+
2834
+ \`\`\`bash
2835
+ kick add prisma
2836
+ ${t} install prisma @prisma/client
2837
+ npx prisma init
2838
+ # Edit prisma/schema.prisma
2839
+ npx prisma migrate dev --name init
2840
+ kick g module user --repo prisma
2841
+ \`\`\`
2842
+
2843
+ ### Add WebSocket Support
2844
+
2845
+ \`\`\`bash
2846
+ kick add ws
2847
+ \`\`\`
2848
+
2849
+ Then add adapter in \`src/index.ts\`:
2850
+
2851
+ \`\`\`ts
2852
+ import { WsAdapter } from '@forinda/kickjs-ws'
2853
+
2854
+ bootstrap({
2855
+ modules,
2856
+ adapters: [new WsAdapter()],
2857
+ })
2858
+ \`\`\`
2859
+
2860
+ Create WebSocket controller:
2861
+
2862
+ \`\`\`bash
2863
+ kick g controller chat --ws
2864
+ \`\`\`
2865
+
2866
+ ## Testing Guidelines
2867
+
2868
+ All tests use Vitest:
2869
+
2870
+ \`\`\`ts
2871
+ import { describe, it, expect, beforeEach } from 'vitest'
2872
+ import { Container } from '@forinda/kickjs-core'
2873
+ import { createTestApp } from '@forinda/kickjs-testing'
2874
+
2875
+ describe('UserController', () => {
2876
+ beforeEach(() => {
2877
+ Container.reset() // Important: isolate DI state
2878
+ })
2879
+
2880
+ it('should return users', async () => {
2881
+ const app = await createTestApp([UserModule])
2882
+ const res = await app.get('/users')
2883
+
2884
+ expect(res.status).toBe(200)
2885
+ expect(res.body).toHaveProperty('users')
2886
+ })
2887
+ })
2888
+ \`\`\`
2889
+
2890
+ Run tests:
2891
+ - \`${t} run test\` — run all tests once
2892
+ - \`${t} run test:watch\` — watch mode
2893
+ - Individual file: \`${t} run test src/modules/user/user.test.ts\`
2894
+
2895
+ ## Environment Variables
2896
+
2897
+ Managed via \`.env\` file. Access with:
2898
+
2899
+ 1. **@Value() decorator** (recommended):
2900
+ \`\`\`ts
2901
+ @Value('DATABASE_URL')
2902
+ private dbUrl!: string
2903
+ \`\`\`
2904
+
2905
+ 2. **ConfigService** (for dynamic access):
2906
+ \`\`\`ts
2907
+ @Autowired()
2908
+ private config!: ConfigService
2909
+
2910
+ const port = this.config.get('PORT', 3000)
2911
+ \`\`\`
2912
+
2913
+ 3. **Direct access** (avoid in app code):
2914
+ \`\`\`ts
2915
+ process.env.PORT
2916
+ \`\`\`
2917
+
2918
+ ## Key Decorators
2919
+
2920
+ ### HTTP Routes
2921
+ | Decorator | Purpose |
2922
+ |-----------|---------|
2923
+ | \`@Controller('/path')\` | Define route prefix |
2924
+ | \`@Get('/'), @Post('/')\` | HTTP method handlers |
2925
+ | \`@Middleware(fn)\` | Attach middleware |
2926
+ | \`@Public()\` | Skip auth (requires auth adapter) |
2927
+ | \`@Roles('admin')\` | Role-based access |
2928
+
2929
+ ### Dependency Injection
2930
+ | Decorator | Purpose |
2931
+ |-----------|---------|
2932
+ | \`@Module({})\` | Define feature module |
2933
+ | \`@Service()\` | Register singleton service |
2934
+ | \`@Repository()\` | Register repository |
2935
+ | \`@Autowired()\` | Property injection |
2936
+ | \`@Inject('token')\` | Token-based injection |
2937
+ | \`@Value('VAR')\` | Inject env variable |
2938
+
2939
+ ${e === "graphql" ? "### GraphQL\n| Decorator | Purpose |\n|-----------|---------|\n| `@Resolver()` | GraphQL resolver class |\n| `@Query()` | Query handler |\n| `@Mutation()` | Mutation handler |\n| `@Arg('name')` | Resolver argument |\n\n" : ""}${e === "cqrs" ? "### Background Jobs\n| Decorator | Purpose |\n|-----------|---------|\n| `@Job('name')` | Queue job handler |\n| `@Process('queue')` | Queue processor |\n| `@Cron('0 * * * *')` | Cron schedule |\n| `@WsController()` | WebSocket controller |\n\n" : ""}## Common Pitfalls
2940
+
2941
+ 1. **Forgot to register module** — Add to \`src/modules/index.ts\` exports array
2942
+ 2. **DI not working** — Ensure \`reflect-metadata\` is imported in \`src/index.ts\`
2943
+ 3. **Tests failing randomly** — Missing \`Container.reset()\` in \`beforeEach\`
2944
+ 4. **Routes not found** — Check controller path and module registration
2945
+ 5. **HMR not working** — Verify \`vite.config.ts\` has \`hmr: true\`
2946
+ 6. **Decorators not working** — Check \`tsconfig.json\` has \`experimentalDecorators: true\`
2947
+
2948
+ ## CLI Commands Reference
2949
+
2950
+ | Command | Description |
2951
+ |---------|-------------|
2952
+ | \`kick dev\` | Dev server with HMR |
2953
+ | \`kick dev:debug\` | Dev server with debugger |
2954
+ | \`kick build\` | Production build |
2955
+ | \`kick start\` | Run production build |
2956
+ | \`kick g module <names...>\` | Generate one or more modules |
2957
+ | \`kick g scaffold <name> <fields>\` | Generate CRUD |
2958
+ | \`kick g controller <name>\` | Generate controller |
2959
+ | \`kick g service <name>\` | Generate service |
2960
+ | \`kick g middleware <name>\` | Generate middleware |
2961
+ | \`kick add <package>\` | Add KickJS package |
2962
+ | \`kick add --list\` | List available packages |
2963
+ | \`kick rm module <names...>\` | Remove one or more modules |
2964
+
2965
+ > **Note:** When using \`kick new\` in scripts or CI, pass \`-t\` (or \`--template\`) and \`-r\` (or \`--repo\`) flags to bypass interactive prompts:
2966
+ > \`\`\`bash
2967
+ > kick new my-api -t ddd -r prisma --pm ${t} --no-git --no-install -f
2968
+ > \`\`\`
2969
+
2970
+ ## Learn More
2971
+
2972
+ - [KickJS Docs](https://forinda.github.io/kick-js/)
2973
+ - [CLI Reference](https://forinda.github.io/kick-js/api/cli.html)
2974
+ - [Decorators Guide](https://forinda.github.io/kick-js/guide/decorators.html)
2975
+ - [DI System](https://forinda.github.io/kick-js/guide/dependency-injection.html)
2976
+ - [Testing](https://forinda.github.io/kick-js/api/testing.html)
2977
+ `;
2978
+ }
2979
+ var Ke = Q(oe(import.meta.url)), V = JSON.parse(re(p(Ke, "..", "package.json"), "utf-8")), Je = `^${V.version}`;
2980
+ async function mt(r) {
2981
+ const { name: e, directory: t, packageManager: o = "pnpm", template: s = "rest", defaultRepo: i = "inmemory" } = r, n = t, a = (u) => console.log(` ${u}`);
2982
+ if (console.log(`
2983
+ Creating KickJS project: ${e}
2984
+ `), await l(p(n, "package.json"), je(e, s, Je)), await l(p(n, "vite.config.ts"), Ee()), await l(p(n, "tsconfig.json"), Ue()), await l(p(n, ".prettierrc"), Me()), await l(p(n, ".editorconfig"), qe()), await l(p(n, ".gitignore"), ze()), await l(p(n, ".gitattributes"), _e()), await l(p(n, ".env"), Ge()), await l(p(n, ".env.example"), Qe()), await l(p(n, "src/index.ts"), Le(e, s, V.version)), await l(p(n, "src/modules/index.ts"), Ne()), s === "graphql" && await l(p(n, "src/resolvers/.gitkeep"), ""), await l(p(n, "kick.config.ts"), We(s, i)), await l(p(n, "vitest.config.ts"), Fe()), await l(p(n, "README.md"), Be(e, s, o)), await l(p(n, "CLAUDE.md"), Ye(e, s, o)), await l(p(n, "AGENTS.md"), He(e, s, o)), r.initGit) try {
2985
+ w("git init", {
2986
+ cwd: n,
2987
+ stdio: "pipe"
2988
+ }), w("git branch -M main", {
2989
+ cwd: n,
2990
+ stdio: "pipe"
2991
+ }), w("git add -A", {
2992
+ cwd: n,
2993
+ stdio: "pipe"
2994
+ }), w('git commit -m "chore: initial commit from kick new"', {
2995
+ cwd: n,
2996
+ stdio: "pipe"
2997
+ }), a("Git repository initialized");
2998
+ } catch {
2999
+ a("Warning: git init failed (git may not be installed)");
3000
+ }
3001
+ if (r.installDeps) {
3002
+ console.log(`
3003
+ Installing dependencies with ${o}...
3004
+ `);
3005
+ try {
3006
+ w(`${o} install`, {
3007
+ cwd: n,
3008
+ stdio: "inherit"
3009
+ }), console.log(`
3010
+ Dependencies installed successfully!`);
3011
+ } catch {
3012
+ console.log(`
3013
+ Warning: ${o} install failed. Run it manually.`);
3014
+ }
3015
+ }
3016
+ console.log(`
3017
+ Project scaffolded successfully!`), console.log();
3018
+ const c = n !== process.cwd();
3019
+ a("Next steps:"), c && a(` cd ${e}`), r.installDeps || a(` ${o} install`);
3020
+ const d = {
3021
+ rest: "kick g module user",
3022
+ graphql: "kick g resolver user",
3023
+ ddd: "kick g module user --repo drizzle",
3024
+ cqrs: "kick g module user --pattern cqrs",
3025
+ minimal: "# add your routes to src/index.ts"
3026
+ };
3027
+ a(` ${d[s] ?? d.rest}`), a(" kick dev"), a(""), a("Commands:"), a(" kick dev Start dev server with Vite HMR"), a(" kick build Production build via Vite"), a(" kick start Run production build"), a(""), a("Generators:"), a(" kick g module <name> Full DDD module (controller, DTOs, use-cases, repo)"), a(" kick g scaffold <n> <f..> CRUD module from field definitions"), a(" kick g controller <name> Standalone controller"), a(" kick g service <name> @Service() class"), a(" kick g middleware <name> Express middleware"), a(" kick g guard <name> Route guard (auth, roles, etc.)"), a(" kick g adapter <name> AppAdapter with lifecycle hooks"), a(" kick g dto <name> Zod DTO schema"), s === "graphql" && a(" kick g resolver <name> GraphQL resolver"), s === "cqrs" && a(" kick g job <name> Queue job processor"), a(" kick g config Generate kick.config.ts"), a(""), a("Add packages:"), a(" kick add <pkg> Install a KickJS package + peers"), a(" kick add --list Show all available packages"), a(""), a("Available: auth, swagger, graphql, drizzle, prisma, ws,"), a(" cron, queue, mailer, otel, multi-tenant, notifications, testing"), a("");
3028
+ }
3029
+ var G = [
3030
+ "drizzle",
3031
+ "inmemory",
3032
+ "prisma"
3033
+ ];
3034
+ function ft(r) {
3035
+ return r;
3036
+ }
3037
+ function $t(r) {
3038
+ if (!r) return {};
3039
+ const e = {
3040
+ dir: r.modules?.dir ?? r.modulesDir,
3041
+ repo: r.modules?.repo ?? r.defaultRepo,
3042
+ schemaDir: r.modules?.schemaDir ?? r.schemaDir,
3043
+ pluralize: r.modules?.pluralize ?? r.pluralize,
3044
+ prismaClientPath: r.modules?.prismaClientPath
3045
+ };
3046
+ return e.repo && typeof e.repo == "string" && !G.includes(e.repo) && console.warn(` Warning: modules.repo '${e.repo}' is not a built-in type (${G.join(", ")}). It will generate a stub repository. Use { name: '${e.repo}' } to silence this warning.`), e;
3047
+ }
3048
+ var Ve = [
3049
+ "kick.config.ts",
3050
+ "kick.config.js",
3051
+ "kick.config.mjs",
3052
+ "kick.config.json"
3053
+ ];
3054
+ async function yt(r) {
3055
+ for (const e of Ve) {
3056
+ const t = p(r, e);
3057
+ try {
3058
+ await F(t);
3059
+ } catch {
3060
+ continue;
3061
+ }
3062
+ if (e.endsWith(".json")) {
3063
+ const o = await L(t, "utf-8");
3064
+ return JSON.parse(o);
3065
+ }
3066
+ try {
3067
+ const { pathToFileURL: o } = await import("node:url"), s = await import(o(t).href);
3068
+ return s.default ?? s;
3069
+ } catch {
3070
+ e.endsWith(".ts") && console.warn(`Warning: Failed to load ${e}. TypeScript config files require a runtime loader (e.g. tsx, ts-node) or use kick.config.js/.mjs instead.`);
3071
+ continue;
3072
+ }
3073
+ }
3074
+ return null;
3075
+ }
3076
+ export {
3077
+ h as _,
3078
+ ut as a,
3079
+ l as b,
3080
+ dt as c,
3081
+ at as d,
3082
+ it as f,
3083
+ y as g,
3084
+ P as h,
3085
+ mt as i,
3086
+ ct as l,
3087
+ se as m,
3088
+ yt as n,
3089
+ lt as o,
3090
+ Y as p,
3091
+ $t as r,
3092
+ pt as s,
3093
+ ft as t,
3094
+ nt as u,
3095
+ B as v,
3096
+ st as y
3097
+ };