express-genix 1.1.5 → 2.0.1

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 (66) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +209 -209
  3. package/index.js +229 -113
  4. package/lib/cleanup.js +41 -129
  5. package/lib/features.js +239 -0
  6. package/lib/generator.js +286 -203
  7. package/lib/utils.js +43 -91
  8. package/package.json +81 -63
  9. package/templates/cicd/github-actions.yml.ejs +70 -0
  10. package/templates/config/database.mongo.js.ejs +29 -33
  11. package/templates/config/database.postgres.js.ejs +41 -40
  12. package/templates/config/database.prisma.js.ejs +26 -0
  13. package/templates/config/redis.js.ejs +28 -0
  14. package/templates/config/schema.prisma.ejs +20 -0
  15. package/templates/config/swagger.js.ejs +30 -0
  16. package/templates/config/websocket.js.ejs +62 -0
  17. package/templates/controllers/authController.js.ejs +152 -129
  18. package/templates/controllers/exampleController.js.ejs +92 -152
  19. package/templates/controllers/userController.js.ejs +52 -60
  20. package/templates/core/Dockerfile.ejs +41 -31
  21. package/templates/core/README.md.ejs +191 -179
  22. package/templates/core/app.js.ejs +114 -64
  23. package/templates/core/docker-compose.yml.ejs +59 -47
  24. package/templates/core/dockerignore.ejs +7 -0
  25. package/templates/core/env.ejs +25 -19
  26. package/templates/core/env.example.ejs +26 -0
  27. package/templates/core/eslintrc.json.ejs +50 -20
  28. package/templates/core/gitignore.ejs +51 -51
  29. package/templates/core/healthcheck.js.ejs +24 -24
  30. package/templates/core/jest.config.js.ejs +19 -22
  31. package/templates/core/package.json.ejs +70 -33
  32. package/templates/core/prettierrc.json.ejs +11 -11
  33. package/templates/core/server.js.ejs +64 -48
  34. package/templates/core/tsconfig.json.ejs +19 -0
  35. package/templates/middleware/auth.js.ejs +80 -66
  36. package/templates/middleware/cache.js.ejs +67 -0
  37. package/templates/middleware/errorHandler.js.ejs +50 -46
  38. package/templates/middleware/requestId.js.ejs +9 -0
  39. package/templates/middleware/validation.js.ejs +109 -47
  40. package/templates/migrations/create-users.js.ejs +50 -0
  41. package/templates/migrations/seed-users.js.ejs +34 -0
  42. package/templates/migrations/sequelizerc.ejs +8 -0
  43. package/templates/models/User.mongo.js.ejs +29 -29
  44. package/templates/models/User.postgres.js.ejs +40 -40
  45. package/templates/models/index.mongo.js.ejs +7 -7
  46. package/templates/models/index.postgres.js.ejs +11 -11
  47. package/templates/routes/authRoutes.js.ejs +222 -13
  48. package/templates/routes/exampleRoutes.js.ejs +100 -12
  49. package/templates/routes/index.js.ejs +34 -24
  50. package/templates/routes/userRoutes.js.ejs +78 -15
  51. package/templates/services/authService.js.ejs +111 -35
  52. package/templates/services/exampleService.js.ejs +112 -112
  53. package/templates/services/userService.mongodb.js.ejs +33 -33
  54. package/templates/services/userService.postgres.js.ejs +30 -30
  55. package/templates/services/userService.prisma.js.ejs +36 -0
  56. package/templates/tests/auth.test.js.ejs +83 -66
  57. package/templates/tests/example.test.js.ejs +109 -112
  58. package/templates/tests/setup.js.ejs +11 -11
  59. package/templates/tests/users.test.js.ejs +42 -42
  60. package/templates/utils/envValidator.js.ejs +23 -0
  61. package/templates/utils/errors.js.ejs +12 -12
  62. package/templates/utils/logger.js.ejs +37 -28
  63. package/templates/utils/response.js.ejs +28 -0
  64. package/templates/utils/validators.js.ejs +34 -34
  65. package/templates/config/swagger.json.ejs +0 -194
  66. package/templates/core/index.js.ejs +0 -24
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Joshua Maeba Nyamasege
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Joshua Maeba Nyamasege
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,209 +1,209 @@
1
- # Express-Genix
2
-
3
- A production-grade CLI tool that generates Express.js applications with a robust, scalable foundation. Get a complete REST API up and running in seconds with authentication, database integration, security, testing, and Docker support.
4
-
5
- ## Features
6
-
7
- **🚀 Three Setup Options**
8
- - **MongoDB** - Full-stack with Mongoose ORM and JWT authentication
9
- - **PostgreSQL** - Enterprise-ready with Sequelize ORM and JWT authentication
10
- - **No Database** - Perfect for microservices, proxy servers, or computational APIs
11
-
12
- **🔐 Security & Authentication**
13
- - JWT authentication with refresh tokens (database modes)
14
- - Helmet security headers
15
- - CORS configuration
16
- - Rate limiting out of the box
17
- - Password hashing with bcrypt
18
-
19
- **📚 Developer Experience**
20
- - Swagger/OpenAPI documentation
21
- - Jest testing with Supertest
22
- - ESLint (Airbnb) + Prettier pre-configured
23
- - Auto-formatted code (zero linting errors)
24
- - Structured logging
25
- - Health check endpoints
26
-
27
- **🐳 Production Ready**
28
- - Docker & Docker Compose included
29
- - Clustering support for performance
30
- - Graceful shutdown handling
31
- - Environment-based configuration
32
-
33
- ## Quick Start
34
-
35
- ### Installation
36
-
37
- ```bash
38
- npm install -g express-genix
39
- ```
40
-
41
- Or use directly with npx (no installation needed):
42
-
43
- ```bash
44
- npx express-genix init
45
- ```
46
-
47
- ### Create Your Project
48
-
49
- ```bash
50
- express-genix init
51
- ```
52
-
53
- Follow the prompts:
54
- 1. **Project name** - Choose your project name (letters, numbers, hyphens, underscores)
55
- 2. **Database** - Select MongoDB, PostgreSQL, or No Database
56
-
57
- The CLI will:
58
- - Generate your project structure
59
- - Install all dependencies
60
- - Auto-format and lint the code
61
- - Set up Docker configuration
62
-
63
- ### Run Your App
64
-
65
- ```bash
66
- cd your-project-name
67
- npm run dev
68
- ```
69
-
70
- Visit:
71
- - **API Documentation**: http://localhost:3000/api-docs
72
- - **Health Check**: http://localhost:3000/health
73
-
74
- ## Generated API Endpoints
75
-
76
- ### With Database (MongoDB/PostgreSQL)
77
-
78
- **Authentication**
79
- - `POST /api/auth/register` - Register new user
80
- - `POST /api/auth/login` - User login
81
- - `POST /api/auth/refresh` - Refresh access token
82
- - `POST /api/auth/logout` - User logout
83
-
84
- **User Management** (Protected)
85
- - `GET /api/users/profile` - Get user profile
86
- - `PUT /api/users/profile` - Update user profile
87
- - `DELETE /api/users/profile` - Delete user account
88
-
89
- ### Without Database
90
-
91
- **Example API** (In-memory CRUD)
92
- - `GET /api/examples` - List all examples (with pagination)
93
- - `GET /api/examples/:id` - Get example by ID
94
- - `POST /api/examples` - Create new example
95
- - `PUT /api/examples/:id` - Update example
96
- - `DELETE /api/examples/:id` - Delete example
97
-
98
- ## Available Scripts
99
-
100
- ```bash
101
- npm run dev # Development server with hot reload
102
- npm start # Production server with clustering
103
- npm test # Run tests with coverage
104
- npm run lint # Check code quality
105
- npm run lint:fix # Auto-fix linting issues
106
- npm run format # Format code with Prettier
107
- npm run format:check # Verify code formatting
108
- ```
109
-
110
- ## Project Structure
111
-
112
- ```
113
- your-project/
114
- ├── src/
115
- ├── config/ # Database and Swagger config
116
- ├── controllers/ # Request handlers
117
- ├── middleware/ # Auth, validation, errors
118
- ├── models/ # Database models (if enabled)
119
- ├── routes/ # API routes
120
- ├── services/ # Business logic
121
- ├── utils/ # Helper functions
122
- ├── app.js # Express setup
123
- │ └── server.js # Server entry point
124
- ├── tests/ # Test suites
125
- ├── .env # Environment variables
126
- ├── Dockerfile # Container config
127
- └── docker-compose.yml # Multi-container setup
128
- ```
129
-
130
- ## Environment Variables
131
-
132
- Create a `.env` file (generated automatically):
133
-
134
- ```bash
135
- # Server
136
- NODE_ENV=development
137
- PORT=3000
138
-
139
- # Database (if using MongoDB/PostgreSQL)
140
- MONGO_URI=mongodb://localhost:27017/myapp
141
- # or
142
- DATABASE_URL=postgresql://user:password@localhost:5432/myapp
143
-
144
- # JWT (if using database)
145
- JWT_SECRET=your-secret-key
146
- JWT_REFRESH_SECRET=your-refresh-secret
147
- JWT_EXPIRE=15m
148
- JWT_REFRESH_EXPIRE=7d
149
-
150
- # Rate Limiting
151
- RATE_LIMIT_WINDOW_MS=900000
152
- RATE_LIMIT_MAX=100
153
- ```
154
-
155
- ## Docker Deployment
156
-
157
- The generated project includes Docker support:
158
-
159
- ```bash
160
- # Build and run with Docker Compose
161
- docker-compose up
162
-
163
- # Or build manually
164
- docker build -t my-app .
165
- docker run -p 3000:3000 --env-file .env my-app
166
- ```
167
-
168
- ## Troubleshooting
169
-
170
- **Database Connection Issues**
171
- - Ensure MongoDB/PostgreSQL is running
172
- - Check connection string in `.env`
173
- - Verify database credentials
174
-
175
- **Dependency Errors**
176
- ```bash
177
- npm cache clean --force
178
- rm -rf node_modules package-lock.json
179
- npm install
180
- ```
181
-
182
- **Port Already in Use**
183
- ```bash
184
- # Change port in .env
185
- PORT=3001
186
- ```
187
-
188
- ## CLI Options
189
-
190
- ```bash
191
- express-genix init --skip-cleanup # Skip auto-formatting (for debugging)
192
- ```
193
-
194
- ## Contributing
195
-
196
- Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
197
-
198
- ## Support
199
-
200
- - **Issues**: [GitHub Issues](https://github.com/yourusername/express-genix/issues)
201
- - **Documentation**: [Full Docs](https://github.com/yourusername/express-genix)
202
-
203
- ## License
204
-
205
- MIT © [Joshua Maeba Nyamasege](LICENSE)
206
-
207
- ## Changelog
208
-
209
- See [CHANGELOG.md](CHANGELOG.md) for version history and release notes.
1
+ # Express-Genix
2
+
3
+ A production-grade CLI tool that generates Express.js applications with best-in-class defaults. Scaffold a complete REST API in seconds with TypeScript, authentication, Prisma/Mongoose/Sequelize, Docker, CI/CD, and more.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/express-genix.svg)](https://www.npmjs.com/package/express-genix)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg)](https://nodejs.org)
8
+
9
+ ## Features
10
+
11
+ **Languages & ORMs**
12
+ - JavaScript or TypeScript
13
+ - MongoDB (Mongoose), PostgreSQL (Sequelize), PostgreSQL (Prisma), or no database
14
+ - Sequelize CLI migrations for PostgreSQL, Prisma migrations ready out of the box
15
+
16
+ **Security & Auth**
17
+ - JWT access + refresh tokens with token blacklist logout
18
+ - Password reset flow (forgot-password / reset-password with crypto tokens)
19
+ - Optional Redis-backed blacklist for production multi-instance deployments
20
+ - Zod request validation with pre-built schemas (register, login, reset, etc.)
21
+ - bcrypt password hashing, input sanitization (`validator`)
22
+ - Helmet, CORS, environment validation on startup
23
+ - Auto-generated cryptographically secure JWT secrets
24
+
25
+ **API & Documentation**
26
+ - Swagger UI + swagger-jsdoc annotation-based docs with example request/response bodies
27
+ - Consistent `{ success, data, meta }` response envelope
28
+ - Paginated list endpoints
29
+ - Request ID / correlation tracking
30
+ - Response caching middleware (Redis-backed, configurable TTL)
31
+
32
+ **Developer Experience**
33
+ - Interactive prompts — pick language, database, features via checkbox
34
+ - Winston or Pino logger (you choose)
35
+ - ESLint (Airbnb) + Prettier pre-configured
36
+ - Jest + Supertest with coverage
37
+ - Rate limiting with configurable window/max
38
+
39
+ **Production Ready**
40
+ - Docker & Docker Compose (multi-stage, non-root user)
41
+ - GitHub Actions CI/CD (matrix testing, DB services)
42
+ - Node.js clustering with graceful shutdown
43
+ - Rollback on generation failure
44
+ - Git init + initial commit
45
+
46
+ **Post-Init**
47
+ - `express-genix add <feature>` — bolt on auth, websocket, docker, cicd, or prisma to an existing project
48
+
49
+ ## Quick Start
50
+
51
+ ### Install globally
52
+
53
+ ```bash
54
+ npm install -g express-genix
55
+ ```
56
+
57
+ Or use with npx:
58
+
59
+ ```bash
60
+ npx express-genix init
61
+ ```
62
+
63
+ ### Create a project
64
+
65
+ ```bash
66
+ express-genix init
67
+ ```
68
+
69
+ You'll be prompted for:
70
+
71
+ 1. **Project name**
72
+ 2. **Language** JavaScript or TypeScript
73
+ 3. **Database** — MongoDB, PostgreSQL (Sequelize), PostgreSQL (Prisma), or None
74
+ 4. **Features** Auth, Rate Limiting, Swagger, Redis Token Blacklist, Docker, CI/CD, WebSocket, Request ID
75
+ 5. **Logger** — Winston or Pino
76
+
77
+ The CLI generates your project, installs dependencies, formats code, and creates an initial git commit.
78
+
79
+ ### Run it
80
+
81
+ ```bash
82
+ cd my-express-app
83
+ npm run dev
84
+ ```
85
+
86
+ - **API**: http://localhost:3000/api
87
+ - **Swagger Docs**: http://localhost:3000/api-docs
88
+ - **Health Check**: http://localhost:3000/health
89
+
90
+ ## Add features to an existing project
91
+
92
+ ```bash
93
+ cd my-express-app
94
+ express-genix add docker # Adds Dockerfile, docker-compose.yml, .dockerignore
95
+ express-genix add cicd # Adds GitHub Actions CI workflow
96
+ express-genix add auth # Adds JWT auth, controllers, routes, middleware
97
+ express-genix add websocket # Adds Socket.io setup
98
+ express-genix add prisma # Adds Prisma schema, client config, migrations
99
+ ```
100
+
101
+ ## Generated Project Structure
102
+
103
+ ```
104
+ my-express-app/
105
+ ├── src/
106
+ │ ├── config/ # Database, Swagger, WebSocket configuration
107
+ │ ├── controllers/ # Route handlers
108
+ │ ├── middleware/ # Auth, validation, error handling, request ID
109
+ │ ├── models/ # Database models (Mongoose/Sequelize)
110
+ │ ├── routes/ # API route definitions with Swagger annotations
111
+ │ ├── services/ # Business logic layer
112
+ │ ├── utils/ # Logger, errors, response helpers, validators
113
+ │ ├── app.js|ts # Express app setup
114
+ │ └── server.js|ts # Server + clustering + WebSocket
115
+ ├── tests/ # Jest + Supertest suites
116
+ ├── prisma/ # Prisma schema (if selected)
117
+ ├── migrations/ # Sequelize migrations (if PostgreSQL + Sequelize)
118
+ ├── seeders/ # Sequelize seeders (if PostgreSQL + Sequelize)
119
+ ├── .github/workflows/ # CI/CD pipeline (if selected)
120
+ ├── .env # Auto-generated environment config
121
+ ├── .env.example # Template for team sharing
122
+ ├── Dockerfile # Multi-stage Docker build (if selected)
123
+ ├── docker-compose.yml # Full stack compose (if selected)
124
+ └── package.json
125
+ ```
126
+
127
+ ## API Endpoints (with database + auth)
128
+
129
+ ### Authentication
130
+ | Method | Endpoint | Description |
131
+ |--------|----------|-------------|
132
+ | POST | `/api/auth/register` | Register a new user |
133
+ | POST | `/api/auth/login` | Login (returns access + refresh tokens) |
134
+ | POST | `/api/auth/refresh` | Refresh access token |
135
+ | POST | `/api/auth/logout` | Logout (blacklists token) |
136
+ | POST | `/api/auth/forgot-password` | Request password reset email |
137
+ | POST | `/api/auth/reset-password` | Reset password with token |
138
+
139
+ ### Users (protected)
140
+ | Method | Endpoint | Description |
141
+ |--------|----------|-------------|
142
+ | GET | `/api/users/profile` | Get current user |
143
+ | PUT | `/api/users/profile` | Update profile |
144
+ | DELETE | `/api/users/profile` | Delete account |
145
+
146
+ ### Health
147
+ | Method | Endpoint | Description |
148
+ |--------|----------|-------------|
149
+ | GET | `/health` | Health check with uptime, DB status, Redis status, memory usage |
150
+
151
+ ## Available Scripts
152
+
153
+ ```bash
154
+ npm run dev # Development server with auto-reload
155
+ npm start # Production server with clustering
156
+ npm test # Run tests with coverage
157
+ npm run lint # Check ESLint
158
+ npm run lint:fix # Auto-fix ESLint issues
159
+ npm run format # Format with Prettier
160
+ npm run format:check # Verify formatting
161
+ npm run build # Compile TypeScript (TS projects only)
162
+ npm run db:migrate # Run Sequelize migrations (PostgreSQL)
163
+ npm run db:migrate:undo # Undo last migration
164
+ npm run prisma:migrate # Run Prisma migrations
165
+ npm run prisma:studio # Open Prisma Studio
166
+ ```
167
+
168
+ ## CLI Options
169
+
170
+ ```bash
171
+ express-genix init --skip-install # Skip npm install (useful for CI)
172
+ express-genix init --skip-cleanup # Skip auto-formatting (for debugging)
173
+ express-genix add <feature> # Add feature to existing project
174
+ ```
175
+
176
+ ## Environment Variables
177
+
178
+ Generated `.env` includes auto-generated JWT secrets:
179
+
180
+ | Variable | Description | Default |
181
+ |----------|-------------|---------|
182
+ | `NODE_ENV` | Environment | `development` |
183
+ | `PORT` | Server port | `3000` |
184
+ | `CORS_ORIGIN` | Allowed origins | `*` |
185
+ | `JWT_SECRET` | Access token secret (auto-generated) | — |
186
+ | `JWT_REFRESH_SECRET` | Refresh token secret (auto-generated) | — |
187
+ | `MONGO_URI` / `DATABASE_URL` | Database connection string | — |
188
+ | `REDIS_URL` | Redis URL (when Redis blacklist enabled) | `redis://localhost:6379` |
189
+ | `RATE_LIMIT_WINDOW_MS` | Rate limit window (ms) | `900000` |
190
+ | `RATE_LIMIT_MAX` | Max requests per window | `100` |
191
+ | `LOG_LEVEL` | Logging level | `info` |
192
+
193
+ ## Docker
194
+
195
+ ```bash
196
+ docker-compose up --build
197
+ ```
198
+
199
+ ## Contributing
200
+
201
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
202
+
203
+ ## License
204
+
205
+ MIT © [Joshua Maeba Nyamasege](LICENSE)
206
+
207
+ ## Changelog
208
+
209
+ See [CHANGELOG.md](CHANGELOG.md) for version history.