@ifecodes/backend-template 1.1.7 → 1.1.9

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 (37) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +22 -4
  3. package/bin/cli.js +162 -42
  4. package/bin/lib/readme-generator.js +118 -124
  5. package/bin/lib/service-setup.js +23 -18
  6. package/package.json +1 -1
  7. package/template/base/js/.env.example +5 -5
  8. package/template/base/js/.husky/pre-commit +1 -7
  9. package/template/base/js/src/app.js +3 -0
  10. package/template/base/js/src/config/db.js +8 -8
  11. package/template/base/js/src/config/env.js +14 -14
  12. package/template/base/js/src/config/index.js +7 -7
  13. package/template/base/js/src/middlewares/error-handler.middleware.js +19 -0
  14. package/template/base/js/src/middlewares/index.js +11 -9
  15. package/template/base/js/src/middlewares/method-not-allowed.middleware.js +13 -13
  16. package/template/base/js/src/middlewares/not-found.middleware.js +10 -10
  17. package/template/base/js/src/middlewares/root.middleware.js +16 -16
  18. package/template/base/js/src/modules/v1/health/health.controller.js +21 -21
  19. package/template/base/js/src/modules/v1/health/health.route.js +9 -9
  20. package/template/base/js/src/modules/v1/health/index.js +5 -5
  21. package/template/base/js/src/modules/v1/index.js +8 -8
  22. package/template/base/js/src/routes.js +16 -16
  23. package/template/base/js/src/utils/http-error.js +74 -53
  24. package/template/base/js/src/utils/index.js +8 -2
  25. package/template/base/ts/package.json +1 -1
  26. package/template/base/ts/src/app.ts +3 -0
  27. package/template/base/ts/src/middlewares/error-handler.middleware.ts +23 -0
  28. package/template/base/ts/src/middlewares/index.ts +1 -0
  29. package/template/base/ts/src/middlewares/method-not-allowed.middleware.ts +2 -0
  30. package/template/base/ts/src/utils/http-error.ts +18 -0
  31. package/template/base/ts/src/utils/index.ts +3 -0
  32. package/template/base/ts/tsconfig.json +1 -2
  33. package/template/features/auth/models/index.ts +1 -1
  34. package/template/features/auth/models/user.model.ts +28 -28
  35. package/template/features/auth/modules/index.ts +1 -1
  36. package/template/features/auth/utils/jwt.ts +15 -15
  37. package/template/gateway/js/inject.js +8 -6
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 FORTUNE IFELOJU ALADETAN
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -346,20 +346,38 @@ npm link
346
346
 
347
347
  ## šŸ“„ License
348
348
 
349
- MIT
349
+ Apache License 2.0
350
+
351
+ Copyright Ā© 2026 Aladetan Fortune Ifeloju (IfeCodes)
352
+
353
+ Licensed under the Apache License, Version 2.0 (the "License");
354
+ you may not use this project except in compliance with the License.
355
+ You may obtain a copy of the License at:
356
+
357
+ http://www.apache.org/licenses/LICENSE-2.0
358
+
359
+ Unless required by applicable law or agreed to in writing, software
360
+ distributed under the License is distributed on an "AS IS" BASIS,
361
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
362
+ See the License for the specific language governing permissions and
363
+ limitations under the License.
350
364
 
351
365
  ---
352
366
 
353
367
  ## ✨ Author
354
368
 
355
369
  **Aladetan Fortune Ifeloju (IfeCodes)**
356
- Full Stack Developer & TechPreneur
370
+ Full-Stack Developer & TechPreneur
357
371
 
