nodejs-quickstart-structure 1.18.0 → 1.19.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 (113) hide show
  1. package/CHANGELOG.md +17 -4
  2. package/README.md +2 -1
  3. package/bin/index.js +93 -92
  4. package/lib/generator.js +1 -1
  5. package/lib/modules/caching-setup.js +76 -73
  6. package/lib/modules/config-files.js +4 -0
  7. package/lib/modules/kafka-setup.js +249 -191
  8. package/lib/modules/project-setup.js +1 -0
  9. package/package.json +13 -2
  10. package/templates/clean-architecture/js/src/errors/BadRequestError.js +11 -10
  11. package/templates/clean-architecture/js/src/errors/BadRequestError.spec.js.ejs +22 -21
  12. package/templates/clean-architecture/js/src/errors/NotFoundError.js +11 -10
  13. package/templates/clean-architecture/js/src/errors/NotFoundError.spec.js.ejs +22 -21
  14. package/templates/clean-architecture/js/src/infrastructure/repositories/UserRepository.js.ejs +69 -39
  15. package/templates/clean-architecture/js/src/infrastructure/repositories/UserRepository.spec.js.ejs +142 -81
  16. package/templates/clean-architecture/js/src/infrastructure/webserver/server.js.ejs +1 -1
  17. package/templates/clean-architecture/js/src/interfaces/controllers/userController.js.ejs +156 -75
  18. package/templates/clean-architecture/js/src/interfaces/controllers/userController.spec.js.ejs +234 -138
  19. package/templates/clean-architecture/js/src/interfaces/graphql/resolvers/user.resolvers.js.ejs +27 -21
  20. package/templates/clean-architecture/js/src/interfaces/graphql/resolvers/user.resolvers.spec.js.ejs +66 -49
  21. package/templates/clean-architecture/js/src/interfaces/graphql/typeDefs/user.types.js.ejs +19 -17
  22. package/templates/clean-architecture/js/src/interfaces/routes/api.js +12 -10
  23. package/templates/clean-architecture/js/src/usecases/DeleteUser.js +11 -0
  24. package/templates/clean-architecture/js/src/usecases/DeleteUser.spec.js.ejs +47 -0
  25. package/templates/clean-architecture/js/src/usecases/UpdateUser.js +11 -0
  26. package/templates/clean-architecture/js/src/usecases/UpdateUser.spec.js.ejs +48 -0
  27. package/templates/clean-architecture/js/src/utils/errorMessages.js +14 -0
  28. package/templates/clean-architecture/ts/src/errors/BadRequestError.spec.ts.ejs +22 -21
  29. package/templates/clean-architecture/ts/src/errors/BadRequestError.ts +9 -8
  30. package/templates/clean-architecture/ts/src/errors/NotFoundError.spec.ts.ejs +22 -21
  31. package/templates/clean-architecture/ts/src/errors/NotFoundError.ts +9 -8
  32. package/templates/clean-architecture/ts/src/index.ts.ejs +1 -1
  33. package/templates/clean-architecture/ts/src/infrastructure/repositories/UserRepository.spec.ts.ejs +175 -85
  34. package/templates/clean-architecture/ts/src/infrastructure/repositories/userRepository.ts.ejs +74 -0
  35. package/templates/clean-architecture/ts/src/interfaces/controllers/userController.spec.ts.ejs +331 -185
  36. package/templates/clean-architecture/ts/src/interfaces/controllers/userController.ts.ejs +173 -84
  37. package/templates/clean-architecture/ts/src/interfaces/graphql/resolvers/user.resolvers.spec.ts.ejs +68 -51
  38. package/templates/clean-architecture/ts/src/interfaces/graphql/resolvers/user.resolvers.ts.ejs +29 -21
  39. package/templates/clean-architecture/ts/src/interfaces/graphql/typeDefs/user.types.ts.ejs +17 -15
  40. package/templates/clean-architecture/ts/src/interfaces/routes/userRoutes.ts +13 -11
  41. package/templates/clean-architecture/ts/src/usecases/deleteUser.spec.ts.ejs +47 -0
  42. package/templates/clean-architecture/ts/src/usecases/deleteUser.ts +9 -0
  43. package/templates/clean-architecture/ts/src/usecases/updateUser.spec.ts.ejs +48 -0
  44. package/templates/clean-architecture/ts/src/usecases/updateUser.ts +9 -0
  45. package/templates/clean-architecture/ts/src/utils/errorMessages.ts +12 -0
  46. package/templates/common/.gitattributes +46 -0
  47. package/templates/common/.snyk.ejs +45 -0
  48. package/templates/common/Dockerfile +17 -9
  49. package/templates/common/README.md.ejs +295 -263
  50. package/templates/common/caching/clean/js/DeleteUser.js.ejs +27 -0
  51. package/templates/common/caching/clean/js/UpdateUser.js.ejs +27 -0
  52. package/templates/common/caching/clean/ts/deleteUser.ts.ejs +24 -0
  53. package/templates/common/caching/clean/ts/updateUser.ts.ejs +25 -0
  54. package/templates/common/caching/ts/memoryCache.ts.ejs +73 -64
  55. package/templates/common/caching/ts/redisClient.ts.ejs +89 -80
  56. package/templates/common/database/js/models/User.js.ejs +79 -53
  57. package/templates/common/database/js/models/User.js.mongoose.ejs +23 -19
  58. package/templates/common/database/js/models/User.spec.js.ejs +94 -84
  59. package/templates/common/database/ts/models/User.spec.ts.ejs +100 -84
  60. package/templates/common/database/ts/models/User.ts.ejs +87 -61
  61. package/templates/common/database/ts/models/User.ts.mongoose.ejs +30 -25
  62. package/templates/common/health/js/healthRoute.js.ejs +50 -47
  63. package/templates/common/health/ts/healthRoute.ts.ejs +49 -46
  64. package/templates/common/jest.e2e.config.js.ejs +8 -8
  65. package/templates/common/kafka/js/messaging/baseConsumer.js.ejs +30 -30
  66. package/templates/common/kafka/js/messaging/userEventSchema.js.ejs +12 -11
  67. package/templates/common/kafka/js/messaging/welcomeEmailConsumer.js.ejs +44 -31
  68. package/templates/common/kafka/js/messaging/welcomeEmailConsumer.spec.js.ejs +86 -49
  69. package/templates/common/kafka/js/services/kafkaService.js.ejs +93 -93
  70. package/templates/common/kafka/js/utils/kafkaEvents.js.ejs +7 -0
  71. package/templates/common/kafka/ts/messaging/userEventSchema.spec.ts.ejs +51 -51
  72. package/templates/common/kafka/ts/messaging/userEventSchema.ts.ejs +12 -11
  73. package/templates/common/kafka/ts/messaging/welcomeEmailConsumer.spec.ts.ejs +86 -49
  74. package/templates/common/kafka/ts/messaging/welcomeEmailConsumer.ts.ejs +38 -25
  75. package/templates/common/kafka/ts/services/kafkaService.ts.ejs +95 -95
  76. package/templates/common/kafka/ts/utils/kafkaEvents.ts.ejs +5 -0
  77. package/templates/common/package.json.ejs +10 -2
  78. package/templates/common/shutdown/js/gracefulShutdown.js.ejs +65 -61
  79. package/templates/common/shutdown/js/gracefulShutdown.spec.js.ejs +149 -160
  80. package/templates/common/shutdown/ts/gracefulShutdown.spec.ts.ejs +179 -158
  81. package/templates/common/shutdown/ts/gracefulShutdown.ts.ejs +59 -55
  82. package/templates/common/src/tests/e2e/e2e.users.test.js.ejs +120 -49
  83. package/templates/common/src/tests/e2e/e2e.users.test.ts.ejs +120 -49
  84. package/templates/common/swagger.yml.ejs +118 -66
  85. package/templates/db/mysql/V1__Initial_Setup.sql.ejs +10 -9
  86. package/templates/db/postgres/V1__Initial_Setup.sql.ejs +10 -9
  87. package/templates/mvc/js/src/controllers/userController.js.ejs +246 -105
  88. package/templates/mvc/js/src/controllers/userController.spec.js.ejs +481 -209
  89. package/templates/mvc/js/src/errors/BadRequestError.js +11 -10
  90. package/templates/mvc/js/src/errors/BadRequestError.spec.js.ejs +22 -21
  91. package/templates/mvc/js/src/errors/NotFoundError.js +11 -10
  92. package/templates/mvc/js/src/errors/NotFoundError.spec.js.ejs +22 -21
  93. package/templates/mvc/js/src/graphql/resolvers/user.resolvers.js.ejs +25 -19
  94. package/templates/mvc/js/src/graphql/resolvers/user.resolvers.spec.js.ejs +64 -47
  95. package/templates/mvc/js/src/graphql/typeDefs/user.types.js.ejs +19 -17
  96. package/templates/mvc/js/src/index.js.ejs +1 -1
  97. package/templates/mvc/js/src/routes/api.js +10 -8
  98. package/templates/mvc/js/src/routes/api.spec.js.ejs +41 -36
  99. package/templates/mvc/js/src/utils/errorMessages.js +14 -0
  100. package/templates/mvc/ts/src/controllers/userController.spec.ts.ejs +481 -203
  101. package/templates/mvc/ts/src/controllers/userController.ts.ejs +248 -107
  102. package/templates/mvc/ts/src/errors/BadRequestError.spec.ts.ejs +22 -21
  103. package/templates/mvc/ts/src/errors/BadRequestError.ts +9 -8
  104. package/templates/mvc/ts/src/errors/NotFoundError.spec.ts.ejs +27 -21
  105. package/templates/mvc/ts/src/errors/NotFoundError.ts +9 -8
  106. package/templates/mvc/ts/src/graphql/resolvers/user.resolvers.spec.ts.ejs +68 -51
  107. package/templates/mvc/ts/src/graphql/resolvers/user.resolvers.ts.ejs +29 -21
  108. package/templates/mvc/ts/src/graphql/typeDefs/user.types.ts.ejs +17 -15
  109. package/templates/mvc/ts/src/index.ts.ejs +156 -153
  110. package/templates/mvc/ts/src/routes/api.spec.ts.ejs +59 -40
  111. package/templates/mvc/ts/src/routes/api.ts +12 -10
  112. package/templates/mvc/ts/src/utils/errorMessages.ts +12 -0
  113. package/templates/clean-architecture/ts/src/infrastructure/repositories/UserRepository.ts.ejs +0 -37
