@ifecodes/backend-template 1.1.8 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +423 -365
  3. package/bin/cli.js +1276 -836
  4. package/bin/lib/microservice-config.js +155 -150
  5. package/bin/lib/prompts.js +277 -241
  6. package/bin/lib/readme-generator.js +364 -335
  7. package/bin/lib/service-setup.js +901 -679
  8. package/package.json +64 -55
  9. package/template/base/js/.env.example +5 -5
  10. package/template/base/js/.eslintrc.json +10 -13
  11. package/template/base/js/.husky/pre-commit +1 -7
  12. package/template/base/js/.prettierrc +7 -7
  13. package/template/base/js/eslint.config.js +33 -31
  14. package/template/base/js/package.json +29 -28
  15. package/template/base/js/src/app.js +20 -15
  16. package/template/base/js/src/config/env.js +32 -2
  17. package/template/base/js/src/config/index.js +2 -2
  18. package/template/base/js/src/docs/index.js +5 -0
  19. package/template/base/js/src/docs/route-registry.js +63 -0
  20. package/template/base/js/src/middlewares/error-handler.middleware.js +22 -0
  21. package/template/base/js/src/middlewares/index.js +9 -3
  22. package/template/base/js/src/middlewares/method-not-allowed.middleware.js +8 -2
  23. package/template/base/js/src/middlewares/not-found.middleware.js +4 -1
  24. package/template/base/js/src/middlewares/observability.middleware.js +24 -0
  25. package/template/base/js/src/middlewares/root.middleware.js +7 -5
  26. package/template/base/js/src/middlewares/validation.middleware.js +39 -0
  27. package/template/base/js/src/modules/index.js +8 -8
  28. package/template/base/js/src/modules/v1/health/health.controller.auth.js +29 -0
  29. package/template/base/js/src/modules/v1/health/health.controller.js +4 -4
  30. package/template/base/js/src/modules/v1/health/health.route.js +70 -5
  31. package/template/base/js/src/modules/v1/health/index.js +1 -1
  32. package/template/base/js/src/modules/v1/index.js +3 -3
  33. package/template/base/js/src/routes.js +13 -6
  34. package/template/base/js/src/server.js +18 -18
  35. package/template/base/js/src/utils/http-error.js +27 -6
  36. package/template/base/js/src/utils/index.js +28 -22
  37. package/template/base/js/src/utils/logger.js +57 -67
  38. package/template/base/ts/.eslintrc.json +13 -17
  39. package/template/base/ts/.prettierrc +7 -7
  40. package/template/base/ts/eslint.config.js +33 -33
  41. package/template/base/ts/package.json +41 -39
  42. package/template/base/ts/src/app.ts +20 -15
  43. package/template/base/ts/src/config/db.ts +4 -4
  44. package/template/base/ts/src/config/env.ts +40 -10
  45. package/template/base/ts/src/config/index.ts +2 -2
  46. package/template/base/ts/src/docs/index.ts +3 -0
  47. package/template/base/ts/src/docs/route-registry.ts +98 -0
  48. package/template/base/ts/src/middlewares/error-handler.middleware.ts +26 -0
  49. package/template/base/ts/src/middlewares/index.ts +6 -3
  50. package/template/base/ts/src/middlewares/method-not-allowed.middleware.ts +23 -16
  51. package/template/base/ts/src/middlewares/not-found.middleware.ts +10 -8
  52. package/template/base/ts/src/middlewares/observability.middleware.ts +25 -0
  53. package/template/base/ts/src/middlewares/root.middleware.ts +16 -14
  54. package/template/base/ts/src/middlewares/validation.middleware.ts +46 -0
  55. package/template/base/ts/src/modules/index.ts +8 -8
  56. package/template/base/ts/src/modules/v1/health/health.controller.auth.ts +26 -0
  57. package/template/base/ts/src/modules/v1/health/health.controller.ts +18 -18
  58. package/template/base/ts/src/modules/v1/health/health.route.ts +68 -9
  59. package/template/base/ts/src/modules/v1/health/index.ts +1 -1
  60. package/template/base/ts/src/modules/v1/index.ts +8 -8
  61. package/template/base/ts/src/routes.ts +23 -15
  62. package/template/base/ts/src/server.ts +19 -19
  63. package/template/base/ts/src/utils/http-error.ts +63 -45
  64. package/template/base/ts/src/utils/index.ts +14 -11
  65. package/template/base/ts/src/utils/logger.ts +58 -68
  66. package/template/base/ts/tsconfig.json +21 -22
  67. package/template/features/auth/argon2/inject.js +50 -50
  68. package/template/features/auth/base/health-openapi.ts +62 -0
  69. package/template/features/auth/base/inject.js +174 -172
  70. package/template/features/auth/bcrypt/inject.js +40 -40
  71. package/template/features/auth/models/user.model.js +24 -24
  72. package/template/features/auth/models/user.model.ts +1 -1
  73. package/template/features/auth/modules/auth.controller.js +21 -21
  74. package/template/features/auth/modules/auth.controller.ts +28 -20
  75. package/template/features/auth/modules/auth.routes.js +89 -10
  76. package/template/features/auth/modules/auth.routes.ts +86 -11
  77. package/template/features/auth/modules/auth.service.js +29 -29
  78. package/template/features/auth/modules/auth.service.ts +38 -38
  79. package/template/features/auth/modules/index.js +1 -1
  80. package/template/features/auth/utils/hash.ts +20 -20
  81. package/template/features/auth/utils/jwt.js +12 -12
  82. package/template/features/cors/inject.js +14 -13
  83. package/template/features/helmet/inject.js +7 -6
  84. package/template/features/morgan/inject.js +8 -7
  85. package/template/features/rate-limit/inject.js +7 -6
  86. package/template/gateway/js/app.js +42 -42
  87. package/template/gateway/js/inject.js +33 -31
  88. package/template/gateway/js/server.js +19 -19
  89. package/template/gateway/ts/app.ts +43 -43
  90. package/template/gateway/ts/inject.js +33 -33
  91. package/template/gateway/ts/server.ts +19 -19
  92. package/template/microservice/docker/docker-compose.yml +5 -5
  93. package/template/microservice/nodocker/pm2.config.js +3 -3
