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
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # nodejs-structure-cli
2
+
3
+ [![npm version](https://img.shields.io/npm/v/nodejs-structure-cli.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-structure-cli)
4
+ [![npm total downloads](https://img.shields.io/npm/dt/nodejs-structure-cli?style=flat-square&color=emerald&label=Downloads)](https://www.npmjs.com/package/nodejs-structure-cli)
5
+ [![npm monthly downloads](https://img.shields.io/npm/dm/nodejs-structure-cli.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-structure-cli)
6
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg?style=flat-square)](https://opensource.org/licenses/ISC)
7
+
8
+ A powerful CLI tool to scaffold production-ready Node.js microservices with built-in best practices. Choose between **MVC** or **Clean Architecture**, **JavaScript** or **TypeScript**, and your preferred tech stack in seconds.
9
+
10
+ ---
11
+
12
+ ---
13
+
14
+ ## 🚀 Quick Start
15
+
16
+ Generate your professional Node.js project in seconds without installing anything globally:
17
+
18
+ ```bash
19
+ npx nodejs-structure-cli@latest init
20
+ ```
21
+
22
+ ### Installation (Optional)
23
+
24
+ If you prefer to install it globally:
25
+
26
+ ```bash
27
+ npm install -g nodejs-structure-cli
28
+ # Then run:
29
+ nodejs-structure-cli init
30
+ ```
31
+
32
+ ---
package/bin/index.js ADDED
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from "commander";
4
+ import chalk from "chalk";
5
+ import { getProjectDetails } from "../lib/prompts.js";
6
+ import { generateProject } from "../lib/generator.js";
7
+ import { readFileSync } from "fs";
8
+ import { join, dirname } from "path";
9
+ import { fileURLToPath } from "url";
10
+
11
+ const __dirname = dirname(fileURLToPath(import.meta.url));
12
+ const pkg = JSON.parse(
13
+ readFileSync(join(__dirname, "../package.json"), "utf-8"),
14
+ );
15
+
16
+ const program = new Command();
17
+
18
+ program
19
+ .name("nodejs-structure-cli")
20
+ .description(
21
+ "🚀 CLI to scaffold production-ready Node.js microservices.\n\nGenerates projects with:\n- MVC or Clean Architecture\n- REST or Kafka\n- MySQL, PostgreSQL, or MongoDB\n- Docker, Flyway & Mongoose support",
22
+ )
23
+ .version(pkg.version, "-v, --version", "Output the current version")
24
+ .addHelpText(
25
+ "after",
26
+ `\n${chalk.yellow("Example:")}\n $ nodejs-structure-cli init ${chalk.gray("# Start the interactive setup")}\n`,
27
+ );
28
+
29
+ program
30
+ .command("init")
31
+ .description("Initialize a new Node.js project")
32
+ .option("-n, --project-name <name>", "Project name")
33
+ .option("-l, --language <language>", "Language (JavaScript, TypeScript)")
34
+ .option(
35
+ "-a, --architecture <architecture>",
36
+ "Architecture (MVC, Clean Architecture)",
37
+ )
38
+ .option("--view-engine <view>", "View Engine (None, EJS, Pug) - MVC only")
39
+ .option("-d, --database <database>", "Database (MySQL, PostgreSQL)")
40
+ .option("--db-name <name>", "Database name")
41
+ .option(
42
+ "-c, --communication <communication>",
43
+ "Communication (REST APIs, GraphQL, Kafka)",
44
+ )
45
+ .option(
46
+ "--ci-provider <provider>",
47
+ "CI/CD Provider (None, GitHub Actions, Jenkins, GitLab CI)",
48
+ )
49
+ .option("--include-security", "Include Enterprise Security Hardening")
50
+ .option("--no-include-security", "Exclude Enterprise Security Hardening")
51
+ .option("--caching <type>", "Caching Layer (None/Redis)")
52
+ .action(async (options) => {
53
+ // Fix for Commander camelCase conversion
54
+ if (options.ciProvider) {
55
+ options.ciProvider = options.ciProvider;
56
+ }
57
+
58
+ console.log(chalk.blue("Welcome to the Node.js Quickstart Generator!"));
59
+
60
+ try {
61
+ const answers = await getProjectDetails(options);
62
+ console.log(
63
+ chalk.blue(
64
+ `\n🚀 Preparing to generate ${chalk.bold(answers.projectName)} (${answers.architecture})...`,
65
+ ),
66
+ );
67
+
68
+ console.log(chalk.yellow("\nGenerating project files..."));
69
+ await generateProject(answers);
70
+
71
+ console.log(chalk.green("\n✔ Project generated successfully!"));
72
+
73
+ console.log(chalk.magenta("\n🚀 Project is AI-Ready!"));
74
+ console.log(chalk.magenta("-----------------------------------------"));
75
+ console.log(chalk.magenta("🤖 We detected you are using AI tools."));
76
+ console.log(
77
+ chalk.magenta(
78
+ `📍 Use Cursor? We've configured '.cursorrules' for you.`,
79
+ ),
80
+ );
81
+ console.log(
82
+ chalk.magenta(
83
+ `📍 Use ChatGPT/Gemini? Check the 'prompts/' folder for Agent Skills.`,
84
+ ),
85
+ );
86
+ console.log(chalk.magenta("-----------------------------------------"));
87
+
88
+ let manualStartInstructions = `\n${chalk.yellow("Development:")}\n cd ${answers.projectName}\n npm install`;
89
+
90
+ const needsInfrastructure =
91
+ answers.database !== "None" ||
92
+ answers.caching === "Redis" ||
93
+ answers.communication === "Kafka";
94
+
95
+ if (needsInfrastructure) {
96
+ let servicesToStart = "";
97
+ if (answers.database === "MongoDB") servicesToStart += " db";
98
+ else if (answers.database !== "None") servicesToStart += " db flyway";
99
+ if (answers.caching === "Redis") servicesToStart += " redis";
100
+ if (answers.communication === "Kafka") servicesToStart += " kafka";
101
+
102
+ manualStartInstructions += `\n docker-compose up -d${servicesToStart} # Start infrastructure first\n npm run dev`;
103
+ } else {
104
+ manualStartInstructions += `\n npm run dev`;
105
+ }
106
+
107
+ console.log(
108
+ chalk.cyan(
109
+ `\nNext steps:\n cd ${answers.projectName}\n npm install\n docker-compose up\n-----------------------${manualStartInstructions}\n\n${chalk.yellow("Production (PM2):")}\n npm run build\n npm run deploy\n npx pm2 logs`,
110
+ ),
111
+ );
112
+
113
+ console.log(chalk.magenta("\n" + "★".repeat(50)));
114
+ console.log(
115
+ chalk.white.bold(" Enjoying the Node.js Quickstart Generator?"),
116
+ );
117
+ console.log(
118
+ chalk.white(` If this tool saved you 4+ hours of architecture setup,`),
119
+ );
120
+ console.log(
121
+ chalk.white(` please help us grow by giving us a ⭐ on GitHub!`),
122
+ );
123
+ console.log(
124
+ chalk.white(
125
+ `\n 👉 ${chalk.underline.bold("https://github.com/Jaysoni2709")}`,
126
+ ),
127
+ );
128
+ console.log(chalk.magenta("★".repeat(50) + "\n"));
129
+ } catch (error) {
130
+ if (error.name === "ExitPromptError") {
131
+ console.log(chalk.yellow("\n\n👋 Goodbye! Setup cancelled."));
132
+ process.exit(0);
133
+ }
134
+ console.error(chalk.red("Error generating project:"), error);
135
+ process.exit(1);
136
+ }
137
+ });
138
+
139
+ program.parse(process.argv);
140
+
141
+ if (!process.argv.slice(2).length) {
142
+ program.outputHelp();
143
+ }
@@ -0,0 +1,145 @@
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import { setupProjectDirectory, copyBaseStructure, copyCommonFiles } from './modules/project-setup.js';
4
+ import { renderPackageJson, renderDockerCompose, renderReadme, renderDockerfile, renderProfessionalConfig, setupCiCd, renderTestSample, renderEnvExample, renderPm2Config, renderAiNativeFiles } from './modules/config-files.js';
5
+ import { renderIndexFile, renderEnvConfig, renderErrorMiddleware, renderDynamicComponents, renderSwaggerConfig, setupViews as setupSrcViews, processAllTests, renderAuthAndUploadComponents } from './modules/app-setup.js';
6
+ import { setupDatabase } from './modules/database-setup.js';
7
+ import { setupKafka, setupViews } from './modules/kafka-setup.js';
8
+ import { setupCaching } from './modules/caching-setup.js';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+
13
+ export const generateProject = async (config) => {
14
+ // 0. Normalize configuration with defaults
15
+ config = {
16
+ viewEngine: 'None',
17
+ caching: 'None',
18
+ dbName: 'demo',
19
+ ciProvider: 'GitHub Actions',
20
+ communication: 'REST APIs',
21
+ database: 'None',
22
+ includeSecurity: false,
23
+ auth: 'None',
24
+ googleLogin: 'None',
25
+ includeMulter: false,
26
+ ...config
27
+ };
28
+
29
+ const { projectName, architecture, language } = config;
30
+ const targetDir = path.resolve(process.cwd(), projectName);
31
+ const templatesDir = path.join(__dirname, '../templates');
32
+
33
+ // 1. Create project directory
34
+ await setupProjectDirectory(targetDir, projectName);
35
+
36
+ // 2. Select & Copy Base Structure
37
+ const { templatePath } = await copyBaseStructure(templatesDir, targetDir, architecture, language);
38
+
39
+ // 3. Render package.json
40
+ await renderPackageJson(templatesDir, targetDir, config);
41
+
42
+ // 4. Render docker-compose.yml
43
+ await renderDockerCompose(templatesDir, targetDir, config);
44
+
45
+ // 5. Render README.md
46
+ await renderReadme(templatesDir, targetDir, config);
47
+
48
+ // 6. Render index file (ts/js)
49
+ await renderIndexFile(templatePath, targetDir, config);
50
+
51
+ // 6a. Render Environment Configuration
52
+ await renderEnvConfig(templatePath, targetDir, config);
53
+
54
+ // 6a. Render error middleware
55
+ await renderErrorMiddleware(templatePath, targetDir, config);
56
+
57
+ // 7. Render Dynamic Components (Controllers/Repos/Server)
58
+ await renderDynamicComponents(templatePath, targetDir, config);
59
+
60
+ // 8. Kafka Setup
61
+ await setupKafka(templatesDir, targetDir, config);
62
+
63
+ // 9. Common Files (.gitignore, Dockerfile, tsconfig)
64
+ await copyCommonFiles(templatesDir, targetDir, language);
65
+ await renderDockerfile(templatesDir, targetDir, config);
66
+
67
+ // 10. Database Setup (Migrations, Config, Models)
68
+ // Note: logic for detailed view copying is also handled nicely if we ensure setupDatabase checks correctly,
69
+ // or we can move strict view logic to setupViews.
70
+ // In strict refactor, database-setup handles the content that was in the DB block.
71
+ await setupDatabase(templatesDir, targetDir, config);
72
+
73
+ // 10a. Caching Setup
74
+ await setupCaching(templatesDir, targetDir, config);
75
+
76
+ // 11. View Engine Public Assets (MVC)
77
+ await setupViews(templatesDir, targetDir, config);
78
+ // Copy src/views (MVC)
79
+ await setupSrcViews(templatesDir, targetDir, config);
80
+
81
+ // 12. Swagger Config
82
+ await renderSwaggerConfig(templatesDir, targetDir, config);
83
+
84
+ // 13. Professional Config & Tests
85
+ await renderProfessionalConfig(templatesDir, targetDir, config);
86
+ await renderTestSample(templatesDir, targetDir, config);
87
+
88
+ // 13.5 AI-Native Scaffolding
89
+ await renderAiNativeFiles(templatesDir, targetDir, config);
90
+
91
+ // 13.6 Auth & Upload Components
92
+ await renderAuthAndUploadComponents(templatesDir, targetDir, config);
93
+
94
+ // 14. CI/CD
95
+ await setupCiCd(templatesDir, targetDir, config);
96
+
97
+ // 15. Env Example
98
+ await renderEnvExample(templatesDir, targetDir, config);
99
+
100
+ // 16. PM2 Configuration
101
+ await renderPm2Config(templatesDir, targetDir, config);
102
+
103
+ // 17. Process All Tests
104
+ await processAllTests(targetDir, config);
105
+
106
+ console.log(`
107
+ ====================================================
108
+ Node.js Project Created Successfully!
109
+ ====================================================
110
+
111
+ Project: ${projectName}
112
+ Architecture: ${architecture}
113
+ Language: ${language}
114
+ Database: ${config.database}
115
+ Communication: ${config.communication}${config.caching && config.caching === 'Redis' ? `\n Caching: ${config.caching}` : ''}${config.auth && config.auth !== 'None' ? `\n Authentication: ${config.auth}` : ''}${config.googleLogin && config.googleLogin !== 'None' ? `\n Social Login: ${config.googleLogin}` : ''}${config.includeMulter ? `\n Image Upload: Multer` : ''}
116
+
117
+ ----------------------------------------------------
118
+ ✨ High-Quality Standards Applied:
119
+ ----------------------------------------------------
120
+ ✅ Linting & Formatting: Eslint + Prettier configured
121
+ ✅ Git Hooks: Husky + Lint-Staged ready
122
+ ✅ Security: Helmet, CORS, Rate-Limiting added${config.includeSecurity ? '\n ✅ Enterprise Security: Snyk (SCA) & SonarCloud (SAST) integration' : ''}
123
+ ✅ Testing: Jest setup for Unit/Integration tests
124
+ ✅ Docker: Production-ready multi-stage build
125
+ ${config.ciProvider !== 'None' ? `✅ CI/CD: ${config.ciProvider} Workflow ready` : '❌ CI/CD: Skipped (User preferred)'}
126
+
127
+ ----------------------------------------------------
128
+ 🚀 Project is AI-Ready!
129
+ ----------------------------------------------------
130
+ 🤖 We detected you are using AI tools.
131
+ 📍 Use Cursor? We've configured '.cursorrules' for you.
132
+ 📍 Use ChatGPT/Gemini? Check the 'prompts/' folder for Agent Skills.
133
+
134
+ ----------------------------------------------------
135
+ 👉 Next Steps:
136
+ ----------------------------------------------------
137
+ 1. cd ${projectName}
138
+ 2. git init
139
+ 3. npm install
140
+ 4. npm run prepare (To setup Husky hooks)
141
+ 5. docker-compose up -d${config.database !== 'None' ? ' db' : ''}${config.caching === 'Redis' ? ' redis' : ''}${config.communication === 'Kafka' ? ' kafka' : ''} (To start DB/Infrastructure)
142
+ 6. npm run dev (To start development server)
143
+ 7. npm test (To run tests)
144
+ `);
145
+ };