@ifecodes/backend-template 1.1.3 → 1.1.6
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/README.md +39 -18
- package/bin/cli.js +602 -101
- package/bin/lib/microservice-config.js +68 -14
- package/bin/lib/prompts.js +25 -6
- package/bin/lib/readme-generator.js +119 -29
- package/bin/lib/service-setup.js +401 -132
- package/package.json +2 -2
- package/template/base/js/.eslintrc.json +13 -0
- package/template/base/js/.prettierrc +7 -0
- package/template/base/js/eslint.config.js +31 -0
- package/template/base/js/package.json +28 -0
- package/template/base/js/src/app.js +15 -0
- package/template/base/js/src/config/db.js +8 -0
- package/template/base/js/src/config/env.js +14 -0
- package/template/base/js/src/config/index.js +7 -0
- package/template/base/js/src/middlewares/index.js +9 -0
- package/template/base/js/src/middlewares/method-not-allowed.middleware.js +13 -0
- package/template/base/js/src/middlewares/not-found.middleware.js +10 -0
- package/template/base/js/src/middlewares/root.middleware.js +16 -0
- package/template/base/js/src/modules/index.js +8 -0
- package/template/base/js/src/modules/v1/health/health.controller.js +21 -0
- package/template/base/js/src/modules/v1/health/health.route.js +9 -0
- package/template/base/js/src/modules/v1/health/index.js +5 -0
- package/template/base/js/src/modules/v1/index.js +8 -0
- package/template/base/js/src/routes.js +16 -0
- package/template/base/js/src/server.js +18 -0
- package/template/base/js/src/utils/http-error.js +53 -0
- package/template/base/js/src/utils/index.js +22 -0
- package/template/base/js/src/utils/logger.js +67 -0
- package/template/base/ts/.env.example +5 -0
- package/template/base/ts/.husky/pre-commit +13 -0
- package/template/base/ts/.prettierignore +47 -0
- package/template/base/ts/gitignore +31 -0
- package/template/base/ts/src/app.ts +15 -0
- package/template/base/{src → ts/src}/config/env.ts +10 -10
- package/template/base/{src → ts/src}/middlewares/index.ts +3 -3
- package/template/base/{src → ts/src}/middlewares/method-not-allowed.middleware.ts +16 -17
- package/template/base/{src → ts/src}/middlewares/root.middleware.ts +2 -2
- package/template/base/{src → ts/src}/modules/v1/health/health.controller.ts +18 -18
- package/template/base/{src → ts/src}/modules/v1/health/health.route.ts +9 -9
- package/template/base/{src → ts/src}/modules/v1/health/index.ts +1 -1
- package/template/base/{src → ts/src}/modules/v1/index.ts +8 -8
- package/template/base/{src → ts/src}/routes.ts +15 -15
- package/template/base/{src → ts/src}/utils/http-error.ts +45 -45
- package/template/base/{src → ts/src}/utils/logger.ts +23 -0
- package/template/features/auth/argon2/inject.js +29 -4
- package/template/features/auth/base/inject.js +108 -26
- package/template/features/auth/bcrypt/inject.js +25 -5
- package/template/features/auth/models/user.model.js +24 -0
- package/template/features/auth/modules/auth.controller.js +21 -0
- package/template/features/auth/modules/auth.routes.js +10 -0
- package/template/features/auth/modules/auth.service.js +29 -0
- package/template/features/auth/modules/index.js +1 -0
- package/template/features/auth/utils/jwt.js +12 -0
- package/template/features/cors/inject.js +4 -1
- package/template/features/helmet/inject.js +4 -1
- package/template/features/morgan/inject.js +4 -1
- package/template/features/rate-limit/inject.js +4 -1
- package/template/gateway/js/app.js +42 -0
- package/template/gateway/js/inject.js +31 -0
- package/template/gateway/js/server.js +19 -0
- package/template/gateway/ts/app.ts +43 -0
- package/template/gateway/ts/inject.js +32 -0
- package/template/gateway/{server.ts → ts/server.ts} +3 -3
- package/template/microservice/docker/.dockerignore +10 -0
- package/template/microservice/docker/Dockerfile +2 -1
- package/template/microservice/docker/docker-compose.yml +0 -1
- package/bin/lib/ts-to-js.js +0 -342
- package/template/base/src/app.ts +0 -8
- package/template/gateway/app.ts +0 -26
- package/template/gateway/inject.js +0 -27
- /package/template/base/{.env.example → js/.env.example} +0 -0
- /package/template/base/{.husky → js/.husky}/pre-commit +0 -0
- /package/template/base/{.prettierignore → js/.prettierignore} +0 -0
- /package/template/base/{gitignore → js/gitignore} +0 -0
- /package/template/base/{.eslintrc.json → ts/.eslintrc.json} +0 -0
- /package/template/base/{.prettierrc → ts/.prettierrc} +0 -0
- /package/template/base/{eslint.config.js → ts/eslint.config.js} +0 -0
- /package/template/base/{package.json → ts/package.json} +0 -0
- /package/template/base/{src → ts/src}/config/db.ts +0 -0
- /package/template/base/{src → ts/src}/config/index.ts +0 -0
- /package/template/base/{src → ts/src}/middlewares/not-found.middleware.ts +0 -0
- /package/template/base/{src → ts/src}/modules/index.ts +0 -0
- /package/template/base/{src → ts/src}/server.ts +0 -0
- /package/template/base/{src → ts/src}/utils/index.ts +0 -0
- /package/template/base/{tsconfig.json → ts/tsconfig.json} +0 -0
package/README.md
CHANGED
|
@@ -113,18 +113,23 @@ my-backend/
|
|
|
113
113
|
```
|
|
114
114
|
my-project/
|
|
115
115
|
├── shared/ # Shared utilities across services
|
|
116
|
-
│ ├── config/ #
|
|
116
|
+
│ ├── config/ # Environment configs (db.ts only if auth enabled)
|
|
117
117
|
│ └── utils/ # Logger, error handlers
|
|
118
118
|
├── services/
|
|
119
119
|
│ ├── gateway/ # API Gateway (port 4000)
|
|
120
120
|
│ ├── health-service/ # Health checks (port 4001)
|
|
121
|
-
│ └── auth-service/ # Authentication (port 4002)
|
|
121
|
+
│ └── auth-service/ # Authentication (port 4002, if enabled)
|
|
122
122
|
├── docker-compose.yml # Docker setup (if selected)
|
|
123
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
|
|
124
127
|
├── .husky/ # Git hooks
|
|
125
128
|
└── package.json # Root package.json
|
|
126
129
|
```
|
|
127
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
|
+
|
|
128
133
|
---
|
|
129
134
|
|
|
130
135
|
## ▶️ Running the Application
|
|
@@ -194,9 +199,9 @@ pm2 stop all
|
|
|
194
199
|
|
|
195
200
|
---
|
|
196
201
|
|
|
197
|
-
##
|
|
202
|
+
## TypeScript vs JavaScript
|
|
198
203
|
|
|
199
|
-
This CLI generates **TypeScript** projects by default but
|
|
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.
|
|
200
205
|
|
|
201
206
|
### TypeScript (Default)
|
|
202
207
|
|
|
@@ -207,12 +212,10 @@ This CLI generates **TypeScript** projects by default but fully supports **JavaS
|
|
|
207
212
|
|
|
208
213
|
### JavaScript
|
|
209
214
|
|
|
210
|
-
-
|
|
211
|
-
-
|
|
212
|
-
-
|
|
213
|
-
- Same functionality
|
|
214
|
-
|
|
215
|
-
**Note**: When selecting JavaScript, the CLI transforms the TypeScript template on-the-fly, ensuring you get a production-ready JavaScript project with all the same features.
|
|
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
|
|
216
219
|
|
|
217
220
|
---
|
|
218
221
|
|
|
@@ -246,10 +249,10 @@ This CLI generates **TypeScript** projects by default but fully supports **JavaS
|
|
|
246
249
|
### Monolith
|
|
247
250
|
|
|
248
251
|
```
|
|
249
|
-
GET /
|
|
250
|
-
GET /v1/health - Health check
|
|
251
|
-
POST /v1/auth/register - Register user (if auth enabled)
|
|
252
|
-
POST /v1/auth/login - Login user (if auth enabled)
|
|
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)
|
|
253
256
|
```
|
|
254
257
|
|
|
255
258
|
### Microservice
|
|
@@ -257,22 +260,40 @@ POST /v1/auth/login - Login user (if auth enabled)
|
|
|
257
260
|
All requests go through the API Gateway at `http://localhost:4000`
|
|
258
261
|
|
|
259
262
|
```
|
|
260
|
-
GET /health
|
|
261
|
-
|
|
262
|
-
POST /auth/
|
|
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)
|
|
263
267
|
```
|
|
264
268
|
|
|
265
269
|
---
|
|
266
270
|
|
|
267
271
|
## 🔧 Environment Variables
|
|
268
272
|
|
|
269
|
-
###
|
|
273
|
+
### Monolith
|
|
270
274
|
|
|
271
275
|
```env
|
|
272
276
|
PORT=4000
|
|
273
277
|
NODE_ENV=development
|
|
274
278
|
```
|
|
275
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
|
+
|
|
276
297
|
### With CORS
|
|
277
298
|
|
|
278
299
|
```env
|