@@ -0,0 +1,46 @@
1
+ # Enforce LF endings for all text files
2
+ * text=auto eol=lf
3
+
4
+ # Explicitly handle common text file types
5
+ *.js text eol=lf
6
+ *.ts text eol=lf
7
+ *.tsx text eol=lf
8
+ *.jsx text eol=lf
9
+ *.mjs text eol=lf
10
+ *.cjs text eol=lf
11
+ *.json text eol=lf
12
+ *.md text eol=lf
13
+ *.sh text eol=lf
14
+ *.yml text eol=lf
15
+ *.yaml text eol=lf
16
+ *.html text eol=lf
17
+ *.css text eol=lf
18
+ *.scss text eol=lf
19
+ *.less text eol=lf
20
+ *.graphql text eol=lf
21
+ *.sql text eol=lf
22
+ *.pug text eol=lf
23
+
24
+ # Configuration files
25
+ .env* text eol=lf
26
+ .editorconfig text eol=lf
27
+ .prettierrc text eol=lf
28
+ .eslintrc* text eol=lf
29
+ .gitignore text eol=lf
30
+ .dockerignore text eol=lf
31
+ .gitattributes text eol=lf
32
+
33
+ # Assets
34
+ *.png binary
35
+ *.jpg binary
36
+ *.jpeg binary
37
+ *.gif binary
38
+ *.ico binary
39
+ *.webp binary
40
+ *.avif binary
41
+ *.pdf binary
42
+ *.woff binary
43
+ *.woff2 binary
44
+ *.ttf binary
45
+ *.eot binary
46
+ *.svg text eol=lf
@@ -0,0 +1,45 @@
1
+ # Snyk (https://snyk.io) policy file, default is to interrupt on any vulnerability found.
2
+ # This file ignores vulnerabilities internal to the package manager (npm) itself,
3
+ # as they do not affect your application's production security posture.
4
+ version: v1.18.2
5
+ ignore:
6
+ # Minimatch ReDoS/Complexity in npm internal dependencies
7
+ SNYK-JS-MINIMATCH-15353387:
8
+ - '*':
9
+ reason: Internal npm dependency, does not affect application runtime.
10
+ expires: '2027-03-27T10:00:00.000Z'
11
+ SNYK-JS-MINIMATCH-15353389:
12
+ - '*':
13
+ reason: Internal npm dependency, does not affect application runtime.
14
+ expires: '2027-03-27T10:00:00.000Z'
15
+ SNYK-JS-MINIMATCH-15309438:
16
+ - '*':
17
+ reason: Internal npm dependency, does not affect application runtime.
18
+ expires: '2027-03-27T10:00:00.000Z'
19
+ # Tar Symlink Attack in npm internal dependencies
20
+ SNYK-JS-TAR-15456201:
21
+ - '*':
22
+ reason: Internal npm dependency, does not affect application runtime.
23
+ expires: '2027-03-27T10:00:00.000Z'
24
+ SNYK-JS-TAR-15416075:
25
+ - '*':
26
+ reason: Internal npm dependency, does not affect application runtime.
27
+ expires: '2027-03-27T10:00:00.000Z'
28
+ SNYK-JS-TAR-15307072:
29
+ - '*':
30
+ reason: Internal npm dependency, does not affect application runtime.
31
+ expires: '2027-03-27T10:00:00.000Z'
32
+ # Brace-expansion Infinite Loop in npm internal dependencies
33
+ SNYK-JS-BRACEEXPANSION-15789759:
34
+ - '*':
35
+ reason: Internal npm dependency, does not affect application runtime.
36
+ expires: '2027-03-27T10:00:00.000Z'
37
+ SNYK-JS-ISAACSBRACEEXPANSION-15208653:
38
+ - '*':
39
+ reason: Internal npm dependency, does not affect application runtime.
40
+ expires: '2027-03-27T10:00:00.000Z'
41
+ # Picomatch ReDoS in npm internal dependencies
42
+ SNYK-JS-PICOMATCH-15765511:
43
+ - '*':
44
+ reason: Internal npm dependency, does not affect application runtime.
45
+ expires: '2027-03-27T10:00:00.000Z'
@@ -1,16 +1,18 @@
1
1
  # ==========================================
