nodejs-structure-cli 1.0.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 (243) hide show
  1. package/README.md +32 -0
  2. package/bin/index.js +143 -0
  3. package/lib/generator.js +145 -0
  4. package/lib/modules/app-setup.js +479 -0
  5. package/lib/modules/caching-setup.js +76 -0
  6. package/lib/modules/config-files.js +151 -0
  7. package/lib/modules/database-setup.js +116 -0
  8. package/lib/modules/kafka-setup.js +249 -0
  9. package/lib/modules/project-setup.js +32 -0
  10. package/lib/prompts.js +128 -0
  11. package/package.json +66 -0
  12. package/templates/clean-architecture/js/src/domain/models/User.js.ejs +11 -0
  13. package/templates/clean-architecture/js/src/errors/ApiError.js +14 -0
  14. package/templates/clean-architecture/js/src/errors/BadRequestError.js +11 -0
  15. package/templates/clean-architecture/js/src/errors/BadRequestError.spec.js.ejs +22 -0
  16. package/templates/clean-architecture/js/src/errors/NotFoundError.js +11 -0
  17. package/templates/clean-architecture/js/src/errors/NotFoundError.spec.js.ejs +22 -0
  18. package/templates/clean-architecture/js/src/index.js.ejs +56 -0
  19. package/templates/clean-architecture/js/src/infrastructure/config/env.js.ejs +47 -0
  20. package/templates/clean-architecture/js/src/infrastructure/log/logger.js +36 -0
  21. package/templates/clean-architecture/js/src/infrastructure/log/logger.spec.js.ejs +63 -0
  22. package/templates/clean-architecture/js/src/infrastructure/repositories/UserRepository.js.ejs +88 -0
  23. package/templates/clean-architecture/js/src/infrastructure/repositories/UserRepository.spec.js.ejs +142 -0
  24. package/templates/clean-architecture/js/src/infrastructure/webserver/middleware/errorMiddleware.js +30 -0
  25. package/templates/clean-architecture/js/src/infrastructure/webserver/server.js.ejs +93 -0
  26. package/templates/clean-architecture/js/src/infrastructure/webserver/swagger.js.ejs +6 -0
  27. package/templates/clean-architecture/js/src/interfaces/controllers/userController.js.ejs +190 -0
  28. package/templates/clean-architecture/js/src/interfaces/controllers/userController.spec.js.ejs +234 -0
  29. package/templates/clean-architecture/js/src/interfaces/graphql/context.js.ejs +13 -0
  30. package/templates/clean-architecture/js/src/interfaces/graphql/context.spec.js.ejs +31 -0
  31. package/templates/clean-architecture/js/src/interfaces/graphql/index.js.ejs +5 -0
  32. package/templates/clean-architecture/js/src/interfaces/graphql/resolvers/index.js.ejs +6 -0
  33. package/templates/clean-architecture/js/src/interfaces/graphql/resolvers/user.resolvers.js.ejs +27 -0
  34. package/templates/clean-architecture/js/src/interfaces/graphql/resolvers/user.resolvers.spec.js.ejs +66 -0
  35. package/templates/clean-architecture/js/src/interfaces/graphql/typeDefs/index.js.ejs +6 -0
  36. package/templates/clean-architecture/js/src/interfaces/graphql/typeDefs/user.types.js.ejs +19 -0
  37. package/templates/clean-architecture/js/src/interfaces/routes/api.js.ejs +17 -0
  38. package/templates/clean-architecture/js/src/interfaces/routes/api.spec.js.ejs +38 -0
  39. package/templates/clean-architecture/js/src/usecases/CreateUser.js.ejs +14 -0
  40. package/templates/clean-architecture/js/src/usecases/CreateUser.spec.js.ejs +51 -0
  41. package/templates/clean-architecture/js/src/usecases/DeleteUser.js +11 -0
  42. package/templates/clean-architecture/js/src/usecases/DeleteUser.spec.js.ejs +47 -0
  43. package/templates/clean-architecture/js/src/usecases/GetAllUsers.js +12 -0
  44. package/templates/clean-architecture/js/src/usecases/GetAllUsers.spec.js.ejs +61 -0
  45. package/templates/clean-architecture/js/src/usecases/UpdateUser.js.ejs +11 -0
  46. package/templates/clean-architecture/js/src/usecases/UpdateUser.spec.js.ejs +48 -0
  47. package/templates/clean-architecture/js/src/utils/errorMessages.js +14 -0
  48. package/templates/clean-architecture/js/src/utils/httpCodes.js +9 -0
  49. package/templates/clean-architecture/ts/src/config/env.ts.ejs +46 -0
  50. package/templates/clean-architecture/ts/src/config/swagger.ts.ejs +6 -0
  51. package/templates/clean-architecture/ts/src/domain/user.ts.ejs +9 -0
  52. package/templates/clean-architecture/ts/src/errors/ApiError.ts +15 -0
  53. package/templates/clean-architecture/ts/src/errors/BadRequestError.spec.ts.ejs +22 -0
  54. package/templates/clean-architecture/ts/src/errors/BadRequestError.ts +9 -0
  55. package/templates/clean-architecture/ts/src/errors/NotFoundError.spec.ts.ejs +22 -0
  56. package/templates/clean-architecture/ts/src/errors/NotFoundError.ts +9 -0
  57. package/templates/clean-architecture/ts/src/index.ts.ejs +144 -0
  58. package/templates/clean-architecture/ts/src/infrastructure/log/logger.spec.ts.ejs +63 -0
  59. package/templates/clean-architecture/ts/src/infrastructure/log/logger.ts +36 -0
  60. package/templates/clean-architecture/ts/src/infrastructure/repositories/UserRepository.spec.ts.ejs +175 -0
  61. package/templates/clean-architecture/ts/src/infrastructure/repositories/userRepository.ts.ejs +125 -0
  62. package/templates/clean-architecture/ts/src/interfaces/controllers/userController.spec.ts.ejs +331 -0
  63. package/templates/clean-architecture/ts/src/interfaces/controllers/userController.ts.ejs +208 -0
  64. package/templates/clean-architecture/ts/src/interfaces/graphql/context.spec.ts.ejs +32 -0
  65. package/templates/clean-architecture/ts/src/interfaces/graphql/context.ts.ejs +17 -0
  66. package/templates/clean-architecture/ts/src/interfaces/graphql/index.ts.ejs +3 -0
  67. package/templates/clean-architecture/ts/src/interfaces/graphql/resolvers/index.ts.ejs +4 -0
  68. package/templates/clean-architecture/ts/src/interfaces/graphql/resolvers/user.resolvers.spec.ts.ejs +68 -0
  69. package/templates/clean-architecture/ts/src/interfaces/graphql/resolvers/user.resolvers.ts.ejs +29 -0
  70. package/templates/clean-architecture/ts/src/interfaces/graphql/typeDefs/index.ts.ejs +4 -0
  71. package/templates/clean-architecture/ts/src/interfaces/graphql/typeDefs/user.types.ts.ejs +17 -0
  72. package/templates/clean-architecture/ts/src/interfaces/routes/userRoutes.spec.ts.ejs +40 -0
  73. package/templates/clean-architecture/ts/src/interfaces/routes/userRoutes.ts.ejs +18 -0
  74. package/templates/clean-architecture/ts/src/usecases/createUser.spec.ts.ejs +51 -0
  75. package/templates/clean-architecture/ts/src/usecases/createUser.ts.ejs +11 -0
  76. package/templates/clean-architecture/ts/src/usecases/deleteUser.spec.ts.ejs +47 -0
  77. package/templates/clean-architecture/ts/src/usecases/deleteUser.ts +9 -0
  78. package/templates/clean-architecture/ts/src/usecases/getAllUsers.spec.ts.ejs +63 -0
  79. package/templates/clean-architecture/ts/src/usecases/getAllUsers.ts +10 -0
  80. package/templates/clean-architecture/ts/src/usecases/updateUser.spec.ts.ejs +48 -0
  81. package/templates/clean-architecture/ts/src/usecases/updateUser.ts.ejs +10 -0
  82. package/templates/clean-architecture/ts/src/utils/errorMessages.ts +12 -0
  83. package/templates/clean-architecture/ts/src/utils/errorMiddleware.ts.ejs +27 -0
  84. package/templates/clean-architecture/ts/src/utils/httpCodes.ts +7 -0
  85. package/templates/common/.cursorrules.ejs +60 -0
  86. package/templates/common/.dockerignore +12 -0
  87. package/templates/common/.env.example.ejs +60 -0
  88. package/templates/common/.gitattributes +46 -0
  89. package/templates/common/.gitlab-ci.yml.ejs +86 -0
  90. package/templates/common/.lintstagedrc +6 -0
  91. package/templates/common/.prettierrc +7 -0
  92. package/templates/common/.snyk.ejs +45 -0
  93. package/templates/common/Dockerfile +73 -0
  94. package/templates/common/Jenkinsfile.ejs +87 -0
  95. package/templates/common/README.md.ejs +148 -0
  96. package/templates/common/_github/workflows/ci.yml.ejs +46 -0
  97. package/templates/common/_github/workflows/security.yml.ejs +36 -0
  98. package/templates/common/_gitignore +5 -0
  99. package/templates/common/_husky/pre-commit +4 -0
  100. package/templates/common/caching/clean/js/CreateUser.js.ejs +29 -0
  101. package/templates/common/caching/clean/js/DeleteUser.js.ejs +27 -0
  102. package/templates/common/caching/clean/js/GetAllUsers.js.ejs +37 -0
  103. package/templates/common/caching/clean/js/UpdateUser.js.ejs +27 -0
  104. package/templates/common/caching/clean/ts/createUser.ts.ejs +27 -0
  105. package/templates/common/caching/clean/ts/deleteUser.ts.ejs +24 -0
  106. package/templates/common/caching/clean/ts/getAllUsers.ts.ejs +34 -0
  107. package/templates/common/caching/clean/ts/updateUser.ts.ejs +25 -0
  108. package/templates/common/caching/js/memoryCache.js.ejs +60 -0
  109. package/templates/common/caching/js/memoryCache.spec.js.ejs +101 -0
  110. package/templates/common/caching/js/redisClient.js.ejs +75 -0
  111. package/templates/common/caching/js/redisClient.spec.js.ejs +147 -0
  112. package/templates/common/caching/ts/memoryCache.spec.ts.ejs +102 -0
  113. package/templates/common/caching/ts/memoryCache.ts.ejs +73 -0
  114. package/templates/common/caching/ts/redisClient.spec.ts.ejs +157 -0
  115. package/templates/common/caching/ts/redisClient.ts.ejs +89 -0
  116. package/templates/common/database/js/database.js.ejs +19 -0
  117. package/templates/common/database/js/database.spec.js.ejs +56 -0
  118. package/templates/common/database/js/models/User.js.ejs +91 -0
  119. package/templates/common/database/js/models/User.js.mongoose.ejs +35 -0
  120. package/templates/common/database/js/models/User.spec.js.ejs +94 -0
  121. package/templates/common/database/js/mongoose.js.ejs +33 -0
  122. package/templates/common/database/js/mongoose.spec.js.ejs +43 -0
  123. package/templates/common/database/ts/database.spec.ts.ejs +56 -0
  124. package/templates/common/database/ts/database.ts.ejs +21 -0
  125. package/templates/common/database/ts/models/User.spec.ts.ejs +100 -0
  126. package/templates/common/database/ts/models/User.ts.ejs +102 -0
  127. package/templates/common/database/ts/models/User.ts.mongoose.ejs +34 -0
  128. package/templates/common/database/ts/mongoose.spec.ts.ejs +42 -0
  129. package/templates/common/database/ts/mongoose.ts.ejs +28 -0
  130. package/templates/common/docker-compose.yml.ejs +159 -0
  131. package/templates/common/ecosystem.config.js.ejs +40 -0
  132. package/templates/common/eslint.config.mjs.ejs +77 -0
  133. package/templates/common/health/js/healthRoute.js.ejs +50 -0
  134. package/templates/common/health/js/healthRoute.spec.js.ejs +70 -0
  135. package/templates/common/health/ts/healthRoute.spec.ts.ejs +76 -0
  136. package/templates/common/health/ts/healthRoute.ts.ejs +49 -0
  137. package/templates/common/jest.config.js.ejs +32 -0
  138. package/templates/common/jest.e2e.config.js.ejs +8 -0
  139. package/templates/common/kafka/js/config/kafka.js +9 -0
  140. package/templates/common/kafka/js/config/kafka.spec.js.ejs +27 -0
  141. package/templates/common/kafka/js/messaging/baseConsumer.js.ejs +30 -0
  142. package/templates/common/kafka/js/messaging/baseConsumer.spec.js.ejs +58 -0
  143. package/templates/common/kafka/js/messaging/userEventSchema.js.ejs +12 -0
  144. package/templates/common/kafka/js/messaging/userEventSchema.spec.js.ejs +27 -0
  145. package/templates/common/kafka/js/messaging/welcomeEmailConsumer.js.ejs +44 -0
  146. package/templates/common/kafka/js/messaging/welcomeEmailConsumer.spec.js.ejs +86 -0
  147. package/templates/common/kafka/js/services/kafkaService.js.ejs +93 -0
  148. package/templates/common/kafka/js/services/kafkaService.spec.js.ejs +106 -0
  149. package/templates/common/kafka/js/utils/kafkaEvents.js.ejs +7 -0
  150. package/templates/common/kafka/ts/config/kafka.spec.ts.ejs +27 -0
  151. package/templates/common/kafka/ts/config/kafka.ts +7 -0
  152. package/templates/common/kafka/ts/messaging/baseConsumer.spec.ts.ejs +50 -0
  153. package/templates/common/kafka/ts/messaging/baseConsumer.ts.ejs +27 -0
  154. package/templates/common/kafka/ts/messaging/userEventSchema.spec.ts.ejs +51 -0
  155. package/templates/common/kafka/ts/messaging/userEventSchema.ts.ejs +12 -0
  156. package/templates/common/kafka/ts/messaging/welcomeEmailConsumer.spec.ts.ejs +86 -0
  157. package/templates/common/kafka/ts/messaging/welcomeEmailConsumer.ts.ejs +38 -0
  158. package/templates/common/kafka/ts/services/kafkaService.spec.ts.ejs +81 -0
  159. package/templates/common/kafka/ts/services/kafkaService.ts.ejs +95 -0
  160. package/templates/common/kafka/ts/utils/kafkaEvents.ts.ejs +5 -0
  161. package/templates/common/migrate-mongo-config.js.ejs +31 -0
  162. package/templates/common/migrations/init.js.ejs +23 -0
  163. package/templates/common/package.json.ejs +137 -0
  164. package/templates/common/prompts/add-feature.md.ejs +26 -0
  165. package/templates/common/prompts/project-context.md.ejs +43 -0
  166. package/templates/common/prompts/troubleshoot.md.ejs +28 -0
  167. package/templates/common/public/css/style.css +147 -0
  168. package/templates/common/scripts/run-e2e.js.ejs +63 -0
  169. package/templates/common/shutdown/js/gracefulShutdown.js.ejs +65 -0
  170. package/templates/common/shutdown/js/gracefulShutdown.spec.js.ejs +149 -0
  171. package/templates/common/shutdown/ts/gracefulShutdown.spec.ts.ejs +179 -0
  172. package/templates/common/shutdown/ts/gracefulShutdown.ts.ejs +59 -0
  173. package/templates/common/sonar-project.properties.ejs +27 -0
  174. package/templates/common/src/config/auth.js.ejs +19 -0
  175. package/templates/common/src/config/auth.ts.ejs +19 -0
  176. package/templates/common/src/controllers/authController.js.ejs +101 -0
  177. package/templates/common/src/controllers/authController.ts.ejs +101 -0
  178. package/templates/common/src/middleware/auth.js.ejs +20 -0
  179. package/templates/common/src/middleware/auth.ts.ejs +25 -0
  180. package/templates/common/src/middleware/upload.js.ejs +31 -0
  181. package/templates/common/src/middleware/upload.ts.ejs +32 -0
  182. package/templates/common/src/routes/authRoutes.js.ejs +20 -0
  183. package/templates/common/src/routes/authRoutes.ts.ejs +20 -0
  184. package/templates/common/src/tests/e2e/e2e.users.test.js.ejs +120 -0
  185. package/templates/common/src/tests/e2e/e2e.users.test.ts.ejs +120 -0
  186. package/templates/common/src/utils/errorMiddleware.spec.js.ejs +79 -0
  187. package/templates/common/src/utils/errorMiddleware.spec.ts.ejs +94 -0
  188. package/templates/common/swagger.yml.ejs +118 -0
  189. package/templates/common/tsconfig.json +23 -0
  190. package/templates/common/views/ejs/index.ejs +55 -0
  191. package/templates/common/views/pug/index.pug +40 -0
  192. package/templates/db/mysql/V1__Initial_Setup.sql.ejs +10 -0
  193. package/templates/db/postgres/V1__Initial_Setup.sql.ejs +10 -0
  194. package/templates/mvc/js/src/config/env.js.ejs +46 -0
  195. package/templates/mvc/js/src/config/swagger.js.ejs +6 -0
  196. package/templates/mvc/js/src/controllers/userController.js.ejs +288 -0
  197. package/templates/mvc/js/src/controllers/userController.spec.js.ejs +481 -0
  198. package/templates/mvc/js/src/errors/ApiError.js +14 -0
  199. package/templates/mvc/js/src/errors/BadRequestError.js +11 -0
  200. package/templates/mvc/js/src/errors/BadRequestError.spec.js.ejs +22 -0
  201. package/templates/mvc/js/src/errors/NotFoundError.js +11 -0
  202. package/templates/mvc/js/src/errors/NotFoundError.spec.js.ejs +22 -0
  203. package/templates/mvc/js/src/graphql/context.js.ejs +7 -0
  204. package/templates/mvc/js/src/graphql/context.spec.js.ejs +29 -0
  205. package/templates/mvc/js/src/graphql/index.js.ejs +5 -0
  206. package/templates/mvc/js/src/graphql/resolvers/index.js.ejs +6 -0
  207. package/templates/mvc/js/src/graphql/resolvers/user.resolvers.js.ejs +25 -0
  208. package/templates/mvc/js/src/graphql/resolvers/user.resolvers.spec.js.ejs +64 -0
  209. package/templates/mvc/js/src/graphql/typeDefs/index.js.ejs +6 -0
  210. package/templates/mvc/js/src/graphql/typeDefs/user.types.js.ejs +19 -0
  211. package/templates/mvc/js/src/index.js.ejs +141 -0
  212. package/templates/mvc/js/src/routes/api.js.ejs +15 -0
  213. package/templates/mvc/js/src/routes/api.spec.js.ejs +41 -0
  214. package/templates/mvc/js/src/utils/errorMessages.js +14 -0
  215. package/templates/mvc/js/src/utils/errorMiddleware.js +29 -0
  216. package/templates/mvc/js/src/utils/httpCodes.js +9 -0
  217. package/templates/mvc/js/src/utils/logger.js +40 -0
  218. package/templates/mvc/js/src/utils/logger.spec.js.ejs +63 -0
  219. package/templates/mvc/ts/src/config/env.ts.ejs +45 -0
  220. package/templates/mvc/ts/src/config/swagger.ts.ejs +6 -0
  221. package/templates/mvc/ts/src/controllers/userController.spec.ts.ejs +481 -0
  222. package/templates/mvc/ts/src/controllers/userController.ts.ejs +292 -0
  223. package/templates/mvc/ts/src/errors/ApiError.ts +15 -0
  224. package/templates/mvc/ts/src/errors/BadRequestError.spec.ts.ejs +22 -0
  225. package/templates/mvc/ts/src/errors/BadRequestError.ts +9 -0
  226. package/templates/mvc/ts/src/errors/NotFoundError.spec.ts.ejs +27 -0
  227. package/templates/mvc/ts/src/errors/NotFoundError.ts +9 -0
  228. package/templates/mvc/ts/src/graphql/context.spec.ts.ejs +30 -0
  229. package/templates/mvc/ts/src/graphql/context.ts.ejs +12 -0
  230. package/templates/mvc/ts/src/graphql/index.ts.ejs +3 -0
  231. package/templates/mvc/ts/src/graphql/resolvers/index.ts.ejs +4 -0
  232. package/templates/mvc/ts/src/graphql/resolvers/user.resolvers.spec.ts.ejs +68 -0
  233. package/templates/mvc/ts/src/graphql/resolvers/user.resolvers.ts.ejs +29 -0
  234. package/templates/mvc/ts/src/graphql/typeDefs/index.ts.ejs +4 -0
  235. package/templates/mvc/ts/src/graphql/typeDefs/user.types.ts.ejs +17 -0
  236. package/templates/mvc/ts/src/index.ts.ejs +157 -0
  237. package/templates/mvc/ts/src/routes/api.spec.ts.ejs +59 -0
  238. package/templates/mvc/ts/src/routes/api.ts.ejs +17 -0
  239. package/templates/mvc/ts/src/utils/errorMessages.ts +12 -0
  240. package/templates/mvc/ts/src/utils/errorMiddleware.ts.ejs +27 -0
  241. package/templates/mvc/ts/src/utils/httpCodes.ts +7 -0
  242. package/templates/mvc/ts/src/utils/logger.spec.ts.ejs +63 -0
  243. package/templates/mvc/ts/src/utils/logger.ts +36 -0
