speedrun-cli 2.7.10 → 2.7.15
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/CHANGELOG.md +38 -0
- package/README.md +128 -491
- package/package.json +1 -1
- package/src/fieldManager.js +338 -191
- package/src/moduleGenerator.js +72 -15
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# 🚀 speedrun-cli
|
|
4
|
+
|
|
5
|
+
> **📖 Looking for full interactive flows, input/output terminal sessions, and generated code examples?**
|
|
6
|
+
> Check out the complete [**USAGE.md (Command & Interactive Flow Guide)**](./USAGE.md).
|
|
4
7
|
|
|
5
8
|
### The Zero-Config Way to Build Secure Authentication & CRUD APIs
|
|
6
9
|
|
|
@@ -17,22 +20,72 @@ Get a battle-tested, production-ready NestJS auth system and Swagger-documented
|
|
|
17
20
|
[](CONTRIBUTING.md)
|
|
18
21
|
|
|
19
22
|
```bash
|
|
20
|
-
npx
|
|
23
|
+
npx speedrun-cli create my-app
|
|
21
24
|
```
|
|
22
25
|
|
|
23
|
-
[Quick Start](#quick-start) | [
|
|
26
|
+
[Quick Start](#getting-started--quick-start) | [Commands](#cli-command-quick-reference) | [Features](#core-feature-highlights) | [Usage Guide](./USAGE.md)
|
|
24
27
|
|
|
25
28
|
---
|
|
26
29
|
|
|
27
|
-
**v2.
|
|
30
|
+
**v2.7.14** | **Interactive Module Generator** | **Field Manager** | **4 ORMs** | **4 Databases**
|
|
28
31
|
|
|
29
32
|
</div>
|
|
30
33
|
|
|
31
34
|
---
|
|
32
35
|
|
|
33
|
-
##
|
|
36
|
+
## 🌟 Core Feature Highlights
|
|
37
|
+
|
|
38
|
+
* ⚡ **Instant NestJS Boilerplate Scaffolding:** Choose your ORM (Prisma, TypeORM, Mongoose, Drizzle) and Database (PostgreSQL, MySQL, SQLite, MongoDB).
|
|
39
|
+
* 🔑 **Custom Primary Key Naming:** Choose between `id`, `snake_case` (`order_id`), `camelCase` (`orderId`), or custom PK formats synced seamlessly across ORM schemas, DTOs, response models, and Controller `@Param()` annotations.
|
|
40
|
+
* 🔤 **ORM-Native Field Types:** The field builder dynamically tailors field type options based on the detected ORM (e.g., Prisma `Int`/`Float`/`DateTime`, TypeORM `decimal`/`timestamp`, Drizzle `numeric`) and applies matching TypeScript types and `class-validator` rules.
|
|
41
|
+
* 🔐 **Auth & Role Guard Injection:** Protect write operations (`POST`, `PUT`, `DELETE`) automatically with pre-configured `@UseGuards(JwtAuthGuard, RolesGuard)` and `@Roles('ADMIN', 'SUPERADMIN')` decorators.
|
|
42
|
+
* 🔗 **Relationship Builder:** Add `Many-to-One` or `One-to-Many` relationships to other modules directly from the terminal with automatic foreign key wiring.
|
|
43
|
+
* ✏️ **Sub-Menu Interactive Field Manager (`speedrun-cli field` / `f`):** Modify existing generated modules on the fly. Selectively edit specific field attributes (Name, Type, or Optional status), add new fields, or delete fields with automated DTO and ORM schema re-sync.
|
|
44
|
+
* 🏗️ **Automated Base Architecture:** Ensures `src/common/base` (`BaseController`, `BaseService`, and Swagger helpers) exists to eliminate missing import compilation errors (`TS2307`/`TS4112`).
|
|
45
|
+
* 🔄 **Auto AppModule Registration:** Automatically injects generated modules into `src/app.module.ts`.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 📌 CLI Command Quick Reference
|
|
50
|
+
|
|
51
|
+
| Command | Alias | Description |
|
|
52
|
+
| --- | --- | --- |
|
|
53
|
+
| `speedrun-cli create [app-name]` | *(default)* | Scaffolds a new production-ready NestJS Auth project. |
|
|
54
|
+
| `speedrun-cli generate [module]` | `g` | Generates a new CRUD module with PKs, fields, ORM sync, and Auth Guards. |
|
|
55
|
+
| `speedrun-cli field [module]` | `f` | Interactive Field Manager to Add, Edit (sub-menu), or Delete fields on existing modules. |
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 🚀 Getting Started & Quick Start
|
|
60
|
+
|
|
61
|
+
### 1. Scaffold a New Project
|
|
62
|
+
```bash
|
|
63
|
+
# Interactive setup: choose ORM, Database, Swagger, Base CRUD & Package Manager
|
|
64
|
+
npx speedrun-cli create my-awesome-api
|
|
34
65
|
|
|
35
|
-
|
|
66
|
+
# Or use non-interactive mode with default options
|
|
67
|
+
npx speedrun-cli create my-awesome-api --yes
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 2. Generate a New CRUD Module
|
|
71
|
+
```bash
|
|
72
|
+
cd my-awesome-api
|
|
73
|
+
|
|
74
|
+
# Interactively generate a module with custom PK, fields, relations & guards
|
|
75
|
+
npx speedrun-cli g orders
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. Modify Fields of an Existing Module
|
|
79
|
+
```bash
|
|
80
|
+
# Manage fields: Add new field, Edit field (via sub-menu), or Delete field
|
|
81
|
+
npx speedrun-cli f orders
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 💡 Why This Exists
|
|
87
|
+
|
|
88
|
+
Building secure JWT authentication and standard CRUD operations from scratch usually takes **34-46 hours**. You need:
|
|
36
89
|
- Access tokens + refresh token rotation
|
|
37
90
|
- HttpOnly cookies (not localStorage)
|
|
38
91
|
- Multi-device session management
|
|
@@ -44,92 +97,66 @@ Building secure JWT authentication and standard CRUD operations isn't trivial. Y
|
|
|
44
97
|
- **Consistent, secure CRUD boilerplate with strict validation**
|
|
45
98
|
- **Automated API Documentation (Swagger)**
|
|
46
99
|
|
|
47
|
-
|
|
100
|
+
**`speedrun-cli` gives you all of that in under 3 minutes.**
|
|
48
101
|
|
|
49
102
|
<div align="center">
|
|
50
103
|
|
|
51
|
-
###
|
|
104
|
+
### Time Savings Matrix
|
|
52
105
|
|
|
53
|
-
| Task |
|
|
54
|
-
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
| Rate limiting | 2-3 hours | Medium |
|
|
59
|
-
| Security hardening | 8-10 hours | Very High |
|
|
60
|
-
| Base CRUD & Swagger setup | 5-7 hours | Medium |
|
|
61
|
-
| Testing & debugging | 6-8 hours | High |
|
|
62
|
-
| **Total** | **34-46 hours** | **** |
|
|
106
|
+
| Task | From Scratch | With `speedrun-cli` |
|
|
107
|
+
|------|---------------|-------------------|
|
|
108
|
+
| Project Scaffolding & Auth | 34-46 hours | **3 minutes** |
|
|
109
|
+
| Module Generation & Schema Sync | 4-6 hours | **10 seconds** |
|
|
110
|
+
| Field Editing & Migration | 2-3 hours | **5 seconds** |
|
|
63
111
|
|
|
64
|
-
|
|
112
|
+
</div>
|
|
65
113
|
|
|
66
|
-
|
|
67
|
-
|------|---------------|------------|
|
|
68
|
-
| Run one command | 3 minutes | **Zero** |
|
|
69
|
-
| Generate new modules | 10 seconds | **Zero** |
|
|
70
|
-
| **Total** | **~3 minutes** | **** |
|
|
114
|
+
---
|
|
71
115
|
|
|
72
|
-
|
|
116
|
+
## ⚙️ How It Works Behind the Scenes
|
|
73
117
|
|
|
74
|
-
|
|
118
|
+
`speedrun-cli` isn't just a simple template copier — it's an intelligent code generation engine that dynamically compiles ORM schemas, NestJS DTOs, Controllers, and Services based on interactive inputs.
|
|
75
119
|
|
|
76
|
-
|
|
120
|
+
```mermaid
|
|
121
|
+
graph TD
|
|
122
|
+
A[npx speedrun-cli create / g / f] --> B[1. Prompt Engine & Package Manager Detection]
|
|
123
|
+
B --> C[2. Template Fusion & Base Architecture Scaffolding]
|
|
124
|
+
C --> D[3. ORM Schema & Entity Synchronization]
|
|
125
|
+
D --> E[4. Type-Safe DTO & Swagger Schema Generator]
|
|
126
|
+
E --> F[5. Controller & Service Code Compilation]
|
|
127
|
+
F --> G[6. Auto AppModule Registration & DB Migration/Seed]
|
|
128
|
+
|
|
129
|
+
style A fill:#667eea,color:#fff
|
|
130
|
+
style G fill:#48bb78,color:#fff
|
|
131
|
+
```
|
|
77
132
|
|
|
78
|
-
|
|
133
|
+
### 1. Template Fusion & Base Architecture (`src/generator.js`)
|
|
134
|
+
When running `create`, the CLI dynamically merges modular template layers based on your chosen ORM (`Prisma`, `TypeORM`, `Drizzle`, `Mongoose`) and Database (`PostgreSQL`, `MySQL`, `SQLite`, `MongoDB`). It automatically injects the `src/common/base` architecture containing abstract `BaseController`, `BaseService`, and Swagger response wrappers.
|
|
79
135
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
# Project name
|
|
86
|
-
# ORM (Prisma, Drizzle, TypeORM, or Mongoose)
|
|
87
|
-
# Database (PostgreSQL, MySQL, SQLite, or MongoDB)
|
|
88
|
-
# Enable Base CRUD Architecture? (Yes/No)
|
|
89
|
-
# Package manager
|
|
90
|
-
# Install dependencies
|
|
91
|
-
# Setup database
|
|
92
|
-
# Initialize git
|
|
93
|
-
|
|
94
|
-
# Done! Your API is running at http://localhost:8080/api/v1
|
|
95
|
-
# Swagger UI is available at http://localhost:8080/api/docs
|
|
96
|
-
```
|
|
136
|
+
### 2. Custom Primary Key & ORM Schema Sync (`src/moduleGenerator.js`)
|
|
137
|
+
When generating a module (`speedrun-cli g [module]`), your primary key selection (`id`, `order_id`, `orderId`, etc.) is bound across the entire stack:
|
|
138
|
+
- **Database Layer:** Marks the custom primary key column in Prisma (`@id`), TypeORM (`@PrimaryGeneratedColumn`), Drizzle (`primaryKey()`), or Mongoose (`@Prop`).
|
|
139
|
+
- **Service Layer:** Binds database query filters (`where: { order_id }`) for all CRUD methods.
|
|
140
|
+
- **Controller Layer:** Generates route params `@Param('order_id', ParseUUIDPipe)` matching OpenAPI `@ApiParam()` documentation.
|
|
97
141
|
|
|
98
|
-
|
|
99
|
-
|
|
142
|
+
### 3. ORM-Native Type Mapping & DTO Compilation
|
|
143
|
+
Field types selected in the interactive prompt (`Int`, `Float`, `Decimal`, `DateTime`, `varchar`, `timestamp`, `numeric`) are automatically converted into:
|
|
144
|
+
- **TypeScript Types:** `string`, `number`, `boolean`, `Date`, `object`.
|
|
145
|
+
- **Validation Rules:** `@IsString()`, `@IsInt()`, `@IsNumber()`, `@IsBoolean()`, `@IsDate()`, `@Type(() => Date)`.
|
|
146
|
+
- **Swagger Documentation:** `@ApiProperty()` / `@ApiPropertyOptional()` metadata with realistic example values.
|
|
100
147
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
? What is your project name? my-awesome-api
|
|
105
|
-
? Which ORM would you like to use? Prisma
|
|
106
|
-
? Which database would you like to use? PostgreSQL
|
|
107
|
-
? Enable Base CRUD Architecture? Yes
|
|
108
|
-
? Which package manager? pnpm (detected)
|
|
109
|
-
? Install dependencies? Yes
|
|
110
|
-
? Initialize git repository? Yes
|
|
111
|
-
|
|
112
|
-
Creating my-awesome-api...
|
|
113
|
-
Installing dependencies...
|
|
114
|
-
Success! Created my-awesome-api
|
|
115
|
-
|
|
116
|
-
? Complete setup now? Yes
|
|
117
|
-
Generating JWT secrets...
|
|
118
|
-
? Enter PostgreSQL URL: postgresql://localhost:5432/mydb
|
|
119
|
-
? Set up database now? Yes
|
|
120
|
-
Running migrations & seed...
|
|
121
|
-
Default admin: admin@example.com / Admin@123
|
|
122
|
-
|
|
123
|
-
? Start dev server? Yes
|
|
124
|
-
Server running at http://localhost:8080/api/v1
|
|
125
|
-
Swagger UI at http://localhost:8080/api/docs
|
|
126
|
-
```
|
|
148
|
+
### 4. Automatic `AppModule` Injection
|
|
149
|
+
The CLI parses `src/app.module.ts` using static analysis, adding the new module's import statement at the top and registering it inside `@Module({ imports: [...] })` so your API routes are active instantly.
|
|
127
150
|
|
|
128
|
-
|
|
151
|
+
### 5. Interactive Field Manager Engine (`src/fieldManager.js`)
|
|
152
|
+
When managing fields on an existing module (`speedrun-cli f [module]`):
|
|
153
|
+
- **Parser Engine:** Reads `create-[module].dto.ts` and decodes `class-validator` decorators to accurately reconstruct existing fields and ORM types without precision loss.
|
|
154
|
+
- **Sub-Menu Property Editor:** Allows isolated changes to field name, field type, or optional status without touching adjacent properties.
|
|
155
|
+
- **Re-Sync Engine:** Updates all 3 DTOs (`create`, `update`, `response`), updates the ORM model definition in-place, and prompts to trigger immediate database migration and seeding.
|
|
129
156
|
|
|
130
157
|
---
|
|
131
158
|
|
|
132
|
-
## What You Get
|
|
159
|
+
## 🛡️ What You Get
|
|
133
160
|
|
|
134
161
|
<table>
|
|
135
162
|
<tr>
|
|
@@ -143,7 +170,7 @@ create-nestjs-auth-swagger
|
|
|
143
170
|
- **Rate Limiting** - 5 auth attempts/min
|
|
144
171
|
- **PII-Safe Logs** - Passwords/tokens auto-redacted
|
|
145
172
|
- **Mass Assignment Protection** - `ValidationPipe` with `whitelist: true` & `forbidNonWhitelisted: true`
|
|
146
|
-
- **Strict Parameter Parsing** - `@ParseUUIDPipe`
|
|
173
|
+
- **Strict Parameter Parsing** - `@ParseUUIDPipe` on ID parameters
|
|
147
174
|
|
|
148
175
|
</td>
|
|
149
176
|
<td width="50%">
|
|
@@ -151,11 +178,11 @@ create-nestjs-auth-swagger
|
|
|
151
178
|
### Developer Experience
|
|
152
179
|
|
|
153
180
|
- **Interactive Module Generator** - Scaffold CRUD in seconds
|
|
181
|
+
- **Sub-Menu Field Manager** - Modify fields safely anytime
|
|
154
182
|
- **Auto-Generated Swagger Docs** - Out-of-the-box UI at `/api/docs`
|
|
155
|
-
- **TypeScript** - Full type safety
|
|
156
183
|
- **Base CRUD Architecture** - Abstract `BaseService` & `BaseController`
|
|
157
|
-
- **
|
|
158
|
-
- **Prisma Studio** - Visual database UI
|
|
184
|
+
- **TypeScript** - 100% type safety across DTOs and ORM schemas
|
|
185
|
+
- **Prisma Studio** - Visual database UI support
|
|
159
186
|
|
|
160
187
|
</td>
|
|
161
188
|
</tr>
|
|
@@ -164,12 +191,12 @@ create-nestjs-auth-swagger
|
|
|
164
191
|
|
|
165
192
|
### Production-Ready
|
|
166
193
|
|
|
167
|
-
- **RBAC in
|
|
194
|
+
- **RBAC in 1 Line** - `@Roles('ADMIN', 'SUPERADMIN')`
|
|
168
195
|
- **Multi-Device Sessions** - Track 5 devices/user
|
|
169
196
|
- **Structured Logging** - Pino JSON logs
|
|
170
|
-
- **Input Validation** -
|
|
197
|
+
- **Input Validation** - class-validator + class-transformer
|
|
171
198
|
- **CORS & Helmet** - Security headers included
|
|
172
|
-
- **Global Error Handling** - Handled `NotFoundException`
|
|
199
|
+
- **Global Error Handling** - Handled `NotFoundException` & Soft-Deletes
|
|
173
200
|
|
|
174
201
|
</td>
|
|
175
202
|
<td width="50%">
|
|
@@ -179,311 +206,15 @@ create-nestjs-auth-swagger
|
|
|
179
206
|
- **4 ORMs** - Prisma, Drizzle, TypeORM, Mongoose
|
|
180
207
|
- **4 Databases** - PostgreSQL, MySQL, SQLite, MongoDB
|
|
181
208
|
- **Type-Safe** - Full TypeScript support across all ORMs
|
|
182
|
-
- **Migrations** -
|
|
183
|
-
- **Seeding** - Default admin user included
|
|
209
|
+
- **Migrations & Seeds** - Automated schema push/migration and table seeding
|
|
184
210
|
|
|
185
211
|
</td>
|
|
186
212
|
</tr>
|
|
187
|
-
</table>
|
|
213
|
+
</table>
|
|
188
214
|
|
|
189
215
|
---
|
|
190
216
|
|
|
191
|
-
##
|
|
192
|
-
|
|
193
|
-
Add new CRUD modules dynamically to your running project anytime using the `generate` (or `g`) sub-command!
|
|
194
|
-
|
|
195
|
-
```bash
|
|
196
|
-
# Inside your project directory
|
|
197
|
-
npx @astralicc/create-nestjs-auth-swagger g [module-name]
|
|
198
|
-
# OR
|
|
199
|
-
npx @astralicc/create-nestjs-auth-swagger generate [module-name]
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### Interactive Prompts
|
|
203
|
-
1. **Module Name:** If not provided via CLI args, you'll be prompted: `"What module do you want to generate?"`
|
|
204
|
-
2. **CRUD Mode Selection:**
|
|
205
|
-
- `Full CRUD (Create, Read All, Read One, Update, Delete)`
|
|
206
|
-
- `Custom Selection...`
|
|
207
|
-
3. **Cherry-Pick Operations:** If you select "Custom Selection", you can use a multiselect checkbox to pick exactly what you need (e.g., just `Create` and `Read All`).
|
|
208
|
-
|
|
209
|
-
### Auto-Generated Files & Swagger Integration
|
|
210
|
-
The generator intelligently creates ORM-aware files for your module, fully wired with Swagger decorators:
|
|
211
|
-
- `module-name.controller.ts` (Decorated with `@ApiTags`, `@ApiOperation`, `@ApiResponse`, etc.)
|
|
212
|
-
- `module-name.service.ts` (Uses the correct Repository implementation based on your active ORM)
|
|
213
|
-
- `module-name.module.ts`
|
|
214
|
-
- `dto/create-module-name.dto.ts` & `update-module-name.dto.ts`
|
|
215
|
-
- `dto/module-name.dto.ts` (With `@ApiProperty` decorators for Swagger schemas)
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
## Base CRUD Architecture & Security-Safe Features
|
|
220
|
-
|
|
221
|
-
During initial setup, if you select **"Enable Base CRUD Architecture? (Y/n)"**, your project is scaffolded with a robust, abstract generic base for controllers and services.
|
|
222
|
-
|
|
223
|
-
- **`BaseService` & `BaseController`**: Extensible classes that handle standard operations.
|
|
224
|
-
- **Security-First**:
|
|
225
|
-
- Protects against Mass Assignment via strict `ValidationPipe` settings (`whitelist: true`, `forbidNonWhitelisted: true`).
|
|
226
|
-
- Ensures valid inputs via strict parameter parsing (e.g., `@ParseUUIDPipe`).
|
|
227
|
-
- **Resilient**: Built-in Soft-delete support and global `NotFoundException` handling.
|
|
228
|
-
|
|
229
|
-
---
|
|
230
|
-
|
|
231
|
-
## Auto-Generated Swagger Docs (@nestjs/swagger)
|
|
232
|
-
|
|
233
|
-
Say goodbye to manual API documentation!
|
|
234
|
-
|
|
235
|
-
- **Swagger UI** is enabled out-of-the-box and accessible at `/api/docs`.
|
|
236
|
-
- Every route scaffolded by the initial CLI setup or the `g` sub-command comes pre-configured with `@nestjs/swagger` decorators.
|
|
237
|
-
- DTOs automatically generate OpenAPI schemas using `@ApiProperty` and `@ApiPropertyOptional`.
|
|
238
|
-
- Endpoint descriptions, expected parameters, and HTTP response codes are fully documented instantly.
|
|
239
|
-
|
|
240
|
-
---
|
|
241
|
-
|
|
242
|
-
## See It in Action
|
|
243
|
-
|
|
244
|
-
### 60-Second Complete Setup
|
|
245
|
-
|
|
246
|
-
```bash
|
|
247
|
-
# 1. Create project (10 seconds)
|
|
248
|
-
npx @astralicc/create-nestjs-auth-swagger@latest my-api
|
|
249
|
-
|
|
250
|
-
# 2. Answer prompts (20 seconds)
|
|
251
|
-
# Project name: my-api
|
|
252
|
-
# ORM: Prisma (or Drizzle, TypeORM, Mongoose)
|
|
253
|
-
# Database: PostgreSQL (or MySQL, SQLite, MongoDB)
|
|
254
|
-
# Enable Base CRUD: Yes
|
|
255
|
-
# Package manager: pnpm
|
|
256
|
-
# Install dependencies: Yes
|
|
257
|
-
# Database URL: postgresql://localhost:5432/mydb
|
|
258
|
-
# Setup database: Yes
|
|
259
|
-
# Start server: Yes
|
|
260
|
-
|
|
261
|
-
# 3. Your API is live! (30 seconds)
|
|
262
|
-
# http://localhost:8080/api/v1
|
|
263
|
-
# http://localhost:8080/api/docs (Swagger UI)
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
### Live Example
|
|
267
|
-
|
|
268
|
-
```bash
|
|
269
|
-
# Login
|
|
270
|
-
curl -X POST http://localhost:8080/api/v1/auth/login \
|
|
271
|
-
-H "Content-Type: application/json" \
|
|
272
|
-
-c cookies.txt \
|
|
273
|
-
-d '{"email":"admin@example.com","password":"Admin@123"}'
|
|
274
|
-
|
|
275
|
-
# Access protected route
|
|
276
|
-
curl http://localhost:8080/api/v1/auth/me -b cookies.txt
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
### What the Code Looks Like
|
|
280
|
-
|
|
281
|
-
**Adding a protected admin endpoint** (2 lines):
|
|
282
|
-
|
|
283
|
-
```typescript
|
|
284
|
-
@Roles(UserRole.ADMIN) // Just add this decorator
|
|
285
|
-
@Delete('posts/:id')
|
|
286
|
-
deletePost() {
|
|
287
|
-
return { message: 'Deleted' };
|
|
288
|
-
}
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
**Getting the current user** (1 line):
|
|
292
|
-
|
|
293
|
-
```typescript
|
|
294
|
-
@Get('my-profile')
|
|
295
|
-
getProfile(@GetUser() user) { // User automatically injected
|
|
296
|
-
return { profile: user };
|
|
297
|
-
}
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
**Making an endpoint public** (1 line):
|
|
301
|
-
|
|
302
|
-
```typescript
|
|
303
|
-
@Public() // Skip authentication
|
|
304
|
-
@Get('posts')
|
|
305
|
-
findAll() {
|
|
306
|
-
return { posts: [] };
|
|
307
|
-
}
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
That's it. No boilerplate. No configuration. Just decorators.
|
|
311
|
-
|
|
312
|
-
---
|
|
313
|
-
|
|
314
|
-
## How It Works
|
|
315
|
-
|
|
316
|
-
### The Magic Behind the CLI
|
|
317
|
-
|
|
318
|
-
```mermaid
|
|
319
|
-
graph LR
|
|
320
|
-
A[Run CLI] --> B[Interactive Setup]
|
|
321
|
-
B --> C[Generate Project]
|
|
322
|
-
C --> D[Install Dependencies]
|
|
323
|
-
D --> E[Generate JWT Secrets]
|
|
324
|
-
E --> F[Configure Database]
|
|
325
|
-
F --> G[Run Migrations]
|
|
326
|
-
G --> H[Seed Admin User]
|
|
327
|
-
H --> I[Start Dev Server & Swagger]
|
|
328
|
-
|
|
329
|
-
style A fill:#667eea
|
|
330
|
-
style I fill:#48bb78
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
### What Gets Created
|
|
334
|
-
|
|
335
|
-
```
|
|
336
|
-
my-app/
|
|
337
|
-
├── src/
|
|
338
|
-
│ ├── modules/
|
|
339
|
-
│ │ ├── auth/ # JWT + Refresh token logic
|
|
340
|
-
│ │ ├── users/ # User CRUD + profile
|
|
341
|
-
│ │ └── health/ # Health check endpoints
|
|
342
|
-
│ ├── common/
|
|
343
|
-
│ │ ├── base/ # Abstract BaseController & BaseService
|
|
344
|
-
│ │ ├── guards/ # JWT & RBAC guards
|
|
345
|
-
│ │ ├── decorators/ # @Roles(), @Public(), @GetUser()
|
|
346
|
-
│ │ └── filters/ # Exception handling
|
|
347
|
-
│ └── config/ # Environment & logging config
|
|
348
|
-
├── prisma/ # (Prisma) Schema + migrations + seed
|
|
349
|
-
├── drizzle/ # (Drizzle) Schema + migrations
|
|
350
|
-
├── test/ # E2E test suite
|
|
351
|
-
├── .env # Auto-configured secrets
|
|
352
|
-
└── package.json # All dependencies ready
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
---
|
|
356
|
-
|
|
357
|
-
## Usage Examples
|
|
358
|
-
|
|
359
|
-
### 1. Interactive Mode (Recommended)
|
|
360
|
-
|
|
361
|
-
**Zero configuration. Just answer questions:**
|
|
362
|
-
|
|
363
|
-
```bash
|
|
364
|
-
npx @astralicc/create-nestjs-auth-swagger@latest
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
### 2. Automation Mode
|
|
368
|
-
|
|
369
|
-
**For CI/CD and scripts:**
|
|
370
|
-
|
|
371
|
-
```bash
|
|
372
|
-
# Skip all prompts, use defaults
|
|
373
|
-
npx @astralicc/create-nestjs-auth-swagger@latest my-app --yes
|
|
374
|
-
|
|
375
|
-
# Specify ORM and database
|
|
376
|
-
npx @astralicc/create-nestjs-auth-swagger@latest my-app --orm drizzle --database postgres --yes
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
---
|
|
380
|
-
|
|
381
|
-
## Complete API Reference
|
|
382
|
-
|
|
383
|
-
Your generated API includes these endpoints out of the box (fully documented in Swagger):
|
|
384
|
-
|
|
385
|
-
### Authentication
|
|
386
|
-
|
|
387
|
-
| Endpoint | Method | Description | Auth |
|
|
388
|
-
|----------|--------|-------------|------|
|
|
389
|
-
| `/auth/signup` | POST | Register new user | |
|
|
390
|
-
| `/auth/login` | POST | Login with credentials | |
|
|
391
|
-
| `/auth/refresh` | POST | Refresh access token | Refresh token |
|
|
392
|
-
| `/auth/logout` | POST | Logout & invalidate tokens | |
|
|
393
|
-
| `/auth/me` | GET | Get current user | |
|
|
394
|
-
|
|
395
|
-
### Users (Admin Only)
|
|
396
|
-
|
|
397
|
-
| Endpoint | Method | Description | Auth |
|
|
398
|
-
|----------|--------|-------------|------|
|
|
399
|
-
| `/users` | GET | List all users (paginated) | ADMIN |
|
|
400
|
-
| `/users/:id` | GET | Get user by ID | ADMIN |
|
|
401
|
-
| `/users/:id` | PATCH | Update user | ADMIN |
|
|
402
|
-
| `/users/:id` | DELETE | Soft delete user | ADMIN |
|
|
403
|
-
|
|
404
|
-
### Profile
|
|
405
|
-
|
|
406
|
-
| Endpoint | Method | Description | Auth |
|
|
407
|
-
|----------|--------|-------------|------|
|
|
408
|
-
| `/users/profile` | GET | Get own profile | |
|
|
409
|
-
| `/users/profile` | PATCH | Update own profile | |
|
|
410
|
-
|
|
411
|
-
<details>
|
|
412
|
-
<summary><b> Example: Add RBAC to Your Endpoint</b></summary>
|
|
413
|
-
|
|
414
|
-
```typescript
|
|
415
|
-
import { Controller, Get } from '@nestjs/common';
|
|
416
|
-
import { Roles } from '@/common/decorators/roles.decorator';
|
|
417
|
-
import { UserRole } from '@prisma/client';
|
|
418
|
-
|
|
419
|
-
@Controller('posts')
|
|
420
|
-
export class PostsController {
|
|
421
|
-
// Public endpoint - anyone can access
|
|
422
|
-
@Public()
|
|
423
|
-
@Get()
|
|
424
|
-
findAll() {
|
|
425
|
-
return { posts: [] };
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// Protected endpoint - any authenticated user
|
|
429
|
-
@Get('my-posts')
|
|
430
|
-
getMyPosts(@GetUser() user) {
|
|
431
|
-
return { posts: [], userId: user.id };
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// Admin only - requires ADMIN role
|
|
435
|
-
@Roles(UserRole.ADMIN)
|
|
436
|
-
@Delete(':id')
|
|
437
|
-
deletePost() {
|
|
438
|
-
return { message: 'Post deleted' };
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
```
|
|
442
|
-
|
|
443
|
-
**That's it!** No manual guard setup. Just decorators.
|
|
444
|
-
|
|
445
|
-
</details>
|
|
446
|
-
|
|
447
|
-
---
|
|
448
|
-
|
|
449
|
-
## CLI Options Reference
|
|
450
|
-
|
|
451
|
-
| Option | Description | Example |
|
|
452
|
-
|--------|-------------|---------|
|
|
453
|
-
| `g [module]` | Generate new CRUD module | `npx @astralicc/create-nestjs-auth-swagger g products` |
|
|
454
|
-
| `--orm <orm>` | Select ORM (prisma, drizzle, typeorm, mongoose) | `npx @astralicc/create-nestjs-auth-swagger@latest my-app --orm drizzle` |
|
|
455
|
-
| `--database <db>` | Select database (postgres, mysql, sqlite, mongodb) | `npx @astralicc/create-nestjs-auth-swagger@latest my-app --database mysql` |
|
|
456
|
-
| `--yes` | Skip all prompts, use defaults | `npx @astralicc/create-nestjs-auth-swagger@latest my-app --yes` |
|
|
457
|
-
| `--skip-install` | Don't install dependencies | `npx @astralicc/create-nestjs-auth-swagger@latest my-app --skip-install` |
|
|
458
|
-
| `--package-manager <pm>` | Force package manager (npm, pnpm, yarn, bun) | `npx @astralicc/create-nestjs-auth-swagger@latest my-app --package-manager pnpm` |
|
|
459
|
-
| `--help` | Show help message | `npx @astralicc/create-nestjs-auth-swagger@latest --help` |
|
|
460
|
-
|
|
461
|
-
---
|
|
462
|
-
|
|
463
|
-
## System Requirements
|
|
464
|
-
|
|
465
|
-
| Requirement | Version | Why? |
|
|
466
|
-
|------------|---------|------|
|
|
467
|
-
| **Node.js** | >= 20.x | Native fetch, improved performance |
|
|
468
|
-
| **Database** | PostgreSQL 16+, MySQL 8+, SQLite 3+, or MongoDB 6+ | Your choice! |
|
|
469
|
-
| **Package Manager** | npm/pnpm/yarn/bun | Any works, auto-detected |
|
|
470
|
-
|
|
471
|
-
---
|
|
472
|
-
|
|
473
|
-
## ORM & Database Options
|
|
474
|
-
|
|
475
|
-
Choose the combination that fits your project:
|
|
476
|
-
|
|
477
|
-
### Supported ORMs
|
|
478
|
-
|
|
479
|
-
| ORM | Best For | Features |
|
|
480
|
-
|-----|----------|----------|
|
|
481
|
-
| **[Prisma](https://www.prisma.io)** | Most projects | Type-safe queries, visual studio, migrations |
|
|
482
|
-
| **[Drizzle](https://orm.drizzle.team)** | SQL lovers | Lightweight, SQL-like syntax, fast |
|
|
483
|
-
| **[TypeORM](https://typeorm.io)** | Enterprise apps | Decorators, Active Record & Data Mapper |
|
|
484
|
-
| **[Mongoose](https://mongoosejs.com)** | MongoDB users | Schema validation, middleware, populate |
|
|
485
|
-
|
|
486
|
-
### ORM + Database Compatibility
|
|
217
|
+
## 🗄️ Multi-ORM & Database Matrix
|
|
487
218
|
|
|
488
219
|
```
|
|
489
220
|
┌─────────────┬────────────┬───────┬────────┬─────────┐
|
|
@@ -498,123 +229,29 @@ Choose the combination that fits your project:
|
|
|
498
229
|
|
|
499
230
|
---
|
|
500
231
|
|
|
501
|
-
##
|
|
502
|
-
|
|
503
|
-
### vs. Building from Scratch
|
|
504
|
-
|
|
505
|
-
| Feature | From Scratch | @astralicc/create-nestjs-auth-swagger |
|
|
506
|
-
|---------|-------------|-------------------|
|
|
507
|
-
| **Time to setup** | 34-46 hours | 3 minutes |
|
|
508
|
-
| **Security audit** | You do it (risky) | Battle-tested |
|
|
509
|
-
| **Token rotation** | Implement yourself | Included |
|
|
510
|
-
| **RBAC** | Build guards | Decorator-based |
|
|
511
|
-
| **Rate limiting** | Manual setup | Pre-configured |
|
|
512
|
-
| **CRUD Generator** | DIY | Included (`g` command) |
|
|
513
|
-
| **Swagger Docs** | Manual annotations | Auto-generated |
|
|
514
|
-
|
|
515
|
-
---
|
|
516
|
-
|
|
517
|
-
## Troubleshooting
|
|
518
|
-
|
|
519
|
-
<details>
|
|
520
|
-
<summary><b> "Command not found: @astralicc/create-nestjs-auth-swagger"</b></summary>
|
|
521
|
-
|
|
522
|
-
Use `npx` with `@latest` tag:
|
|
523
|
-
```bash
|
|
524
|
-
npx @astralicc/create-nestjs-auth-swagger@latest my-app
|
|
525
|
-
```
|
|
526
|
-
|
|
527
|
-
</details>
|
|
528
|
-
|
|
529
|
-
<details>
|
|
530
|
-
<summary><b> "Template directory not found"</b></summary>
|
|
531
|
-
|
|
532
|
-
Reinstall the CLI:
|
|
533
|
-
```bash
|
|
534
|
-
npm uninstall -g @astralicc/create-nestjs-auth-swagger
|
|
535
|
-
npm cache clean --force
|
|
536
|
-
npm install -g @astralicc/create-nestjs-auth-swagger
|
|
537
|
-
```
|
|
538
|
-
|
|
539
|
-
</details>
|
|
540
|
-
|
|
541
|
-
<details>
|
|
542
|
-
<summary><b> Database connection fails</b></summary>
|
|
543
|
-
|
|
544
|
-
Check your PostgreSQL is running:
|
|
545
|
-
```bash
|
|
546
|
-
pg_isready
|
|
547
|
-
psql postgresql://user:password@localhost:5432/mydb
|
|
548
|
-
```
|
|
549
|
-
</details>
|
|
550
|
-
|
|
551
|
-
<details>
|
|
552
|
-
<summary><b> Port 8080 already in use</b></summary>
|
|
553
|
-
|
|
554
|
-
Option 1: Change port in `.env`:
|
|
555
|
-
```env
|
|
556
|
-
PORT=3000
|
|
557
|
-
```
|
|
558
|
-
</details>
|
|
559
|
-
|
|
560
|
-
---
|
|
561
|
-
|
|
562
|
-
## Contributing
|
|
563
|
-
|
|
564
|
-
We love contributions! Here's how you can help:
|
|
565
|
-
|
|
566
|
-
1. Fork the repository
|
|
567
|
-
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
|
568
|
-
3. Make your changes
|
|
569
|
-
4. Test thoroughly: `npm test`
|
|
570
|
-
5. Commit: `git commit -m 'Add amazing feature'`
|
|
571
|
-
6. Push: `git push origin feature/amazing-feature`
|
|
572
|
-
7. Open a Pull Request
|
|
573
|
-
|
|
574
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
|
|
575
|
-
|
|
576
|
-
---
|
|
577
|
-
|
|
578
|
-
## Tech Stack
|
|
579
|
-
|
|
580
|
-
<div align="center">
|
|
581
|
-
|
|
582
|
-
| Technology | Version | Purpose |
|
|
583
|
-
|------------|---------|---------|
|
|
584
|
-
| [NestJS](https://nestjs.com) | 11.0 | Progressive Node.js framework |
|
|
585
|
-
| [TypeScript](https://www.typescriptlang.org) | 5.7 | Type safety |
|
|
586
|
-
| [Prisma](https://www.prisma.io) | 6.x | Type-safe ORM (option 1) |
|
|
587
|
-
| [Drizzle](https://orm.drizzle.team) | Latest | Lightweight ORM (option 2) |
|
|
588
|
-
| [TypeORM](https://typeorm.io) | 0.3.x | Decorator-based ORM (option 3) |
|
|
589
|
-
| [Mongoose](https://mongoosejs.com) | 8.x | MongoDB ODM (option 4) |
|
|
590
|
-
| [Swagger](https://swagger.io/) | - | API Documentation |
|
|
591
|
-
| [Passport JWT](https://www.passportjs.org) | - | JWT authentication |
|
|
232
|
+
## 📋 CLI Flags & Options
|
|
592
233
|
|
|
593
|
-
|
|
234
|
+
| Option | Description | Example |
|
|
235
|
+
|--------|-------------|---------|
|
|
236
|
+
| `g [module]` / `generate` | Generate a new CRUD module | `npx speedrun-cli g products` |
|
|
237
|
+
| `f [module]` / `field` | Manage fields on an existing module | `npx speedrun-cli f products` |
|
|
238
|
+
| `--orm <orm>` | Select ORM (prisma, drizzle, typeorm, mongoose) | `npx speedrun-cli create my-app --orm drizzle` |
|
|
239
|
+
| `--database <db>` | Select database (postgres, mysql, sqlite, mongodb) | `npx speedrun-cli create my-app --database mysql` |
|
|
240
|
+
| `--yes` | Skip all prompts, use defaults | `npx speedrun-cli create my-app --yes` |
|
|
241
|
+
| `--skip-install` | Skip dependency installation | `npx speedrun-cli create my-app --skip-install` |
|
|
242
|
+
| `--package-manager <pm>` | Force package manager (npm, pnpm, yarn, bun) | `npx speedrun-cli create my-app --package-manager pnpm` |
|
|
243
|
+
| `--help` | Show CLI help message | `npx speedrun-cli --help` |
|
|
594
244
|
|
|
595
245
|
---
|
|
596
246
|
|
|
597
|
-
##
|
|
247
|
+
## 📖 Full Interactive Flow & Code Output Guide
|
|
598
248
|
|
|
599
|
-
|
|
249
|
+
For detailed terminal walkthroughs, step-by-step interactive prompt sessions, generated code outputs, and multi-ORM schema matrices, please visit:
|
|
600
250
|
|
|
601
|
-
|
|
251
|
+
👉 [**USAGE.md — Command & Interactive Flow Guide**](./USAGE.md)
|
|
602
252
|
|
|
603
253
|
---
|
|
604
254
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
### Did this save you time?
|
|
255
|
+
## 📄 License
|
|
608
256
|
|
|
609
|
-
**
|
|
610
|
-
|
|
611
|
-
<sub>
|
|
612
|
-
Generated projects follow <strong>NestJS best practices</strong> and <strong>OWASP security guidelines</strong><br>
|
|
613
|
-
<strong>v2.4.0</strong> | Multi-ORM & Multi-Database Support | MIT License
|
|
614
|
-
</sub>
|
|
615
|
-
|
|
616
|
-
<br><br>
|
|
617
|
-
|
|
618
|
-
**Now go build something amazing!**
|
|
619
|
-
|
|
620
|
-
</div>
|
|
257
|
+
**MIT License** - free to use in personal and commercial projects. See [LICENSE](LICENSE) for details.
|