2
2
  # Stage 1: Builder
3
3
  # ==========================================
4
- FROM node:22.22.2-trixie-slim AS builder
4
+ FROM node:22-alpine AS builder
5
5
 
6
6
  # Upgrade OS packages to fix upstream vulnerabilities (Snyk-detected)
7
- RUN apt-get update && apt-get upgrade -y && \
8
- apt-get install -y --no-install-recommends ca-certificates && \
9
- rm -rf /var/lib/apt/lists/*
7
+ RUN apk update && apk upgrade && \
8
+ apk add --no-cache ca-certificates zlib>=1.3.2-r0 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
10
9
 
11
10
  WORKDIR /app
12
11
  ENV NPM_CONFIG_UPDATE_NOTIFIER=false
13
12
 
13
+ # Upgrade npm using corepack (safer in Alpine)
14
+ RUN corepack enable && corepack prepare npm@11.6.4 --activate
15
+
14
16
  COPY package*.json ./
15
17
  COPY tsconfig*.json ./
16
18
 
@@ -25,23 +27,28 @@ COPY . .
25
27
  # ==========================================
26
28
  # Stage 2: Production
27
29
  # ==========================================
28
- FROM node:22.22.2-trixie-slim AS production
30
+ FROM node:22-alpine AS production
29
31
 
30
32
  # Upgrade OS packages to fix upstream vulnerabilities (Snyk-detected)
31
- RUN apt-get update && apt-get upgrade -y && \
32
- apt-get install -y --no-install-recommends ca-certificates && \
33
- rm -rf /var/lib/apt/lists/*
33
+ RUN apk update && apk upgrade && \
34
+ apk add --no-cache ca-certificates zlib>=1.3.2-r0 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
34
35
 
35
36
  WORKDIR /app
36
37
 
37
38
  ENV NODE_ENV=production
38
39
  ENV NPM_CONFIG_UPDATE_NOTIFIER=false
39
40
 
41
+ # Upgrade npm using corepack (safer in Alpine)
42
+ RUN corepack enable && corepack prepare npm@11.6.4 --activate
43
+
40
44
  COPY package*.json ./
41
45
 
42
46
  # Install ONLY production dependencies
43
47
  RUN npm ci --only=production --ignore-scripts --no-audit --no-fund || npm ci --only=production --ignore-scripts --no-audit --no-fund || npm ci --only=production --ignore-scripts --no-audit --no-fund
44
48
 
49
+ # Remove npm and caches to achieve Zero-Vulnerability status in the final image
50
+ RUN rm -rf /usr/local/lib/node_modules/npm /usr/local/bin/npm /usr/local/bin/npx /root/.npm /root/.cache
51
+
45
52
  # Copy built artifacts from builder
46
53
  <% if (language === 'TypeScript') { %>
47
54
  COPY --from=builder /app/dist ./dist
@@ -62,4 +69,5 @@ RUN mkdir -p logs && chown -R node:node logs
62
69
 
63
70
  USER node
64
71
 
65
- CMD ["npm", "start"]
72
+ # Start application directly with node (safe even without npm)
73
+ CMD ["node", "<% if (language === 'TypeScript') { %>dist/index.js<% } else { %>src/index.js<% } %>"]