express-genix 1.1.5 → 2.0.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 (66) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +204 -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,204 @@
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
+ - Optional Redis-backed blacklist for production multi-instance deployments
19
+ - bcrypt password hashing, input sanitization (`validator`)
20
+ - Helmet, CORS, environment validation on startup
21
+ - Auto-generated cryptographically secure JWT secrets
22
+
23
+ **API & Documentation**
24
+ - Swagger UI + swagger-jsdoc annotation-based docs
25
+ - Consistent `{ success, data, meta }` response envelope
26
+ - Paginated list endpoints
27
+ - Request ID / correlation tracking
28
+
29
+ **Developer Experience**
30
+ - Interactive prompts — pick language, database, features via checkbox
31
+ - Winston or Pino logger (you choose)
32
+ - ESLint (Airbnb) + Prettier pre-configured
33
+ - Jest + Supertest with coverage
34
+ - Rate limiting with configurable window/max
35
+
36
+ **Production Ready**
37
+ - Docker & Docker Compose (multi-stage, non-root user)
38
+ - GitHub Actions CI/CD (matrix testing, DB services)
39
+ - Node.js clustering with graceful shutdown
40
+ - Rollback on generation failure
41
+ - Git init + initial commit
42
+
43
+ **Post-Init**
44
+ - `express-genix add <feature>` — bolt on auth, websocket, docker, cicd, or prisma to an existing project
45
+
46
+ ## Quick Start
47
+
48
+ ### Install globally
49
+
50
+ ```bash
51
+ npm install -g express-genix
52
+ ```
53
+
54
+ Or use with npx:
55
+
56
+ ```bash
57
+ npx express-genix init
58
+ ```
59
+
60
+ ### Create a project
61
+
62
+ ```bash
63
+ express-genix init
64
+ ```
65
+
66
+ You'll be prompted for:
67
+
68
+ 1. **Project name**
69
+ 2. **Language** — JavaScript or TypeScript
70
+ 3. **Database** — MongoDB, PostgreSQL (Sequelize), PostgreSQL (Prisma), or None
71
+ 4. **Features** Auth, Rate Limiting, Swagger, Redis Token Blacklist, Docker, CI/CD, WebSocket, Request ID
72
+ 5. **Logger** Winston or Pino
73
+
74
+ The CLI generates your project, installs dependencies, formats code, and creates an initial git commit.
75
+
76
+ ### Run it
77
+
78
+ ```bash
79
+ cd my-express-app
80
+ npm run dev
81
+ ```
82
+
83
+ - **API**: http://localhost:3000/api
84
+ - **Swagger Docs**: http://localhost:3000/api-docs
85
+ - **Health Check**: http://localhost:3000/health
86
+
87
+ ## Add features to an existing project
88
+
89
+ ```bash
90
+ cd my-express-app
91
+ express-genix add docker # Adds Dockerfile, docker-compose.yml, .dockerignore
92
+ express-genix add cicd # Adds GitHub Actions CI workflow
93
+ express-genix add auth # Adds JWT auth, controllers, routes, middleware
94
+ express-genix add websocket # Adds Socket.io setup
95
+ express-genix add prisma # Adds Prisma schema, client config, migrations
96
+ ```
97
+
98
+ ## Generated Project Structure
99
+
100
+ ```
101
+ my-express-app/
102
+ ├── src/
103
+ │ ├── config/ # Database, Swagger, WebSocket configuration
104
+ │ ├── controllers/ # Route handlers
105
+ │ ├── middleware/ # Auth, validation, error handling, request ID
106
+ │ ├── models/ # Database models (Mongoose/Sequelize)
107
+ │ ├── routes/ # API route definitions with Swagger annotations
108
+ │ ├── services/ # Business logic layer
109
+ │ ├── utils/ # Logger, errors, response helpers, validators
110
+ │ ├── app.js|ts # Express app setup
111
+ │ └── server.js|ts # Server + clustering + WebSocket
112
+ ├── tests/ # Jest + Supertest suites
113
+ ├── prisma/ # Prisma schema (if selected)
114
+ ├── migrations/ # Sequelize migrations (if PostgreSQL + Sequelize)
115
+ ├── seeders/ # Sequelize seeders (if PostgreSQL + Sequelize)
116
+ ├── .github/workflows/ # CI/CD pipeline (if selected)
117
+ ├── .env # Auto-generated environment config
118
+ ├── .env.example # Template for team sharing
119
+ ├── Dockerfile # Multi-stage Docker build (if selected)
120
+ ├── docker-compose.yml # Full stack compose (if selected)
121
+ └── package.json
122
+ ```
123
+
124
+ ## API Endpoints (with database + auth)
125
+
126
+ ### Authentication
127
+ | Method | Endpoint | Description |
128
+ |--------|----------|-------------|
129
+ | POST | `/api/auth/register` | Register a new user |
130
+ | POST | `/api/auth/login` | Login (returns access + refresh tokens) |
131
+ | POST | `/api/auth/refresh` | Refresh access token |
132
+ | POST | `/api/auth/logout` | Logout (blacklists token) |
133
+
134
+ ### Users (protected)
135
+ | Method | Endpoint | Description |
136
+ |--------|----------|-------------|
137
+ | GET | `/api/users/profile` | Get current user |
138
+ | PUT | `/api/users/profile` | Update profile |
139
+ | DELETE | `/api/users/profile` | Delete account |
140
+
141
+ ### Health
142
+ | Method | Endpoint | Description |
143
+ |--------|----------|-------------|
144
+ | GET | `/health` | Health check with uptime + DB status |
145
+
146
+ ## Available Scripts
147
+
148
+ ```bash
149
+ npm run dev # Development server with auto-reload
150
+ npm start # Production server with clustering
151
+ npm test # Run tests with coverage
152
+ npm run lint # Check ESLint
153
+ npm run lint:fix # Auto-fix ESLint issues
154
+ npm run format # Format with Prettier
155
+ npm run format:check # Verify formatting
156
+ npm run build # Compile TypeScript (TS projects only)
157
+ npm run db:migrate # Run Sequelize migrations (PostgreSQL)
158
+ npm run db:migrate:undo # Undo last migration
159
+ npm run prisma:migrate # Run Prisma migrations
160
+ npm run prisma:studio # Open Prisma Studio
161
+ ```
162
+
163
+ ## CLI Options
164
+
165
+ ```bash
166
+ express-genix init --skip-install # Skip npm install (useful for CI)
167
+ express-genix init --skip-cleanup # Skip auto-formatting (for debugging)
168
+ express-genix add <feature> # Add feature to existing project
169
+ ```
170
+
171
+ ## Environment Variables
172
+
173
+ Generated `.env` includes auto-generated JWT secrets:
174
+
175
+ | Variable | Description | Default |
176
+ |----------|-------------|---------|
177
+ | `NODE_ENV` | Environment | `development` |
178
+ | `PORT` | Server port | `3000` |
179
+ | `CORS_ORIGIN` | Allowed origins | `*` |
180
+ | `JWT_SECRET` | Access token secret (auto-generated) | — |
181
+ | `JWT_REFRESH_SECRET` | Refresh token secret (auto-generated) | — |
182
+ | `MONGO_URI` / `DATABASE_URL` | Database connection string | — |
183
+ | `REDIS_URL` | Redis URL (when Redis blacklist enabled) | `redis://localhost:6379` |
184
+ | `RATE_LIMIT_WINDOW_MS` | Rate limit window (ms) | `900000` |
185
+ | `RATE_LIMIT_MAX` | Max requests per window | `100` |
186
+ | `LOG_LEVEL` | Logging level | `info` |
187
+
188
+ ## Docker
189
+
190
+ ```bash
191
+ docker-compose up --build
192
+ ```
193
+
194
+ ## Contributing
195
+
196
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
197
+
198
+ ## License
199
+
200
+ MIT © [Joshua Maeba Nyamasege](LICENSE)
201
+
202
+ ## Changelog
203
+
204
+ See [CHANGELOG.md](CHANGELOG.md) for version history.