speedrun-cli 2.6.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.
- package/CHANGELOG.md +96 -0
- package/LICENSE +21 -0
- package/README.md +620 -0
- package/bin/cli.js +224 -0
- package/index.js +12 -0
- package/package.json +74 -0
- package/src/constants.js +65 -0
- package/src/generator.js +271 -0
- package/src/index.js +13 -0
- package/src/moduleGenerator.js +586 -0
- package/src/postSetup.js +365 -0
- package/src/prompts.js +189 -0
- package/src/utils.js +112 -0
- package/templates/README.md +81 -0
- package/templates/base/eslint.config.mjs +34 -0
- package/templates/base/gitignore +78 -0
- package/templates/base/nest-cli.json +8 -0
- package/templates/base/src/common/constants/cookie.config.ts +20 -0
- package/templates/base/src/common/decorators/get-user.decorator.ts +13 -0
- package/templates/base/src/common/decorators/public.decorator.ts +4 -0
- package/templates/base/src/common/decorators/roles.decorator.ts +4 -0
- package/templates/base/src/common/dtos/pagination.dto.ts +29 -0
- package/templates/base/src/common/filters/http-exception.filter.ts +108 -0
- package/templates/base/src/common/guards/auth.guard.ts +51 -0
- package/templates/base/src/common/guards/refresh-token.guard.ts +39 -0
- package/templates/base/src/common/guards/roles.guard.ts +45 -0
- package/templates/base/src/common/interceptors/response.interceptor.ts +55 -0
- package/templates/base/src/common/interfaces/api-response.interface.ts +26 -0
- package/templates/base/src/common/middleware/correlation-id.middleware.ts +20 -0
- package/templates/base/src/common/validators/password.validator.ts +37 -0
- package/templates/base/src/config/config.module.ts +14 -0
- package/templates/base/src/config/logger.config.ts +109 -0
- package/templates/base/src/main.ts +84 -0
- package/templates/base/src/modules/auth/auth.controller.ts +133 -0
- package/templates/base/src/modules/auth/dtos/login.dto.ts +11 -0
- package/templates/base/src/modules/auth/dtos/signup.dto.ts +8 -0
- package/templates/base/src/modules/health/health.controller.ts +20 -0
- package/templates/base/src/modules/health/health.module.ts +7 -0
- package/templates/base/src/modules/users/dtos/update-profile.dto.ts +12 -0
- package/templates/base/src/modules/users/dtos/update-user.dto.ts +13 -0
- package/templates/base/src/modules/users/users.controller.ts +65 -0
- package/templates/base/test/app.e2e-spec.ts +24 -0
- package/templates/base/test/jest-e2e.json +9 -0
- package/templates/base/tsconfig.build.json +4 -0
- package/templates/base/tsconfig.json +24 -0
- package/templates/base-crud/CRUD_README.md +385 -0
- package/templates/base-crud/src/common/base/base.controller.ts +321 -0
- package/templates/base-crud/src/common/base/base.service.ts +192 -0
- package/templates/base-crud/src/common/base/index.ts +20 -0
- package/templates/base-crud/src/common/base/swagger/api-response.dto.ts +82 -0
- package/templates/base-crud/src/common/base/swagger/paginated.dto.ts +102 -0
- package/templates/base-crud/src/modules/products/dto/create-product.dto.ts +44 -0
- package/templates/base-crud/src/modules/products/dto/product.dto.ts +38 -0
- package/templates/base-crud/src/modules/products/dto/update-product.dto.ts +12 -0
- package/templates/base-crud/src/modules/products/products.controller.ts +94 -0
- package/templates/base-crud-drizzle/src/modules/products/products.controller.ts +79 -0
- package/templates/base-crud-drizzle/src/modules/products/products.module.ts +24 -0
- package/templates/base-crud-drizzle/src/modules/products/products.service.ts +140 -0
- package/templates/base-crud-drizzle/src/modules/products/schema/products.schema.ts +39 -0
- package/templates/base-crud-mongoose/src/modules/products/products.controller.ts +79 -0
- package/templates/base-crud-mongoose/src/modules/products/products.module.ts +26 -0
- package/templates/base-crud-mongoose/src/modules/products/products.service.ts +133 -0
- package/templates/base-crud-mongoose/src/modules/products/schemas/product.schema.ts +67 -0
- package/templates/base-crud-prisma/src/modules/products/products.module.ts +12 -0
- package/templates/base-crud-prisma/src/modules/products/products.service.ts +100 -0
- package/templates/base-crud-typeorm/src/modules/products/entities/product.entity.ts +58 -0
- package/templates/base-crud-typeorm/src/modules/products/products.controller.ts +79 -0
- package/templates/base-crud-typeorm/src/modules/products/products.module.ts +25 -0
- package/templates/base-crud-typeorm/src/modules/products/products.service.ts +102 -0
- package/templates/database/mongodb/.env.example +22 -0
- package/templates/database/mysql/.env.example +24 -0
- package/templates/database/mysql/drizzle.config.ts +13 -0
- package/templates/database/mysql/package.json +5 -0
- package/templates/database/mysql/prisma/schema.prisma +55 -0
- package/templates/database/mysql/src/database/drizzle.ts +13 -0
- package/templates/database/mysql/src/database/schema.ts +58 -0
- package/templates/database/postgres/.env.example +24 -0
- package/templates/database/postgres/drizzle.config.ts +13 -0
- package/templates/database/postgres/package.json +8 -0
- package/templates/database/postgres/prisma/schema.prisma +55 -0
- package/templates/database/sqlite/.env.example +24 -0
- package/templates/database/sqlite/drizzle.config.ts +13 -0
- package/templates/database/sqlite/package.json +8 -0
- package/templates/database/sqlite/prisma/schema.prisma +48 -0
- package/templates/database/sqlite/src/database/drizzle.ts +11 -0
- package/templates/database/sqlite/src/database/schema.ts +52 -0
- package/templates/orm/drizzle/drizzle.config.ts +13 -0
- package/templates/orm/drizzle/package.json +90 -0
- package/templates/orm/drizzle/src/app.module.ts +73 -0
- package/templates/orm/drizzle/src/config/env.validation.ts +55 -0
- package/templates/orm/drizzle/src/database/database.module.ts +25 -0
- package/templates/orm/drizzle/src/database/drizzle.ts +13 -0
- package/templates/orm/drizzle/src/database/schema.ts +60 -0
- package/templates/orm/drizzle/src/database/seed.ts +87 -0
- package/templates/orm/drizzle/src/modules/auth/auth.module.ts +12 -0
- package/templates/orm/drizzle/src/modules/auth/auth.service.ts +298 -0
- package/templates/orm/drizzle/src/modules/health/health.controller.ts +34 -0
- package/templates/orm/drizzle/src/modules/health/health.module.ts +7 -0
- package/templates/orm/drizzle/src/modules/users/users.module.ts +10 -0
- package/templates/orm/drizzle/src/modules/users/users.service.ts +152 -0
- package/templates/orm/mongoose/.env.example +22 -0
- package/templates/orm/mongoose/package.json +86 -0
- package/templates/orm/mongoose/src/app.module.ts +73 -0
- package/templates/orm/mongoose/src/config/env.validation.ts +55 -0
- package/templates/orm/mongoose/src/database/database.module.ts +19 -0
- package/templates/orm/mongoose/src/database/seed.ts +107 -0
- package/templates/orm/mongoose/src/modules/auth/auth.module.ts +21 -0
- package/templates/orm/mongoose/src/modules/auth/auth.service.ts +272 -0
- package/templates/orm/mongoose/src/modules/auth/dtos/login.dto.ts +10 -0
- package/templates/orm/mongoose/src/modules/auth/dtos/signup.dto.ts +8 -0
- package/templates/orm/mongoose/src/modules/health/health.controller.ts +26 -0
- package/templates/orm/mongoose/src/modules/health/health.module.ts +7 -0
- package/templates/orm/mongoose/src/modules/users/dtos/update-profile.dto.ts +24 -0
- package/templates/orm/mongoose/src/modules/users/dtos/update-user.dto.ts +13 -0
- package/templates/orm/mongoose/src/modules/users/users.module.ts +19 -0
- package/templates/orm/mongoose/src/modules/users/users.service.ts +179 -0
- package/templates/orm/mongoose/src/schemas/index.ts +2 -0
- package/templates/orm/mongoose/src/schemas/refresh-token.schema.ts +55 -0
- package/templates/orm/mongoose/src/schemas/user.schema.ts +53 -0
- package/templates/orm/prisma/package.json +102 -0
- package/templates/orm/prisma/prisma/schema.prisma +60 -0
- package/templates/orm/prisma/prisma/seed.ts +69 -0
- package/templates/orm/prisma/src/app.module.ts +55 -0
- package/templates/orm/prisma/src/config/env.validation.ts +56 -0
- package/templates/orm/prisma/src/modules/auth/auth.module.ts +17 -0
- package/templates/orm/prisma/src/modules/auth/auth.service.ts +308 -0
- package/templates/orm/prisma/src/modules/health/health.controller.ts +26 -0
- package/templates/orm/prisma/src/modules/health/health.module.ts +10 -0
- package/templates/orm/prisma/src/modules/users/users.module.ts +11 -0
- package/templates/orm/prisma/src/modules/users/users.service.ts +105 -0
- package/templates/orm/prisma/src/prisma/prisma.module.ts +9 -0
- package/templates/orm/prisma/src/prisma/prisma.service.ts +16 -0
- package/templates/orm/typeorm/package.json +100 -0
- package/templates/orm/typeorm/src/app.module.ts +55 -0
- package/templates/orm/typeorm/src/config/env.validation.ts +58 -0
- package/templates/orm/typeorm/src/database/data-source.ts +19 -0
- package/templates/orm/typeorm/src/database/database.module.ts +27 -0
- package/templates/orm/typeorm/src/database/seed.ts +76 -0
- package/templates/orm/typeorm/src/entities/index.ts +2 -0
- package/templates/orm/typeorm/src/entities/refresh-token.entity.ts +45 -0
- package/templates/orm/typeorm/src/entities/user.entity.ts +51 -0
- package/templates/orm/typeorm/src/modules/auth/auth.module.ts +19 -0
- package/templates/orm/typeorm/src/modules/auth/auth.service.ts +286 -0
- package/templates/orm/typeorm/src/modules/health/health.controller.ts +24 -0
- package/templates/orm/typeorm/src/modules/health/health.module.ts +9 -0
- package/templates/orm/typeorm/src/modules/users/users.module.ts +13 -0
- package/templates/orm/typeorm/src/modules/users/users.service.ts +108 -0
- package/templates/swagger/src/common/dtos/pagination.dto.ts +43 -0
- package/templates/swagger/src/main.ts +116 -0
- package/templates/swagger/src/modules/auth/auth.controller.ts +235 -0
- package/templates/swagger/src/modules/auth/dtos/login.dto.ts +20 -0
- package/templates/swagger/src/modules/auth/dtos/signup.dto.ts +14 -0
- package/templates/swagger/src/modules/users/dtos/update-profile.dto.ts +19 -0
- package/templates/swagger/src/modules/users/dtos/update-user.dto.ts +23 -0
- package/templates/swagger/src/modules/users/users.controller.ts +214 -0
- package/templates/swagger-mongoose/src/modules/auth/dtos/login.dto.ts +20 -0
- package/templates/swagger-mongoose/src/modules/auth/dtos/signup.dto.ts +14 -0
- package/templates/swagger-mongoose/src/modules/users/dtos/update-profile.dto.ts +40 -0
- package/templates/swagger-mongoose/src/modules/users/dtos/update-user.dto.ts +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @astralicc/create-nestjs-auth-swagger
|
|
4
|
+
|
|
5
|
+
### The Zero-Config Way to Build Secure Authentication & CRUD APIs
|
|
6
|
+
|
|
7
|
+
**Stop wasting 40 hours building JWT auth & CRUD modules from scratch.**
|
|
8
|
+
Get a battle-tested, production-ready NestJS auth system and Swagger-documented APIs in **under 3 minutes**.
|
|
9
|
+
|
|
10
|
+
[](https://www.npmjs.com/package/@astralicc/create-nestjs-auth-swagger)
|
|
11
|
+
[](https://www.npmjs.com/package/@astralicc/create-nestjs-auth-swagger)
|
|
12
|
+
[](LICENSE)
|
|
13
|
+
[](https://nodejs.org)
|
|
14
|
+
[](https://www.typescriptlang.org/)
|
|
15
|
+
[](https://nestjs.com/)
|
|
16
|
+
[](https://swagger.io/)
|
|
17
|
+
[](CONTRIBUTING.md)
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx @astralicc/create-nestjs-auth-swagger@latest
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
[Quick Start](#quick-start) | [ORM & Database Options](#orm--database-options) | [Features](#what-you-get) | [Docs](#links--resources)
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
**v2.4.0** | **Interactive Module Generator** | **Swagger UI Included** | **4 ORMs** | **4 Databases**
|
|
28
|
+
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Why This Exists
|
|
34
|
+
|
|
35
|
+
Building secure JWT authentication and standard CRUD operations isn't trivial. You need:
|
|
36
|
+
- Access tokens + refresh token rotation
|
|
37
|
+
- HttpOnly cookies (not localStorage)
|
|
38
|
+
- Multi-device session management
|
|
39
|
+
- Role-based access control (RBAC)
|
|
40
|
+
- Rate limiting & brute-force protection
|
|
41
|
+
- PII-safe logging
|
|
42
|
+
- Proper password hashing (bcrypt 12 rounds)
|
|
43
|
+
- Flexible ORM & database choices
|
|
44
|
+
- **Consistent, secure CRUD boilerplate with strict validation**
|
|
45
|
+
- **Automated API Documentation (Swagger)**
|
|
46
|
+
|
|
47
|
+
**This CLI gives you all of that.** Production-ready, security-hardened, tested patterns - instantly.
|
|
48
|
+
|
|
49
|
+
<div align="center">
|
|
50
|
+
|
|
51
|
+
### The Problem with Building APIs From Scratch
|
|
52
|
+
|
|
53
|
+
| Task | Time Required | Complexity |
|
|
54
|
+
|------|---------------|------------|
|
|
55
|
+
| JWT access/refresh setup | 6-8 hours | High |
|
|
56
|
+
| Token rotation logic | 4-6 hours | Very High |
|
|
57
|
+
| RBAC implementation | 3-4 hours | Medium |
|
|
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** | **** |
|
|
63
|
+
|
|
64
|
+
### With @astralicc/create-nestjs-auth-swagger
|
|
65
|
+
|
|
66
|
+
| Task | Time Required | Complexity |
|
|
67
|
+
|------|---------------|------------|
|
|
68
|
+
| Run one command | 3 minutes | **Zero** |
|
|
69
|
+
| Generate new modules | 10 seconds | **Zero** |
|
|
70
|
+
| **Total** | **~3 minutes** | **** |
|
|
71
|
+
|
|
72
|
+
*Save 40+ hours and get battle-tested code that just works.*
|
|
73
|
+
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
## Quick Start
|
|
77
|
+
|
|
78
|
+
**30 seconds to a running auth API with Swagger Docs:**
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Run the CLI
|
|
82
|
+
npx @astralicc/create-nestjs-auth-swagger@latest
|
|
83
|
+
|
|
84
|
+
# Answer quick questions
|
|
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
|
+
```
|
|
97
|
+
|
|
98
|
+
<details>
|
|
99
|
+
<summary><b>See it in action (GIF/Video coming soon)</b></summary>
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
create-nestjs-auth-swagger
|
|
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
|
+
```
|
|
127
|
+
|
|
128
|
+
</details>
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## What You Get
|
|
133
|
+
|
|
134
|
+
<table>
|
|
135
|
+
<tr>
|
|
136
|
+
<td width="50%">
|
|
137
|
+
|
|
138
|
+
### Enterprise-Grade Security
|
|
139
|
+
|
|
140
|
+
- **Token Rotation** - Refresh tokens auto-rotate on use
|
|
141
|
+
- **Zero XSS Risk** - HttpOnly cookies only
|
|
142
|
+
- **Bcrypt 12 Rounds** - 2025 security baseline
|
|
143
|
+
- **Rate Limiting** - 5 auth attempts/min
|
|
144
|
+
- **PII-Safe Logs** - Passwords/tokens auto-redacted
|
|
145
|
+
- **Mass Assignment Protection** - `ValidationPipe` with `whitelist: true` & `forbidNonWhitelisted: true`
|
|
146
|
+
- **Strict Parameter Parsing** - `@ParseUUIDPipe` / `@ParseIntPipe` on ID parameters.
|
|
147
|
+
|
|
148
|
+
</td>
|
|
149
|
+
<td width="50%">
|
|
150
|
+
|
|
151
|
+
### Developer Experience
|
|
152
|
+
|
|
153
|
+
- **Interactive Module Generator** - Scaffold CRUD in seconds
|
|
154
|
+
- **Auto-Generated Swagger Docs** - Out-of-the-box UI at `/api/docs`
|
|
155
|
+
- **TypeScript** - Full type safety
|
|
156
|
+
- **Base CRUD Architecture** - Abstract `BaseService` & `BaseController`
|
|
157
|
+
- **Hot Reload** - Instant feedback
|
|
158
|
+
- **Prisma Studio** - Visual database UI
|
|
159
|
+
|
|
160
|
+
</td>
|
|
161
|
+
</tr>
|
|
162
|
+
<tr>
|
|
163
|
+
<td width="50%">
|
|
164
|
+
|
|
165
|
+
### Production-Ready
|
|
166
|
+
|
|
167
|
+
- **RBAC in 2 Lines** - `@Roles(UserRole.ADMIN)`
|
|
168
|
+
- **Multi-Device Sessions** - Track 5 devices/user
|
|
169
|
+
- **Structured Logging** - Pino JSON logs
|
|
170
|
+
- **Input Validation** - Zod + class-validator
|
|
171
|
+
- **CORS & Helmet** - Security headers included
|
|
172
|
+
- **Global Error Handling** - Handled `NotFoundException` and Soft-Deletes.
|
|
173
|
+
|
|
174
|
+
</td>
|
|
175
|
+
<td width="50%">
|
|
176
|
+
|
|
177
|
+
### Flexible Database Support
|
|
178
|
+
|
|
179
|
+
- **4 ORMs** - Prisma, Drizzle, TypeORM, Mongoose
|
|
180
|
+
- **4 Databases** - PostgreSQL, MySQL, SQLite, MongoDB
|
|
181
|
+
- **Type-Safe** - Full TypeScript support across all ORMs
|
|
182
|
+
- **Migrations** - Version control for your database
|
|
183
|
+
- **Seeding** - Default admin user included
|
|
184
|
+
|
|
185
|
+
</td>
|
|
186
|
+
</tr>
|
|
187
|
+
</table>
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Interactive Module Generator
|
|
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
|
|
487
|
+
|
|
488
|
+
```
|
|
489
|
+
┌─────────────┬────────────┬───────┬────────┬─────────┐
|
|
490
|
+
│ │ PostgreSQL │ MySQL │ SQLite │ MongoDB │
|
|
491
|
+
├─────────────┼────────────┼───────┼────────┼─────────┤
|
|
492
|
+
│ Prisma │ ✅ │ ✅ │ ✅ │ ❌ │
|
|
493
|
+
│ Drizzle │ ✅ │ ✅ │ ✅ │ ❌ │
|
|
494
|
+
│ TypeORM │ ✅ │ ✅ │ ✅ │ ❌ │
|
|
495
|
+
│ Mongoose │ ❌ │ ❌ │ ❌ │ ✅ │
|
|
496
|
+
└─────────────┴────────────┴───────┴────────┴─────────┘
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
## Comparison with Alternatives
|
|
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 |
|
|
592
|
+
|
|
593
|
+
</div>
|
|
594
|
+
|
|
595
|
+
---
|
|
596
|
+
|
|
597
|
+
## License
|
|
598
|
+
|
|
599
|
+
**MIT License** - do whatever you want with it!
|
|
600
|
+
|
|
601
|
+
See [LICENSE](LICENSE) for full details.
|
|
602
|
+
|
|
603
|
+
---
|
|
604
|
+
|
|
605
|
+
<div align="center">
|
|
606
|
+
|
|
607
|
+
### Did this save you time?
|
|
608
|
+
|
|
609
|
+
**Star this repository** to help others discover it!
|
|
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>
|