@@ -0,0 +1,42 @@
1
+ jest.mock('mongoose', () => ({
2
+ connect: jest.fn().mockResolvedValue(true),
3
+ }));
4
+
5
+ const logger = {
6
+ info: jest.fn(),
7
+ error: jest.fn(),
8
+ };
9
+
10
+ jest.mock('<% if (architecture === "MVC") { %>@/utils/logger<% } else { %>@/infrastructure/log/logger<% } %>', () => logger);
11
+
12
+ describe('Mongoose Configuration', () => {
13
+ beforeEach(() => {
14
+ jest.clearAllMocks();
15
+ jest.resetModules();
16
+ });
17
+
18
+ it('should call mongoose.connect with correct parameters', async () => {
19
+ const connectDB = require('<% if (architecture === "MVC") { %>@/config/database<% } else { %>@/infrastructure/database/database<% } %>').default;
20
+ const mongoose = require('mongoose');
21
+ await connectDB();
22
+ expect(mongoose.connect).toHaveBeenCalledWith(
23
+ expect.stringContaining('mongodb://')
24
+ );
25
+ });
26
+
27
+ it('should handle connection failure and retry', async () => {
28
+ const connectDB = require('<% if (architecture === "MVC") { %>@/config/database<% } else { %>@/infrastructure/database/database<% } %>').default;
29
+ const mongoose = require('mongoose');
30
+ (mongoose.connect as jest.Mock)
31
+ .mockRejectedValueOnce(new Error('Connection failed'))
32
+ .mockResolvedValueOnce(true);
33
+
34
+ const timeoutSpy = jest.spyOn(global, 'setTimeout').mockImplementation(cb => { (cb as any)(); return {} as any; });
35
+
36
+ await connectDB();
37
+
38
+ expect(logger.error).toHaveBeenCalled();
39
+ expect(mongoose.connect).toHaveBeenCalledTimes(2);
40
+ timeoutSpy.mockRestore();
41
+ });
42
+ });
@@ -0,0 +1,28 @@
1
+ import mongoose from 'mongoose';
2
+ <% if (architecture === 'MVC') { %>
3
+ import logger from '@/utils/logger';
4
+ <% } else { %>
5
+ import logger from '@/infrastructure/log/logger';
6
+ <% } %>
7
+ const connectDB = async (): Promise<void> => {
8
+ const dbHost = process.env.DB_HOST || 'localhost';
9
+ const dbPort = process.env.DB_PORT || '27017';
10
+ const dbName = process.env.DB_NAME || '<%= dbName %>';
11
+ const mongoURI = process.env.MONGO_URI || `mongodb://${dbHost}:${dbPort}/${dbName}`;
12
+
13
+ let retries = 5;
14
+ while (retries) {
15
+ try {
16
+ await mongoose.connect(mongoURI);
17
+ logger.info('MongoDB Connected...');
18
+ break;
19
+ } catch (err) {
20
+ logger.error('MongoDB connection failed:', err);
21
+ retries -= 1;
22
+ logger.info(`Retries left: ${retries}. Waiting 5s...`);
23
+ await new Promise(res => setTimeout(res, 5000));
24
+ }
25
+ }
26
+ };
27
+
28
+ export default connectDB;
@@ -0,0 +1,159 @@
1
+ services:
2
+ app:
3
+ build: .
4
+ ports:
5
+ - "${PORT:-3000}:3000"
6
+ <%_ if (database !== 'None' || communication === 'Kafka') { -%>
7
+ depends_on:
8
+ <%_ if (database !== 'None') { -%>
9
+ - db
10
+ <%_ } -%>
11
+ <%_ if (communication === 'Kafka') { -%>
12
+ - kafka
13
+ <%_ } -%>
14
+ <%_ } -%>
15
+ <%_ if (communication === 'Kafka') { -%>
16
+ environment:
17
+ - KAFKA_BROKER=kafka:9092
18
+ - KAFKAJS_NO_PARTITIONER_WARNING=1
19
+ - PORT=3000
20
+ <%_ if (caching === 'Redis') { -%>
21
+ - REDIS_HOST=redis
22
+ - REDIS_PORT=6379
23
+ - REDIS_PASSWORD=
24
+ <%_ } -%>
25
+ <%_ if (database !== 'None') { -%>
26
+ - DB_HOST=db
27
+ <%_ if (database === 'MySQL') { -%>
28
+ - DB_USER=root
29
+ - DB_PASSWORD=root
30
+ - DB_NAME=<%= dbName %>
31
+ - DB_PORT=3306
32
+ <%_ } -%><%_ if (database === 'PostgreSQL') { -%>
33
+ - DB_USER=postgres
34
+ - DB_PASSWORD=root
35
+ - DB_NAME=<%= dbName %>
36
+ - DB_PORT=5432
37
+ <%_ } -%><%_ if (database === 'MongoDB') { -%>
38
+ - DB_NAME=<%= dbName %>
39
+ - DB_PORT=27017
40
+ <%_ } -%>
41
+ <%_ } -%>
42
+ <%_ } else { -%>
43
+ environment:
44
+ - PORT=3000
45
+ <%_ if (caching === 'Redis') { -%>
46
+ - REDIS_HOST=redis
47
+ - REDIS_PORT=6379
48
+ - REDIS_PASSWORD=
49
+ <%_ } -%>
50
+ <%_ if (database !== 'None') { -%>
51
+ - DB_HOST=db
52
+ <%_ if (database === 'MySQL') { -%>
53
+ - DB_USER=root
54
+ - DB_PASSWORD=root
55
+ - DB_NAME=<%= dbName %>
56
+ - DB_PORT=3306
57
+ <%_ } -%><%_ if (database === 'PostgreSQL') { -%>
58
+ - DB_USER=postgres
59
+ - DB_PASSWORD=root
60
+ - DB_NAME=<%= dbName %>
61
+ - DB_PORT=5432
62
+ <%_ } -%><%_ if (database === 'MongoDB') { -%>
63
+ - DB_NAME=<%= dbName %>
64
+ - DB_PORT=27017
65
+ <%_ } -%>
66
+ <%_ } -%>
67
+ <%_ } -%>
68
+ <%_ if (database !== 'None') { -%>
69
+ db:
70
+ <%_ if (database === 'MySQL') { -%>
71
+ image: mysql:8.0
72
+ restart: always
73
+ environment:
74
+ MYSQL_ROOT_PASSWORD: root
75
+ MYSQL_DATABASE: <%= dbName %>
76
+ ports:
77
+ - "${DB_PORT:-3306}:3306"
78
+ volumes:
79
+ - ./flyway/sql:/docker-entrypoint-initdb.d
80
+ <%_ } else if (database === 'PostgreSQL') { -%>
81
+ image: postgres:15
82
+ restart: always
83
+ environment:
84
+ POSTGRES_USER: postgres
85
+ POSTGRES_PASSWORD: root
86
+ POSTGRES_DB: <%= dbName %>
87
+ ports:
88
+ - "${DB_PORT:-5432}:5432"
89
+ volumes:
90
+ - ./flyway/sql:/docker-entrypoint-initdb.d
91
+ <%_ } else if (database === 'MongoDB') { -%>
92
+ image: mongo:latest
93
+ restart: always
94
+ environment:
95
+ MONGO_INITDB_DATABASE: <%= dbName %>
96
+ ports:
97
+ - "${DB_PORT:-27017}:27017"
98
+ volumes:
99
+ - mongodb_data:/data/db
100
+
101
+ mongo-migrate:
102
+ image: node:22-slim
103
+ working_dir: /app
104
+ volumes:
105
+ - .:/app
106
+ command: sh -c "npm install migrate-mongo && npm run migrate"
107
+ environment:
108
+ - DB_HOST=db
109
+ - DB_NAME=<%= dbName %>
110
+ depends_on:
111
+ - db
112
+ <%_ } -%>
113
+ <%_ } -%>
114
+ <%_ if (database !== 'MongoDB' && database !== 'None') { -%>
115
+ flyway:
116
+ image: flyway/flyway
117
+ command: -connectRetries=60 migrate
118
+ volumes:
119
+ - ./flyway/sql:/flyway/sql
120
+ environment:
121
+ <%_ if (database === 'MySQL') { -%>
122
+ FLYWAY_URL: jdbc:mysql://db:3306/<%= dbName %>
123
+ FLYWAY_USER: root
124
+ FLYWAY_PASSWORD: root
125
+ <%_ } -%><%_ if (database === 'PostgreSQL') { -%>
126
+ FLYWAY_URL: jdbc:postgresql://db:5432/<%= dbName %>
127
+ FLYWAY_USER: postgres
128
+ FLYWAY_PASSWORD: root
129
+ <%_ } -%>
130
+ depends_on:
131
+ - db
132
+ <%_ } -%>
133
+ <%_ if (communication === 'Kafka') { -%>
134
+ kafka:
135
+ image: bitnamilegacy/kafka:3.4.1-debian-12-r39
136
+ ports:
137
+ - "${KAFKA_EXTERNAL_PORT:-9093}:9093"
138
+ environment:
139
+ - KAFKA_ENABLE_KRAFT=yes
140
+ - KAFKA_CFG_PROCESS_ROLES=broker,controller
141
+ - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@localhost:9094
142
+ - KAFKA_CFG_NODE_ID=1
143
+ - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:${KAFKA_PORT:-9093}
144
+ - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,PLAINTEXT_HOST://:9093,CONTROLLER://:9094
145
+ - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
146
+ - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
147
+ - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=PLAINTEXT
148
+ <%_ } -%>
149
+ <%_ if (caching === 'Redis') { -%>
150
+ redis:
151
+ image: redis:alpine
152
+ restart: always
153
+ ports:
154
+ - "${REDIS_PORT:-6379}:6379"
155
+ <%_ } -%>
156
+ <%_ if (database !== 'None') { -%>
157
+ volumes:
158
+ <%= database.toLowerCase() %>_data:
159
+ <%_ } -%>
@@ -0,0 +1,40 @@
1
+ module.exports = {
2
+ apps: [{
3
+ name: "<%= projectName %>",
4
+ script: "<% if (language === 'TypeScript') { %>./dist/index.js<% } else { %>./src/index.js<% } %>", // Entry point
5
+ instances: "max", // Run in Cluster Mode to utilize all CPUs (Note: On Windows, cluster mode may throw `spawn wmic ENOENT` errors due to missing WMIC in Windows 11. To fix, change instances to 1, or install wmic)
6
+ exec_mode: "cluster",
7
+ watch: false, // Disable watch in production
8
+ max_memory_restart: "1G",
9
+ env_production: {
10
+ NODE_ENV: "production",
11
+ PORT: 3000,
12
+ <%_ if (caching === 'Redis') { -%>
13
+ REDIS_HOST: "127.0.0.1",
14
+ REDIS_PORT: 6379,
15
+ REDIS_PASSWORD: "",
16
+ <%_ } -%>
17
+ <%_ if (communication === 'Kafka') { -%>
18
+ KAFKA_BROKER: "127.0.0.1:9093",
19
+ KAFKAJS_NO_PARTITIONER_WARNING: 1,
20
+ <%_ } -%>
21
+ <%_ if (database !== 'None') { -%>
22
+ DB_HOST: "127.0.0.1",
23
+ <%_ if (database === 'MySQL') { -%>
24
+ DB_USER: "root",
25
+ DB_PASSWORD: "root",
26
+ DB_NAME: "<%= dbName %>",
27
+ DB_PORT: 3306
28
+ <%_ } else if (database === 'PostgreSQL') { -%>
29
+ DB_USER: "postgres",
30
+ DB_PASSWORD: "root",
31
+ DB_NAME: "<%= dbName %>",
32
+ DB_PORT: 5432
33
+ <%_ } else if (database === 'MongoDB') { -%>
34
+ DB_NAME: "<%= dbName %>",
35
+ DB_PORT: 27017
36
+ <%_ } -%>
37
+ <%_ } -%>
38
+ }
39
+ }]
40
+ };
@@ -0,0 +1,77 @@
1
+ import eslint from '@eslint/js';
2
+ import eslintConfigPrettier from 'eslint-config-prettier';
3
+ import globals from 'globals';
4
+ import importPlugin from 'eslint-plugin-import-x';
5
+ <% if (language === 'TypeScript') { %>import tseslint from 'typescript-eslint';
6
+
7
+ export default tseslint.config(
8
+ eslint.configs.recommended,
9
+ ...tseslint.configs.recommended,
10
+ eslintConfigPrettier,
11
+ {
12
+ plugins: {
13
+ import: importPlugin,
14
+ },
15
+ settings: {
16
+ 'import-x/resolver': {
17
+ typescript: true,
18
+ node: true,
19
+ },
20
+ },
21
+ languageOptions: {
22
+ globals: {
23
+ ...globals.node,
24
+ ...globals.jest,
25
+ },
26
+ },
27
+ rules: {
28
+ "no-console": "warn",
29
+ "no-unused-vars": "off",
30
+ "@typescript-eslint/no-unused-vars": ["warn", {
31
+ "argsIgnorePattern": "^_",
32
+ "varsIgnorePattern": "^_"
33
+ }],
34
+ "@typescript-eslint/no-require-imports": "error",
35
+ "import/no-unresolved": [2, { "caseSensitive": false }]
36
+ },
37
+ },
38
+ {
39
+ files: ["**/*.test.ts", "**/*.spec.ts", "tests/**/*.ts"],
40
+ rules: {
41
+ "@typescript-eslint/no-require-imports": "off",
42
+ "@typescript-eslint/no-unused-vars": ["warn", {
43
+ "argsIgnorePattern": "^_",
44
+ "varsIgnorePattern": "^_"
45
+ }],
46
+ "@typescript-eslint/no-explicit-any": "off",
47
+ "import/no-unresolved": [2, { "caseSensitive": false }]
48
+ },
49
+ }
50
+ );<% } else { %>
51
+ export default [
52
+ eslint.configs.recommended,
53
+ eslintConfigPrettier,
54
+ {
55
+ plugins: {
56
+ import: importPlugin,
57
+ },
58
+ settings: {
59
+ 'import-x/resolver': {
60
+ node: true,
61
+ },
62
+ },
63
+ languageOptions: {
64
+ ecmaVersion: 'latest',
65
+ sourceType: 'module',
66
+ globals: {
67
+ ...globals.node,
68
+ ...globals.jest,
69
+ },
70
+ },
71
+ rules: {
72
+ "no-console": "warn",
73
+ "no-unused-vars": "warn",
74
+ "import/no-unresolved": [2, { "caseSensitive": false }]
75
+ }
76
+ }
77
+ ];<% } %>
@@ -0,0 +1,50 @@
1
+ const express = require('express');
2
+ const router = express.Router();
3
+ const logger = require('<% if (architecture === "MVC") { %>../utils/logger<% } else { %>../../infrastructure/log/logger<% } %>');
4
+ const HTTP_STATUS = require('<% if (architecture === "MVC") { %>../utils/httpCodes<% } else { %>../../utils/httpCodes<% } %>');
5
+ <%_ if (database !== 'None') { -%>
6
+ const ERROR_MESSAGES = require('<% if (architecture === "MVC") { %>../utils/errorMessages<% } else { %>../../utils/errorMessages<% } %>');
7
+ <%_ } -%>
8
+ <%_ if (database === 'MongoDB') { -%>
9
+ const mongoose = require('mongoose');
10
+ <%_ } else if (database !== 'None') { -%>
11
+ const sequelize = require('<% if (architecture === "MVC") { %>../config/database<% } else { %>../../infrastructure/database/database<% } %>');
12
+ <%_ } -%>
13
+
14
+ router.get('/', async (req, res) => {
15
+ const healthData = {
16
+ status: 'UP',
17
+ uptime: process.uptime(),
18
+ memory: process.memoryUsage(),
19
+ database: 'disconnected',
20
+ timestamp: Date.now()
21
+ };
22
+ logger.info('Health Check');
23
+
24
+ <%_ if (database !== 'None') { -%>
25
+ try {
26
+ <%_ if (database === 'MongoDB') { -%>
27
+ if (mongoose.connection.readyState === 1) {
28
+ if (mongoose.connection.db && mongoose.connection.db.admin) {
29
+ await mongoose.connection.db.admin().ping();
30
+ }
31
+ healthData.database = 'connected';
32
+ }
33
+ <%_ } else { -%>
34
+ await sequelize.authenticate();
35
+ healthData.database = 'connected';
36
+ <%_ } -%>
37
+ } catch (err) {
38
+ healthData.database = 'error';
39
+ healthData.status = 'DOWN';
40
+ logger.error(`${ERROR_MESSAGES.DATABASE_PING_FAILED}:`, err);
41
+ return res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json(healthData);
42
+ }
43
+ <%_ } else { -%>
44
+ healthData.database = 'None';
45
+ <%_ } -%>
46
+
47
+ res.status(HTTP_STATUS.OK).json(healthData);
48
+ });
49
+
50
+ module.exports = router;
@@ -0,0 +1,70 @@
1
+ const request = require('supertest');
2
+ const express = require('express');
3
+ <% if (architecture === 'MVC') { -%>
4
+ const healthRoute = require('@/routes/healthRoute');
5
+ <% } else { -%>
6
+ const healthRoute = require('@/interfaces/routes/healthRoute');
7
+ <% } -%>
8
+ const HTTP_STATUS = require('@/utils/httpCodes');
9
+
10
+ <%_ if (database === 'MongoDB') { -%>
11
+ jest.mock('mongoose', () => {
12
+ return {
13
+ connection: {
14
+ readyState: 1,
15
+ db: {
16
+ admin: jest.fn().mockReturnValue({
17
+ ping: jest.fn().mockResolvedValue(true)
18
+ })
19
+ }
20
+ }
21
+ };
22
+ });
23
+ <%_ } else if (database !== 'None') { -%>
24
+ jest.mock('<% if (architecture === "MVC") { %>@/config/database<% } else { %>@/infrastructure/database/database<% } %>', () => {
25
+ return {
26
+ authenticate: jest.fn()
27
+ };
28
+ });
29
+ <%_ } -%>
30
+
31
+ describe('Health Route', () => {
32
+ let app;
33
+
34
+ beforeEach(() => {
35
+ app = express();
36
+ app.use('/health', healthRoute);
37
+ jest.clearAllMocks();
38
+ });
39
+
40
+ it('should return 200 OK with UP status', async () => {
41
+ const res = await request(app).get('/health');
42
+ expect(res.status).toBe(HTTP_STATUS.OK);
43
+ expect(res.body.status).toBe('UP');
44
+ expect(res.body.database).toBe('<% if (database === "None") { %>None<% } else { %>connected<% } %>');
45
+ });
46
+
47
+ <%_ if (database === 'MongoDB') { -%>
48
+ it('should handle database ping failure and return 500', async () => {
49
+ const mongoose = require('mongoose');
50
+ mongoose.connection.db.admin.mockReturnValueOnce({
51
+ ping: jest.fn().mockRejectedValueOnce(new Error('DB Error'))
52
+ });
53
+
54
+ const res = await request(app).get('/health');
55
+ expect(res.status).toBe(HTTP_STATUS.INTERNAL_SERVER_ERROR);
56
+ expect(res.body.status).toBe('DOWN');
57
+ expect(res.body.database).toBe('error');
58
+ });
59
+ <%_ } else if (database !== 'None') { -%>
60
+ it('should handle database authentication failure and return 500', async () => {
61
+ const sequelize = require('<% if (architecture === "MVC") { %>@/config/database<% } else { %>@/infrastructure/database/database<% } %>');
62
+ sequelize.authenticate.mockRejectedValueOnce(new Error('DB Error'));
63
+
64
+ const res = await request(app).get('/health');
65
+ expect(res.status).toBe(HTTP_STATUS.INTERNAL_SERVER_ERROR);
66
+ expect(res.body.status).toBe('DOWN');
67
+ expect(res.body.database).toBe('error');
68
+ });
69
+ <%_ } -%>
70
+ });
@@ -0,0 +1,76 @@
1
+ import request from 'supertest';
2
+ import express from 'express';
3
+ <% if (architecture === 'MVC') { -%>
4
+ import healthRoute from '@/routes/healthRoute';
5
+ <% } else { -%>
6
+ import healthRoute from '@/interfaces/routes/healthRoute';
7
+ <% } -%>
8
+ import { HTTP_STATUS } from '@/utils/httpCodes';
9
+ <%_ if (database === 'MongoDB') { -%>
10
+ import mongoose from 'mongoose';
11
+ <%_ } else if (database !== 'None') { -%>
12
+ import sequelize from '<% if (architecture === "MVC") { %>@/config/database<% } else { %>@/infrastructure/database/database<% } %>';
13
+ <%_ } -%>
14
+
15
+ <%_ if (database === 'MongoDB') { -%>
16
+ jest.mock('mongoose', () => {
17
+ return {
18
+ connection: {
19
+ readyState: 1,
20
+ db: {
21
+ admin: jest.fn().mockReturnValue({
22
+ ping: jest.fn().mockResolvedValue(true)
23
+ })
24
+ }
25
+ }
26
+ };
27
+ });
28
+ <%_ } else if (database !== 'None') { -%>
29
+ jest.mock('<% if (architecture === "MVC") { %>@/config/database<% } else { %>@/infrastructure/database/database<% } %>', () => {
30
+ return {
31
+ __esModule: true,
32
+ default: {
33
+ authenticate: jest.fn()
34
+ }
35
+ };
36
+ });
37
+ <%_ } -%>
38
+
39
+ describe('Health Route', () => {
40
+ let app: express.Express;
41
+
42
+ beforeEach(() => {
43
+ app = express();
44
+ app.use('/health', healthRoute);
45
+ jest.clearAllMocks();
46
+ });
47
+
48
+ it('should return 200 OK with UP status', async () => {
49
+ const res = await request(app).get('/health');
50
+ expect(res.status).toBe(HTTP_STATUS.OK);
51
+ expect(res.body.status).toBe('UP');
52
+ expect(res.body.database).toBe('<% if (database === "None") { %>None<% } else { %>connected<% } %>');
53
+ });
54
+
55
+ <%_ if (database === 'MongoDB') { -%>
56
+ it('should handle database ping failure and return 500', async () => {
57
+ ((mongoose.connection.db as any).admin as jest.Mock).mockReturnValueOnce({
58
+ ping: jest.fn().mockRejectedValueOnce(new Error('DB Error'))
59
+ });
60
+
61
+ const res = await request(app).get('/health');
62
+ expect(res.status).toBe(HTTP_STATUS.INTERNAL_SERVER_ERROR);
63
+ expect(res.body.status).toBe('DOWN');
64
+ expect(res.body.database).toBe('error');
65
+ });
66
+ <%_ } else if (database !== 'None') { -%>
67
+ it('should handle database authentication failure and return 500', async () => {
68
+ (sequelize.authenticate as jest.Mock).mockRejectedValueOnce(new Error('DB Error'));
69
+
70
+ const res = await request(app).get('/health');
71
+ expect(res.status).toBe(HTTP_STATUS.INTERNAL_SERVER_ERROR);
72
+ expect(res.body.status).toBe('DOWN');
73
+ expect(res.body.database).toBe('error');
74
+ });
75
+ <%_ } -%>
76
+ });
@@ -0,0 +1,49 @@
1
+ import { Router, Request, Response } from 'express';
2
+ import logger from '<% if (architecture === "MVC") { %>@/utils/logger<% } else { %>@/infrastructure/log/logger<% } %>';
3
+ import { HTTP_STATUS } from '@/utils/httpCodes';
4
+ <%_ if (database !== 'None') { -%>
5
+ import { ERROR_MESSAGES } from '@/utils/errorMessages';
6
+ <%_ } -%>
7
+ <%_ if (database === 'MongoDB') { -%>
8
+ import mongoose from 'mongoose';
9
+ <%_ } else if (database !== 'None') { -%>
10
+ import sequelize from '<% if (architecture === "MVC") { %>@/config/database<% } else { %>@/infrastructure/database/database<% } %>';
11
+ <%_ } -%>
12
+
13
+ const router = Router();
14
+
15
+ router.get('/', async (req: Request, res: Response) => {
16
+ const healthData: Record<string, unknown> = {
17
+ status: 'UP',
18
+ uptime: process.uptime(),
19
+ memory: process.memoryUsage(),
20
+ database: 'disconnected',
21
+ timestamp: Date.now()
22
+ };
23
+ logger.info('Health Check');
24
+
25
+ <%_ if (database !== 'None') { -%>
26
+ try {
27
+ <%_ if (database === 'MongoDB') { -%>
28
+ if (mongoose.connection.readyState === 1) {
29
+ await mongoose.connection.db?.admin().ping();
30
+ healthData.database = 'connected';
31
+ }
32
+ <%_ } else { -%>
33
+ await sequelize.authenticate();
34
+ healthData.database = 'connected';
35
+ <%_ } -%>
36
+ } catch (err) {
37
+ healthData.database = 'error';
38
+ healthData.status = 'DOWN';
39
+ logger.error(`${ERROR_MESSAGES.DATABASE_PING_FAILED}:`, err);
40
+ return res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json(healthData);
41
+ }
42
+ <%_ } else { -%>
43
+ healthData.database = 'None';
44
+ <%_ } -%>
45
+
46
+ res.status(HTTP_STATUS.OK).json(healthData);
47
+ });
48
+
49
+ export default router;
@@ -0,0 +1,32 @@
1
+ module.exports = {
2
+ testEnvironment: 'node',
3
+ coverageDirectory: 'coverage',
4
+ collectCoverageFrom: ['src/**/*.{js,ts}'],
5
+ testMatch: ['**/*.test.ts', '**/*.test.js', '**/*.spec.ts', '**/*.spec.js'],
6
+ testPathIgnorePatterns: ['/node_modules/', '/tests/e2e/'],
7
+ <% if (language === 'TypeScript') { %>preset: 'ts-jest',<% } %>
8
+ moduleNameMapper: {
9
+ '^@/(.*)$': '<rootDir>/src/$1',
10
+ },
11
+ coveragePathIgnorePatterns: [
12
+ "/node_modules/",
13
+ "/dist/",
14
+ "src/index",
15
+ "src/app",
16
+ "src/config/env",
17
+ "src/infrastructure/config/env",
18
+ "src/config/swagger",
19
+ "src/infrastructure/webserver/swagger",
20
+ "src/infrastructure/webserver/server",
21
+ "src/utils/logger",
22
+ "src/infrastructure/log/logger"
23
+ ],
24
+ coverageThreshold: {
25
+ global: {
26
+ branches: 70,
27
+ functions: 80,
28
+ lines: 80,
29
+ statements: 80
30
+ }
31
+ }
32
+ };
@@ -0,0 +1,8 @@
1
+ <%_ if (language === 'TypeScript') { -%>/* eslint-disable @typescript-eslint/no-require-imports */<%_ } -%>
2
+ module.exports = {
3
+ ...require('./jest.config'),
4
+ testMatch: ['<rootDir>/tests/e2e/**/*.test.ts', '<rootDir>/tests/e2e/**/*.test.js'],
5
+ testPathIgnorePatterns: ['/node_modules/'],
6
+ testTimeout: 30000,
7
+ clearMocks: true
8
+ };
@@ -0,0 +1,9 @@
1
+ const { Kafka } = require('kafkajs');
2
+ const { env } = require('./env');
3
+
4
+ const kafka = new Kafka({
5
+ clientId: 'nodejs-service',
6
+ brokers: [env.KAFKA_BROKER]
7
+ });
8
+
9
+ module.exports = { kafka };
@@ -0,0 +1,27 @@
1
+ const { Kafka } = require('kafkajs');
2
+
3
+ jest.mock('kafkajs', () => {
4
+ return {
5
+ Kafka: jest.fn().mockImplementation(() => ({
6
+ producer: jest.fn(),
7
+ consumer: jest.fn(),
8
+ })),
9
+ };
10
+ });
11
+
12
+ jest.mock('<% if (architecture === "MVC") { %>@/config/env<% } else { %>@/infrastructure/config/env<% } %>', () => ({
13
+ env: {
14
+ KAFKA_BROKER: 'localhost:9092'
15
+ }
16
+ }));
17
+
18
+ describe('Kafka Configuration', () => {
19
+ beforeEach(() => {
20
+ jest.clearAllMocks();
21
+ });
22
+
23
+ it('should initialize Kafka', () => {
24
+ require('<% if (architecture === "MVC") { %>@/config/kafka<% } else { %>@/infrastructure/config/kafka<% } %>');
25
+ expect(Kafka).toHaveBeenCalled();
26
+ });
27
+ });