@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.
- package/LICENSE +201 -0
- package/README.md +423 -365
- package/bin/cli.js +1276 -836
- package/bin/lib/microservice-config.js +155 -150
- package/bin/lib/prompts.js +277 -241
- package/bin/lib/readme-generator.js +364 -335
- package/bin/lib/service-setup.js +901 -679
- package/package.json +64 -55
- package/template/base/js/.env.example +5 -5
- package/template/base/js/.eslintrc.json +10 -13
- package/template/base/js/.husky/pre-commit +1 -7
- package/template/base/js/.prettierrc +7 -7
- package/template/base/js/eslint.config.js +33 -31
- package/template/base/js/package.json +29 -28
- package/template/base/js/src/app.js +20 -15
- package/template/base/js/src/config/env.js +32 -2
- package/template/base/js/src/config/index.js +2 -2
- package/template/base/js/src/docs/index.js +5 -0
- package/template/base/js/src/docs/route-registry.js +63 -0
- package/template/base/js/src/middlewares/error-handler.middleware.js +22 -0
- package/template/base/js/src/middlewares/index.js +9 -3
- package/template/base/js/src/middlewares/method-not-allowed.middleware.js +8 -2
- package/template/base/js/src/middlewares/not-found.middleware.js +4 -1
- package/template/base/js/src/middlewares/observability.middleware.js +24 -0
- package/template/base/js/src/middlewares/root.middleware.js +7 -5
- package/template/base/js/src/middlewares/validation.middleware.js +39 -0
- package/template/base/js/src/modules/index.js +8 -8
- package/template/base/js/src/modules/v1/health/health.controller.auth.js +29 -0
- package/template/base/js/src/modules/v1/health/health.controller.js +4 -4
- package/template/base/js/src/modules/v1/health/health.route.js +70 -5
- package/template/base/js/src/modules/v1/health/index.js +1 -1
- package/template/base/js/src/modules/v1/index.js +3 -3
- package/template/base/js/src/routes.js +13 -6
- package/template/base/js/src/server.js +18 -18
- package/template/base/js/src/utils/http-error.js +27 -6
- package/template/base/js/src/utils/index.js +28 -22
- package/template/base/js/src/utils/logger.js +57 -67
- package/template/base/ts/.eslintrc.json +13 -17
- package/template/base/ts/.prettierrc +7 -7
- package/template/base/ts/eslint.config.js +33 -33
- package/template/base/ts/package.json +41 -39
- package/template/base/ts/src/app.ts +20 -15
- package/template/base/ts/src/config/db.ts +4 -4
- package/template/base/ts/src/config/env.ts +40 -10
- package/template/base/ts/src/config/index.ts +2 -2
- package/template/base/ts/src/docs/index.ts +3 -0
- package/template/base/ts/src/docs/route-registry.ts +98 -0
- package/template/base/ts/src/middlewares/error-handler.middleware.ts +26 -0
- package/template/base/ts/src/middlewares/index.ts +6 -3
- package/template/base/ts/src/middlewares/method-not-allowed.middleware.ts +23 -16
- package/template/base/ts/src/middlewares/not-found.middleware.ts +10 -8
- package/template/base/ts/src/middlewares/observability.middleware.ts +25 -0
- package/template/base/ts/src/middlewares/root.middleware.ts +16 -14
- package/template/base/ts/src/middlewares/validation.middleware.ts +46 -0
- package/template/base/ts/src/modules/index.ts +8 -8
- package/template/base/ts/src/modules/v1/health/health.controller.auth.ts +26 -0
- package/template/base/ts/src/modules/v1/health/health.controller.ts +18 -18
- package/template/base/ts/src/modules/v1/health/health.route.ts +68 -9
- package/template/base/ts/src/modules/v1/health/index.ts +1 -1
- package/template/base/ts/src/modules/v1/index.ts +8 -8
- package/template/base/ts/src/routes.ts +23 -15
- package/template/base/ts/src/server.ts +19 -19
- package/template/base/ts/src/utils/http-error.ts +63 -45
- package/template/base/ts/src/utils/index.ts +14 -11
- package/template/base/ts/src/utils/logger.ts +58 -68
- package/template/base/ts/tsconfig.json +21 -22
- package/template/features/auth/argon2/inject.js +50 -50
- package/template/features/auth/base/health-openapi.ts +62 -0
- package/template/features/auth/base/inject.js +174 -172
- package/template/features/auth/bcrypt/inject.js +40 -40
- package/template/features/auth/models/user.model.js +24 -24
- package/template/features/auth/models/user.model.ts +1 -1
- package/template/features/auth/modules/auth.controller.js +21 -21
- package/template/features/auth/modules/auth.controller.ts +28 -20
- package/template/features/auth/modules/auth.routes.js +89 -10
- package/template/features/auth/modules/auth.routes.ts +86 -11
- package/template/features/auth/modules/auth.service.js +29 -29
- package/template/features/auth/modules/auth.service.ts +38 -38
- package/template/features/auth/modules/index.js +1 -1
- package/template/features/auth/utils/hash.ts +20 -20
- package/template/features/auth/utils/jwt.js +12 -12
- package/template/features/cors/inject.js +14 -13
- package/template/features/helmet/inject.js +7 -6
- package/template/features/morgan/inject.js +8 -7
- package/template/features/rate-limit/inject.js +7 -6
- package/template/gateway/js/app.js +42 -42
- package/template/gateway/js/inject.js +33 -31
- package/template/gateway/js/server.js +19 -19
- package/template/gateway/ts/app.ts +43 -43
- package/template/gateway/ts/inject.js +33 -33
- package/template/gateway/ts/server.ts +19 -19
- package/template/microservice/docker/docker-compose.yml +5 -5
- 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
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
├──
|
|
124
|
-
├──
|
|
125
|
-
├──
|
|
126
|
-
├──
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
#
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
#
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
#
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
#
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
#
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
- **
|
|
234
|
-
- **
|
|
235
|
-
- **
|
|
236
|
-
- **
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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.
|