358
- - GitHub: [@ALADETAN-IFE](https://github.com/ALADETAN-IFE)
359
- - Twitter: [@IfeCodes](https://twitter.com/IfeCodes_)
372
+ - GitHub: [@ALADETAN-IFE](https://github.com/ALADETAN-IFE)
373
+ - Portfolio: [IFECODES](https://ifecodes.xyz)
374
+ - Twitter/X: [@IfeCodes](https://twitter.com/IfeCodes_)
375
+ - LinkedIn: [Aladetan Fortune Ife](https://www.linkedin.com/in/fortune-ife-aladetan-458ab136a?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=android_app)
360
376
 
361
377
  ---
362
378
 
363
379
  ## šŸ™ Acknowledgments
364
380
 
365
381
  Built with ā¤ļø for the developer community to accelerate backend development.
382
+
383
+ Special thanks to contributors and organizations who adopt, extend, and support this project while respecting its license and attribution.
package/bin/cli.js CHANGED
@@ -5,6 +5,7 @@ import { execSync } from "child_process";
5
5
  import { fileURLToPath } from "url";
6
6
  import pc from "picocolors";
7
7
  import { getProjectConfig } from "./lib/prompts.js";
8
+ import prompts from "prompts";
8
9
  import { setupService } from "./lib/service-setup.js";
9
10
  import { generateReadme } from "./lib/readme-generator.js";
10
11
  // No TS->JS transform: templates contain language-specific folders (base/js, base/ts)
@@ -35,6 +36,7 @@ const base = baseRoot;
35
36
 
36
37
  // Determine which services to create
37
38
  const servicesToCreate = [];
39
+ const servicesToSetup = [];
38
40
  if (isInMicroserviceProject) {
39
41
  const newServiceName = config.serviceName.replace(/\s+/g, "-");
40
42
  servicesToCreate.push(newServiceName);
@@ -259,13 +261,56 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
259
261
  for (const serviceName of servicesToCreate) {
260
262
  const serviceRoot = path.join(target, "services", serviceName);
261
263
 
262
- if (fs.existsSync(serviceRoot)) {
263
- console.error(`\nāŒ Error: Service '${serviceName}' already exists!`);
264
- process.exit(1);
264
+ // Check for exact or alternate folder conflicts (e.g., 'order' vs 'order-service')
265
+ const altName = serviceName.endsWith("-service")
266
+ ? serviceName.replace(/-service$/, "")
267
+ : `${serviceName}-service`;
268
+ const altPath = path.join(target, "services", altName);
269
+ let conflictPath = null;
270
+ if (fs.existsSync(serviceRoot)) conflictPath = serviceRoot;
271
+ else if (fs.existsSync(altPath)) conflictPath = altPath;
272
+
273
+ if (conflictPath) {
274
+ const rel = path.relative(target, conflictPath);
275
+ const resp = await prompts({
276
+ type: "select",
277
+ name: "action",
278
+ message: `Service directory '${rel}' already exists and conflicts with requested '${serviceName}'. Choose action:`,
279
+ choices: [
280
+ { title: "Abort generation", value: "abort" },
281
+ { title: `Skip creating '${serviceName}'`, value: "skip" },
282
+ {
283
+ title: `Overwrite '${rel}' with '${serviceName}'`,
284
+ value: "overwrite",
285
+ },
286
+ ],
287
+ initial: 0,
288
+ });
289
+
290
+ if (!resp.action || resp.action === "abort") {
291
+ console.log(pc.red("Aborting."));
292
+ process.exit(1);
293
+ }
294
+ if (resp.action === "skip") {
295
+ console.log(pc.yellow(`Skipping ${serviceName}`));
296
+ continue;
297
+ }
298
+ if (resp.action === "overwrite") {
299
+ try {
300
+ fs.rmSync(conflictPath, { recursive: true, force: true });
301
+ } catch (e) {
302
+ console.error(
303
+ pc.red(`Failed to remove existing path: ${conflictPath}`),
304
+ );
305
+ process.exit(1);
306
+ }
307
+ }
265
308
  }
266
309
 
267
310
  console.log(`\nšŸ”Ø Setting up ${serviceName}...`);
268
311
  fs.cpSync(base, serviceRoot, { recursive: true });
312
+ // track which services we actually created/overwrote so we can run setupService for them
313
+ servicesToSetup.push(serviceName);
269
314
 
270
315
  // Remove .env and .env.example from microservices (environment variables come from docker-compose/pm2)
271
316
  const envPath = path.join(serviceRoot, ".env");
@@ -294,14 +339,14 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
294
339
  // Include services we're about to create so port computation and gateway routing
295
340
  // are aware of newly added services when setting up files.
296
341
  const allServices = Array.from(
297
- new Set([...existingServices, ...servicesToCreate]),
342
+ new Set([...existingServices, ...servicesToSetup]),
298
343
  );
299
344
 
300
345
  // Step 1: Setup all service files first (without installing dependencies)
301
346
  console.log(pc.cyan("\nāš™ļø Setting up service files...\n"));
302
347
  const serviceConfigs = [];
303
348
 
304
- for (const serviceName of servicesToCreate) {
349
+ for (const serviceName of servicesToSetup) {
305
350
  const serviceRoot = path.join(target, "services", serviceName);
306
351
  const shouldIncludeAuth = isInMicroserviceProject
307
352
  ? config.auth
@@ -347,7 +392,9 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
347
392
  fs.mkdirSync(rootHuskyDir, { recursive: true });
348
393
  const preCommitPath = path.join(rootHuskyDir, "pre-commit");
349
394
  const preCommitContent =
350
- 'set -e\n\necho "Checking format (prettier)..."\nnpm run check-format\n\necho "Running TypeScript type-check..."\nnpx tsc --noEmit\n\necho "Checking lint..."\nnpm run lint -- --max-warnings=0\n';
395
+ config.language === "typescript"
396
+ ? 'set -e\n\necho "Checking format (prettier)..."\nnpm run check-format\n\necho "Running TypeScript type-check..."\nnpx tsc --noEmit\n\necho "Checking lint..."\nnpm run lint -- --max-warnings=0\n'
397
+ : 'set -e\n\necho "Checking format (prettier)..."\nnpm run check-format\n\necho "Checking lint..."\nnpm run lint -- --max-warnings=0\n';
351
398
  fs.writeFileSync(preCommitPath, preCommitContent);
352
399
  } catch (err) {
353
400
  // Non-fatal; continue setup even if husky files couldn't be created/removed
@@ -356,8 +403,8 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
356
403
  // Step 2: Generate docker-compose/pm2 config and root files
357
404
  if (mode === "docker") {
358
405
  generateDockerCompose(target, allServices, config.sanitizedName);
359
- copyDockerfile(target, servicesToCreate);
360
- copyDockerignore(target, servicesToCreate);
406
+ copyDockerfile(target, servicesToSetup);
407
+ copyDockerignore(target, servicesToSetup);
361
408
  } else {
362
409
  generatePm2Config(target, allServices);
363
410
  }
@@ -571,24 +618,28 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
571
618
 
572
619
  // Attempt several fallback strategies to inject port variables:
573
620
  // 1. Replace explicit placeholder if present in template
574
- // 2. Insert right after the first object opening brace
575
- // 3. Append to the end as a last resort
621
+ // 2. Insert right after the first object opening brace (or replace placeholder)
576
622
  if (envContent.includes("/*__PORTS__*/")) {
577
- envContent = envContent.replace("/*__PORTS__*/", portEnvVars);
623
+ envContent = envContent.replace(
624
+ "/*__PORTS__*/",
625
+ "/*__PORTS__*/\n" + portEnvVars,
626
+ );
578
627
  } else {
579
628
  // Fallback: find the opening brace of the exported ENV object and insert after it
580
629
  const braceIndex = envContent.indexOf("{");
581
630
  if (braceIndex !== -1) {
582
631
  const insertPos =
583
632
  envContent.indexOf("\n", braceIndex) + 1 || braceIndex + 1;
633
+ // insert a stable placeholder comment followed by the ports block
584
634
  envContent =
585
635
  envContent.slice(0, insertPos) +
636
+ " /*__PORTS__*/\n" +
586
637
  portEnvVars +
587
638
  "\n" +
588
639
  envContent.slice(insertPos);
589
640
  } else {
590
- // Final fallback: append to the end
591
- envContent = envContent + "\n" + portEnvVars;
641
+ // Final fallback: append a placeholder and the ports to the end
642
+ envContent = envContent + "\n/*__PORTS__*/\n" + portEnvVars;
592
643
  }
593
644
  }
594
645
 
@@ -620,23 +671,85 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
620
671
  )
621
672
  : allServices;
622
673
 
623
- let rootENVContent = `# Environment Configuration\nNODE_ENV=development\n\n`;
624
- svcList.forEach((service, index) => {
625
- const isGateway = service === "gateway";
626
- const port = isGateway
627
- ? 4000
628
- : 4001 +
629
- svcList.filter((s, i) => s !== "gateway" && i < index).length;
630
- const envVarName = `${service.toUpperCase().replace(/-/g, "_")}_PORT`;
631
- const serviceNamePretty = service
632
- .split("-")
633
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
634
- .join(" ");
635
- rootENVContent += `# ${serviceNamePretty}\n${envVarName}=${port}\n\n`;
636
- });
674
+ // Update only .env.example: preserve runtime .env (don't overwrite user changes)
675
+ try {
676
+ const envExamplePath = path.join(target, ".env.example");
677
+ const servicesPorts = svcList.map((service, index) => {
678
+ const isGateway = service === "gateway";
679
+ const port = isGateway
680
+ ? 4000
681
+ : 4001 +
682
+ svcList.filter((s, i) => s !== "gateway" && i < index).length;
683
+ const envVarName = `${service.toUpperCase().replace(/-/g, "_")}_PORT`;
684
+ const serviceNamePretty = service
685
+ .split("-")
686
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
687
+ .join(" ");
688
+ return `# ${serviceNamePretty}\n${envVarName}=${port}\n`;
689
+ });
690
+
691
+ const portsBlock = servicesPorts.join("\n");
692
+
693
+ let exampleContent = "";
694
+ if (fs.existsSync(envExamplePath)) {
695
+ exampleContent = fs.readFileSync(envExamplePath, "utf8");
696
+
697
+ // Remove existing *_PORT lines and any immediate preceding single-line comment
698
+ const lines = exampleContent.split(/\r?\n/);
699
+ const filtered = [];
700
+ for (let i = 0; i < lines.length; i++) {
701
+ const line = lines[i];
702
+ const next = lines[i + 1];
703
+ if (next && /^[A-Z0-9_]+_PORT=/.test(next.trim())) {
704
+ // skip this line if it's a comment immediately preceding a _PORT assignment
705
+ i++; // skip next as well
706
+ continue;
707
+ }
708
+ if (/^[A-Z0-9_]+_PORT=/.test(line.trim())) {
709
+ // skip existing port assignment
710
+ continue;
711
+ }
712
+ filtered.push(line);
713
+ }
714
+
715
+ exampleContent = filtered.join("\n");
716
+ } else {
717
+ // create minimal header if example file doesn't exist
718
+ exampleContent = `# Environment Configuration\nNODE_ENV=development\n\n`;
719
+ }
720
+
721
+ // Ensure NODE_ENV line exists and insert portsBlock after it
722
+ const nodeEnvRegex = /^NODE_ENV=.*$/m;
723
+ if (nodeEnvRegex.test(exampleContent)) {
724
+ exampleContent = exampleContent.replace(
725
+ nodeEnvRegex,
726
+ (m) => `${m}\n\n${portsBlock}\n`,
727
+ );
728
+ } else {
729
+ // Prepend header and ports
730
+ exampleContent =
731
+ `# Environment Configuration\nNODE_ENV=development\n\n${portsBlock}\n` +
732
+ exampleContent;
733
+ }
637
734
 
638
- fs.writeFileSync(path.join(target, ".env"), rootENVContent);
639
- fs.writeFileSync(path.join(target, ".env.example"), rootENVContent);
735
+ fs.writeFileSync(envExamplePath, exampleContent);
736
+ // Inform the user about the new ports and remind them to update their runtime .env if needed
737
+ try {
738
+ console.log(
739
+ pc.cyan("\nšŸ”§ Updated .env.example with service port entries:\n"),
740
+ );
741
+ console.log(pc.green(portsBlock));
742
+ console.log(
743
+ pc.dim(
744
+ "If you keep a runtime .env with custom overrides, do NOT overwrite it.\nPlease copy any new *_PORT entries from .env.example into .env as appropriate.",
745
+ ),
746
+ );
747
+ } catch (e) {
748
+ // non-fatal if logging fails
749
+ }
750
+ } catch (e) {
751
+ // non-fatal
752
+ }
640
753
  } catch (e) {
641
754
  // non-fatal
642
755
  }
@@ -684,6 +797,17 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
684
797
  } else {
685
798
  const result = await setupService(config, null, target, true);
686
799
  config.installSucceeded = result.installSucceeded;
800
+
801
+ // Safety net: ensure eslint.config.js exists in generated monolith projects
802
+ const templateEslintConfig = path.join(base, "eslint.config.js");
803
+ const generatedEslintConfig = path.join(target, "eslint.config.js");
804
+ if (
805
+ config.projectType === "monolith" &&
806
+ fs.existsSync(templateEslintConfig) &&
807
+ !fs.existsSync(generatedEslintConfig)
808
+ ) {
809
+ fs.copyFileSync(templateEslintConfig, generatedEslintConfig);
810
+ }
687
811
  }
688
812
 
689
813
  // Generate README.md for monolith (microservices already done above)
@@ -781,16 +905,16 @@ if (isInMicroserviceProject) {
781
905
  }
782
906
 
783
907
  if (isInMicroserviceProject) {
784
- console.log(
785
- `\n${pc.green("āœ… Service")} ${pc.bold(servicesToCreate[0])} ${pc.green("added successfully!")}`,
786
- );
908
+ if (servicesToSetup.length > 0) {
909
+ console.log(
910
+ `\n${pc.green("āœ… Service")} ${pc.bold(servicesToSetup[0])} ${pc.green("added successfully!")}`,
911
+ );
912
+ } else {
913
+ console.log(pc.yellow("\nāš ļø No new service was created (skipped by your selection)."));
914
+ }
787
915
  console.log(`\n${pc.cyan("šŸ“¦ All services:")} ${allServices.join(", ")}`);
788
916
  console.log(`\n${pc.blue("šŸ’” Next steps:")}`);
789
- console.log(
790
- mode === "docker"
791
- ? ` ${pc.dim("1.")} Start services: ${pc.bold("npm run dev")}`
792
- : ` ${pc.dim("1.")} Start services: ${pc.bold("pm2 start pm2.config.js")}`,
793
- );
917
+ console.log(` ${pc.dim("1.")} Start services: ${pc.bold("npm run dev")}`);
794
918
  } else if (config.projectType === "microservice") {
795
919
  console.log(`\n${pc.green("āœ… Microservice Backend created successfully!")}`);
796
920
  console.log(
@@ -798,11 +922,7 @@ if (isInMicroserviceProject) {
798
922
  );
799
923
  console.log(`\n${pc.blue("šŸ’” Next steps:")}`);
800
924
  console.log(` ${pc.dim("1.")} cd ${pc.bold(sanitizedName)}`);
801
- console.log(
802
- mode === "docker"
803
- ? ` ${pc.dim("2.")} Start services: ${pc.bold("npm run dev")}`
804
- : ` ${pc.dim("2.")} Start services: ${pc.bold("pm2 start pm2.config.js")}`,
805
- );
925
+ console.log(` ${pc.dim("2.")} Start services: ${pc.bold("npm run dev")}`);
806
926
  } else {
807
927
  console.log(`\n${pc.green("āœ… Monolith Backend created successfully!")}`);
808
928
  console.log(`\n${pc.blue("šŸ’” Next steps:")}`);