package/README.md CHANGED
@@ -1,365 +1,423 @@
1
- # 🚀 Backend Template Generator
2
-
3
- A powerful CLI tool to generate production-ready Node.js backend applications with Express.js. Supports both **TypeScript** and **JavaScript**, with monolith and microservice architectures, and optional features like authentication, CORS, rate limiting, and more.
4
-
5
- ---
6
-
7
- ## ✨ Features
8
-
9
- - 🎯 **TypeScript & JavaScript Support** - Choose your preferred language
10
- - 🏗️ **Dual Architecture** - Monolith or Microservice
11
- - 🐳 **Docker Ready** - Containerized microservices
12
- - ⚡ **PM2 Support** - Process management for production
13
- - 🔐 **JWT Authentication** - Built-in auth with MongoDB
14
- - 🛡️ **Security First** - CORS, Helmet, Rate Limiting
15
- - 📝 **Professional Logging** - Morgan + Winston
16
- - 🎨 **Colored CLI** - Beautiful Vite-like terminal output
17
- - 📋 **Project Metadata** - Description, author, and keywords support
18
-
19
- ---
20
-
21
- ## 📦 Installation & Usage
22
-
23
- ### Quick Start
24
-
25
- ```bash
26
- npx @ifecodes/backend-template my-project
27
- ```
28
-
29
- Or install globally:
30
-
31
- ```bash
32
- npm install -g @ifecodes/backend-template
33
- ifecodes-template my-project
34
- ```
35
-
36
- ### With Arguments
37
-
38
- ```bash
39
- # Create a monolith
40
- npx @ifecodes/backend-template my-api mono
41
-
42
- # Create a microservice
43
- npx @ifecodes/backend-template my-project micro
44
- ```
45
-
46
- ---
47
-
48
- ## 🧠 Interactive Setup
49
-
50
- When you run the CLI, you'll be prompted to choose:
51
-
52
- ### 1. **Language**
53
-
54
- - **TypeScript** (default) - Full type safety and modern tooling
55
- - **JavaScript** - Transpiled from TypeScript for simplicity
56
-
57
- ### 2. **Project Metadata**
58
-
59
- - **Description** - Project description for package.json
60
- - **Author** - Your name or organization
61
- - **Keywords** - Comma-separated keywords for discoverability
62
-
63
- ### 3. **Project Type**
64
-
65
- - **Monolith API** - Traditional single-server architecture
66
- - **Microservice** - Distributed services with API Gateway
67
-
68
- ### 4. **Deployment Mode** (Microservices only)
69
-
70
- - **Docker** - Container-based deployment with docker-compose
71
- - **PM2** - Process manager for Node.js applications
72
-
73
- ### 5. **Optional Features**
74
-
75
- - **CORS** - Cross-Origin Resource Sharing
76
- - ✅ **Helmet** - Security headers middleware
77
- - **Rate Limiting** - API request throttling
78
- - ✅ **Morgan** - HTTP request logger
79
-
80
- ### 6. **Authentication**
81
-
82
- - **JWT Authentication** with MongoDB
83
- - Choose between **bcrypt** (recommended for Windows) or **argon2** for password hashing
84
-
85
- ---
86
-
87
- ## 🗂 Project Structure
88
-
89
- ### Monolith
90
-
91
- ```
92
- my-backend/
93
- ├── src/
94
- │ ├── config/ # Configuration files
95
- │ ├── middlewares/ # Custom middlewares
96
- │ ├── modules/ # Feature modules
97
- │ │ └── v1/ # API version 1
98
- │ │ ├── auth/ # Auth module (if enabled)
99
- │ │ └── health/ # Health check
100
- │ ├── models/ # Database models (if auth)
101
- │ ├── utils/ # Utility functions
102
- │ ├── app.ts # Express app setup
103
- │ ├── routes.ts # Route definitions
104
- │ └── server.ts # Server entry point
105
- ├── .husky/ # Git hooks
106
- ├── .env # Environment variables
107
- ├── package.json
108
- └── tsconfig.json
109
- ```
110
-
111
- ### Microservice
112
-
113
- ```
114
- my-project/
115
- ├── shared/ # Shared utilities across services
116
- │ ├── config/ # Environment configs (db.ts only if auth enabled)
117
- │ └── utils/ # Logger, error handlers
118
- ├── services/
119
- │ ├── gateway/ # API Gateway (port 4000)
120
- │ ├── health-service/ # Health checks (port 4001)
121
- │ └── auth-service/ # Authentication (port 4002, if enabled)
122
- ├── docker-compose.yml # Docker setup (if selected)
123
- ├── pm2.config.js # PM2 setup (if selected)
124
- ├── .env # Root environment variables
125
- ├── .gitignore # Git ignore (includes .env and node_modules)
126
- ├── tsconfig.json # Root TypeScript config with project references
127
- ├── .husky/ # Git hooks
128
- └── package.json # Root package.json
129
- ```
130
-
131
- **Note**: Each microservice does NOT have its own `.env` file. Environment variables are managed at the root level through `docker-compose.yml` or `pm2.config.js`.
132
-
133
- ---
134
-
135
- ## ▶️ Running the Application
136
-
137
- ### Monolith
138
-
139
- ```bash
140
- cd my-backend
141
-
142
- # Development
143
- npm run dev
144
-
145
- # Production
146
- npm run build
147
- npm start
148
- ```
149
-
150
- ### Microservice (Docker)
151
-
152
- ```bash
153
- cd my-project
154
-
155
- # Start all services
156
- docker-compose up
157
-
158
- # Start in detached mode
159
- docker-compose up -d
160
-
161
- # View logs
162
- docker-compose logs -f
163
-
164
- # Stop all services
165
- docker-compose down
166
- ```
167
-
168
- ### Microservice (PM2)
169
-
170
- ```bash
171
- cd my-project
172
-
173
- # Start all services
174
- pm2 start pm2.config.js
175
-
176
- # View logs
177
- pm2 logs
178
-
179
- # Monitor services
180
- pm2 monit
181
-
182
- # Stop all services
183
- pm2 stop all
184
- ```
185
-
186
- ---
187
-
188
- ## 🛠 Tech Stack
189
-
190
- - **Runtime**: Node.js (v18+)
191
- - **Language**: TypeScript or JavaScript
192
- - **Framework**: Express.js
193
- - **Database**: MongoDB (with Mongoose, if auth enabled)
194
- - **Authentication**: JWT + bcrypt/argon2
195
- - **Security**: Helmet, CORS, Rate Limiting
196
- - **Logging**: Morgan, Custom Logger
197
- - **Git Hooks**: Husky
198
- - **Deployment**: Docker or PM2
199
-
200
- ---
201
-
202
- ## TypeScript vs JavaScript
203
-
204
- This CLI generates **TypeScript** projects by default but also includes explicit **JavaScript** templates. There is no fragile, on-the-fly TypeScript → JavaScript transform at runtime — the project templates include language-specific variants so the output is predictable and parseable in Node.js.
205
-
206
- ### TypeScript (Default)
207
-
208
- - Full type safety and IntelliSense
209
- - Modern ECMAScript features
210
- - Compile-time error checking
211
- - Better tooling and refactoring support
212
-
213
- ### JavaScript
214
-
215
- - Pre-authored JavaScript (CommonJS) templates are included
216
- - No TypeScript annotations remain in generated `.js` files
217
- - DevDependencies that are TypeScript-only are omitted for JS projects
218
- - Same functionality with simpler runtime setup
219
-
220
- ---
221
-
222
- ## 🌟 Features
223
-
224
- ### ✅ Smart Defaults
225
-
226
- - Auto-generates README with project-specific instructions
227
- - Creates `.env` from `.env.example` with default values
228
- - Configures TypeScript paths for clean imports (`@/config`, `@/utils`)
229
- - Project metadata (description, author, keywords) in package.json
230
-
231
- ### Microservice Architecture
232
-
233
- - **API Gateway** on port 4000 (single entry point)
234
- - **Service Discovery** - Automatically routes to correct service
235
- - **Shared Folder** - Common utilities across all services
236
- - **Health Checks** - Built-in monitoring endpoints
237
-
238
- ### Developer Experience
239
-
240
- - **Hot Reload** - Development server with nodemon
241
- - **ESLint** - Code quality enforcement
242
- - **Git Hooks** - Pre-commit linting with Husky
243
- - **Type Safety** - Full TypeScript support
244
-
245
- ---
246
-
247
- ## 📡 API Endpoints
248
-
249
- ### Monolith
250
-
251
- ```
252
- GET / - API information
253
- GET /api/v1/health - Health check
254
- POST /api/v1/auth/register - Register user (if auth enabled)
255
- POST /api/v1/auth/login - Login user (if auth enabled)
256
- ```
257
-
258
- ### Microservice
259
-
260
- All requests go through the API Gateway at `http://localhost:4000`
261
-
262
- ```
263
- GET /health - Gateway health check
264
- GET /api/v1/health - Health service check
265
- POST /api/v1/auth/register - Auth service (if enabled)
266
- POST /api/v1/auth/login - Auth service (if enabled)
267
- ```
268
-
269
- ---
270
-
271
- ## 🔧 Environment Variables
272
-
273
- ### Monolith
274
-
275
- ```env
276
- PORT=4000
277
- NODE_ENV=development
278
- ```
279
-
280
- ### Microservice (Root .env)
281
-
282
- ```env
283
- NODE_ENV=development
284
-
285
- # Gateway Service
286
- GATEWAY_PORT=4000
287
-
288
- # Health Service
289
- HEALTH_SERVICE_PORT=4001
290
-
291
- # Auth Service (if enabled)
292
- AUTH_SERVICE_PORT=4002
293
- ```
294
-
295
- **Note**: Microservices use environment variables from `docker-compose.yml` or `pm2.config.js`. Individual services don't have `.env` files.
296
-
297
- ### With CORS
298
-
299
- ```env
300
- ALLOWED_ORIGIN=http://localhost:3000
301
- ```
302
-
303
- ### With Authentication
304
-
305
- ```env
306
- MONGO_URI=mongodb://localhost:27017/your-database-name
307
- JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
308
- ```
309
-
310
- ---
311
-
312
- ## 🚀 Adding Services (Microservice)
313
-
314
- You can add more services to an existing microservice project:
315
-
316
- ```bash
317
- cd my-project
318
- npx @ifecodes/backend-template
319
-
320
- # You'll be prompted to name the new service
321
- # Example: user-service, order-service, etc.
322
- ```
323
-
324
- The CLI will:
325
-
326
- - Create the new service
327
- - Update `docker-compose.yml` or `pm2.config.js`
328
- - Configure routing in the API Gateway
329
-
330
- ---
331
-
332
- ## 🤝 Contributing
333
-
334
- Contributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details.
335
-
336
- ### Development
337
-
338
- ```bash
339
- git clone https://github.com/ALADETAN-IFE/backend-template.git
340
- cd backend-template
341
- npm install
342
- npm link
343
- ```
344
-
345
- ---
346
-
347
- ## 📄 License
348
-
349
- MIT
350
-
351
- ---
352
-
353
- ## ✨ Author
354
-
355
- **Aladetan Fortune Ifeloju (IfeCodes)**
356
- Full Stack Developer & TechPreneur
357
-
358
- - GitHub: [@ALADETAN-IFE](https://github.com/ALADETAN-IFE)
359
- - Twitter: [@IfeCodes](https://twitter.com/IfeCodes_)
360
-
361
- ---
362
-
363
- ## 🙏 Acknowledgments
364
-
365
- Built with ❤️ for the developer community to accelerate backend development.
1
+ # 🚀 Backend Template Generator
2
+
3
+ A powerful CLI tool to generate production-ready Node.js backend applications with Express.js. Supports both **TypeScript** and **JavaScript**, with monolith and microservice architectures, and optional features like authentication, CORS, rate limiting, and more.
4
+
5
+ ---
6
+
7
+ ## ✨ Features
8
+
9
+ - 🎯 **TypeScript & JavaScript Support** - Choose your preferred language
10
+ - 🏗️ **Dual Architecture** - Monolith or Microservice
11
+ - 🐳 **Docker Ready** - Containerized microservices
12
+ - ⚡ **PM2 Support** - Process management for production
13
+ - 🔐 **JWT Authentication** - Built-in auth with MongoDB
14
+ - 🛡️ **Security First** - CORS, Helmet, Rate Limiting
15
+ - 📝 **Professional Logging** - Morgan + Winston
16
+ - 🎨 **Colored CLI** - Beautiful Vite-like terminal output
17
+ - **Environment Validation** - Fails fast on missing config
18
+ - 📈 **Observability** - Request IDs and HTTP access logs
19
+ - � **CI/CD Workflows** - GitHub Actions starter workflow for team projects
20
+ - 📋 **Project Metadata** - Description, author, and keywords support
21
+ - 📖 **Contributing Guide** - Auto-generated CONTRIBUTING.md for team projects
22
+ - 🔀 **PR Templates** - Pre-formatted pull request templates for team projects
23
+
24
+ ---
25
+
26
+ ## 🤝 Team & Individual Projects
27
+
28
+ The template distinguishes between **team projects** and **individual projects** during setup:
29
+
30
+ ### Team Projects
31
+
32
+ Team projects automatically receive:
33
+
34
+ - ✅ **GitHub Actions Workflow** (`.github/workflows/ci-cd.yml`) - CI/CD automation for building, linting, and testing
35
+ - ✅ **Pull Request Template** (`.github/pull_request_template.md`) - Standardized PR format for contributions
36
+ - **Contributing Guide** (`CONTRIBUTING.md`) - Guidelines for team collaboration, code style, commit conventions, and development setup
37
+
38
+ ### Individual Projects
39
+
40
+ Individual projects skip these collaboration files, keeping the scaffold lean and focused on the application itself.
41
+
42
+ You can specify your project type during CLI setup, and these files will be generated accordingly.
43
+
44
+ ---
45
+
46
+ ## 📦 Installation & Usage
47
+
48
+ ### Quick Start
49
+
50
+ ```bash
51
+ npx @ifecodes/backend-template my-project
52
+ ```
53
+
54
+ Or install globally:
55
+
56
+ ```bash
57
+ npm install -g @ifecodes/backend-template
58
+ ifecodes-template my-project
59
+ ```
60
+
61
+ ### With Arguments
62
+
63
+ ```bash
64
+ # Create a monolith
65
+ npx @ifecodes/backend-template my-api mono
66
+
67
+ # Create a microservice
68
+ npx @ifecodes/backend-template my-project micro
69
+ ```
70
+
71
+ ---
72
+
73
+ ## 🧠 Interactive Setup
74
+
75
+ When you run the CLI, you'll be prompted to choose:
76
+
77
+ ### 1. **Language**
78
+
79
+ - **TypeScript** (default) - Full type safety and modern tooling
80
+ - **JavaScript** - Transpiled from TypeScript for simplicity
81
+
82
+ ### 2. **Project Metadata**
83
+
84
+ - **Description** - Project description for package.json
85
+ - **Author** - Your name or organization
86
+ - **Keywords** - Comma-separated keywords for discoverability
87
+
88
+ ### 3. **Project Type**
89
+
90
+ - **Monolith API** - Traditional single-server architecture
91
+ - **Microservice** - Distributed services with API Gateway
92
+
93
+ ### 4. **Project Scope** (Team or Individual)
94
+
95
+ - **Team Project** - Generates CI/CD workflows, PR templates, and contributing guidelines
96
+ - **Individual Project** - Focuses on the application without collaboration overhead
97
+
98
+ ### 5. **Deployment Mode** (Microservices only)
99
+
100
+ - **Docker** - Container-based deployment with docker-compose
101
+ - **PM2** - Process manager for Node.js applications
102
+
103
+ ### 6. **Optional Features**
104
+
105
+ - **CORS** - Cross-Origin Resource Sharing
106
+ - **Helmet** - Security headers middleware
107
+ - ✅ **Rate Limiting** - API request throttling
108
+ - ✅ **Morgan** - HTTP request logger
109
+
110
+ ### 7. **Authentication**
111
+
112
+ - ✅ **JWT Authentication** with MongoDB
113
+ - Choose between **bcrypt** (recommended for Windows) or **argon2** for password hashing
114
+
115
+ ---
116
+
117
+ ## 🗂 Project Structure
118
+
119
+ ### Monolith
120
+
121
+ ```
122
+ my-backend/
123
+ ├── src/
124
+ ├── config/ # Configuration files
125
+ ├── middlewares/ # Custom middlewares
126
+ ├── modules/ # Feature modules
127
+ │ │ └── v1/ # API version 1
128
+ │ │ ├── auth/ # Auth module (if enabled)
129
+ │ │ └── health/ # Health check
130
+ │ ├── models/ # Database models (if auth)
131
+ │ ├── utils/ # Utility functions
132
+ │ ├── app.ts # Express app setup
133
+ │ ├── routes.ts # Route definitions
134
+ │ └── server.ts # Server entry point
135
+ ├── .github/ # GitHub configuration (team projects only)
136
+ │ ├── workflows/ # CI/CD workflows
137
+ │ │ └── ci-cd.yml # GitHub Actions workflow
138
+ │ └── pull_request_template.md # PR template
139
+ ├── .husky/ # Git hooks
140
+ ├── .env # Environment variables
141
+ ├── CONTRIBUTING.md # Contribution guidelines (team projects only)
142
+ ├── package.json
143
+ └── tsconfig.json
144
+ ```
145
+
146
+ ### Microservice
147
+
148
+ ```
149
+ my-project/
150
+ ├── shared/ # Shared utilities across services
151
+ │ ├── config/ # Environment configs (db.ts only if auth enabled)
152
+ │ └── utils/ # Logger, error handlers
153
+ ├── services/
154
+ │ ├── gateway/ # API Gateway (port 4000)
155
+ │ ├── health-service/ # Health checks (port 4001)
156
+ │ └── auth-service/ # Authentication (port 4002, if enabled)
157
+ ├── .github/ # GitHub configuration (team projects only)
158
+ │ ├── workflows/ # CI/CD workflows
159
+ │ │ └── ci-cd.yml # GitHub Actions workflow
160
+ │ └── pull_request_template.md # PR template
161
+ ├── docker-compose.yml # Docker setup (if selected)
162
+ ├── pm2.config.js # PM2 setup (if selected)
163
+ ├── .env # Root environment variables
164
+ ├── .gitignore # Git ignore (includes .env and node_modules)
165
+ ├── CONTRIBUTING.md # Contribution guidelines (team projects only)
166
+ ├── tsconfig.json # Root TypeScript config with project references
167
+ ├── .husky/ # Git hooks
168
+ └── package.json # Root package.json
169
+ ```
170
+
171
+ **Note**: Each microservice does NOT have its own `.env` file. Environment variables are managed at the root level through `docker-compose.yml` or `pm2.config.js`.
172
+
173
+ ---
174
+
175
+ ## ▶️ Running the Application
176
+
177
+ ### Monolith
178
+
179
+ ```bash
180
+ cd my-backend
181
+
182
+ # Development
183
+ npm run dev
184
+
185
+ # Production
186
+ npm run build
187
+ npm start
188
+ ```
189
+
190
+ ### Microservice (Docker)
191
+
192
+ ```bash
193
+ cd my-project
194
+
195
+ # Start all services
196
+ docker-compose up
197
+
198
+ # Start in detached mode
199
+ docker-compose up -d
200
+
201
+ # View logs
202
+ docker-compose logs -f
203
+
204
+ # Stop all services
205
+ docker-compose down
206
+ ```
207
+
208
+ ### Microservice (PM2)
209
+
210
+ ```bash
211
+ cd my-project
212
+
213
+ # Start all services
214
+ pm2 start pm2.config.js
215
+
216
+ # View logs
217
+ pm2 logs
218
+
219
+ # Monitor services
220
+ pm2 monit
221
+
222
+ # Stop all services
223
+ pm2 stop all
224
+ ```
225
+
226
+ ---
227
+
228
+ ## 🛠 Tech Stack
229
+
230
+ - **Runtime**: Node.js (v18+)
231
+ - **Language**: TypeScript or JavaScript
232
+ - **Framework**: Express.js
233
+ - **Database**: MongoDB (with Mongoose, if auth enabled)
234
+ - **Authentication**: JWT + bcrypt/argon2
235
+ - **Security**: Helmet, CORS, Rate Limiting
236
+ - **Logging**: Morgan, Custom Logger
237
+ - **Git Hooks**: Husky
238
+ - **Deployment**: Docker or PM2
239
+
240
+ ---
241
+
242
+ ## TypeScript vs JavaScript
243
+
244
+ This CLI generates **TypeScript** projects by default but also includes explicit **JavaScript** templates. There is no fragile, on-the-fly TypeScript → JavaScript transform at runtime — the project templates include language-specific variants so the output is predictable and parseable in Node.js.
245
+
246
+ ### TypeScript (Default)
247
+
248
+ - Full type safety and IntelliSense
249
+ - Modern ECMAScript features
250
+ - Compile-time error checking
251
+ - Better tooling and refactoring support
252
+
253
+ ### JavaScript
254
+
255
+ - Pre-authored JavaScript (CommonJS) templates are included
256
+ - No TypeScript annotations remain in generated `.js` files
257
+ - DevDependencies that are TypeScript-only are omitted for JS projects
258
+ - Same functionality with simpler runtime setup
259
+
260
+ ---
261
+
262
+ ## 🌟 Features
263
+
264
+ ### Smart Defaults
265
+
266
+ - Auto-generates README with project-specific instructions
267
+ - Creates `.env` from `.env.example` with default values
268
+ - Configures TypeScript paths for clean imports (`@/config`, `@/utils`)
269
+ - Project metadata (description, author, keywords) in package.json
270
+
271
+ ### Microservice Architecture
272
+
273
+ - **API Gateway** on port 4000 (single entry point)
274
+ - **Service Discovery** - Automatically routes to correct service
275
+ - **Shared Folder** - Common utilities across all services
276
+ - **Health Checks** - Built-in monitoring endpoints
277
+
278
+ ### ✅ Developer Experience
279
+
280
+ - **Hot Reload** - Development server with nodemon
281
+ - **ESLint** - Code quality enforcement
282
+ - **Git Hooks** - Pre-commit linting with Husky
283
+ - **Type Safety** - Full TypeScript support
284
+
285
+ ---
286
+
287
+ ## 📡 API Endpoints
288
+
289
+ ### Monolith
290
+
291
+ ```
292
+ GET / - API information
293
+ GET /api/v1/health - Health check
294
+ POST /api/v1/auth/register - Register user (if auth enabled)
295
+ POST /api/v1/auth/login - Login user (if auth enabled)
296
+ ```
297
+
298
+ ### Microservice
299
+
300
+ All requests go through the API Gateway at `http://localhost:4000`
301
+
302
+ ```
303
+ GET /health - Gateway health check
304
+ GET /api/v1/health - Health service check
305
+ POST /api/v1/auth/register - Auth service (if enabled)
306
+ POST /api/v1/auth/login - Auth service (if enabled)
307
+ ```
308
+
309
+ ---
310
+
311
+ ## 🔧 Environment Variables
312
+
313
+ ### Monolith
314
+
315
+ ```env
316
+ PORT=4000
317
+ NODE_ENV=development
318
+ ```
319
+
320
+ ### Microservice (Root .env)
321
+
322
+ ```env
323
+ NODE_ENV=development
324
+
325
+ # Gateway Service
326
+ GATEWAY_PORT=4000
327
+
328
+ # Health Service
329
+ HEALTH_SERVICE_PORT=4001
330
+
331
+ # Auth Service (if enabled)
332
+ AUTH_SERVICE_PORT=4002
333
+ ```
334
+
335
+ **Note**: Microservices use environment variables from `docker-compose.yml` or `pm2.config.js`. Individual services don't have `.env` files.
336
+
337
+ ### With CORS
338
+
339
+ ```env
340
+ ALLOWED_ORIGIN=http://localhost:3000
341
+ ```
342
+
343
+ ### With Authentication
344
+
345
+ ```env
346
+ MONGO_URI=mongodb://localhost:27017/your-database-name
347
+ JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
348
+ ```
349
+
350
+ ---
351
+
352
+ ## 🚀 Adding Services (Microservice)
353
+
354
+ You can add more services to an existing microservice project:
355
+
356
+ ```bash
357
+ cd my-project
358
+ npx @ifecodes/backend-template
359
+
360
+ # You'll be prompted to name the new service
361
+ # Example: user-service, order-service, etc.
362
+ ```
363
+
364
+ The CLI will:
365
+
366
+ - Create the new service
367
+ - Update `docker-compose.yml` or `pm2.config.js`
368
+ - Configure routing in the API Gateway
369
+
370
+ ---
371
+
372
+ ## 🤝 Contributing
373
+
374
+ Contributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details.
375
+
376
+ ### Development
377
+
378
+ ```bash
379
+ git clone https://github.com/ALADETAN-IFE/backend-template.git
380
+ cd backend-template
381
+ npm install
382
+ npm link
383
+ ```
384
+
385
+ ---
386
+
387
+ ## 📄 License
388
+
389
+ Apache License 2.0
390
+
391
+ Copyright © 2026 Aladetan Fortune Ifeloju (IfeCodes)
392
+
393
+ Licensed under the Apache License, Version 2.0 (the "License");
394
+ you may not use this project except in compliance with the License.
395
+ You may obtain a copy of the License at:
396
+
397
+ http://www.apache.org/licenses/LICENSE-2.0
398
+
399
+ Unless required by applicable law or agreed to in writing, software
400
+ distributed under the License is distributed on an "AS IS" BASIS,
401
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
402
+ See the License for the specific language governing permissions and
403
+ limitations under the License.
404
+
405
+ ---
406
+
407
+ ## ✨ Author
408
+
409
+ **Aladetan Fortune Ifeloju (IfeCodes)**
410
+ Full-Stack Developer & TechPreneur
411
+
412
+ - GitHub: [@ALADETAN-IFE](https://github.com/ALADETAN-IFE)
413
+ - Portfolio: [IFECODES](https://ifecodes.xyz)
414
+ - Twitter/X: [@IfeCodes](https://twitter.com/IfeCodes_)
415
+ - 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)
416
+
417
+ ---
418
+
419
+ ## 🙏 Acknowledgments
420
+
421
+ Built with ❤️ for the developer community to accelerate backend development.
422
+
423
+ Special thanks to contributors and organizations who adopt, extend, and support this project while respecting its license and attribution.