ar-saas 0.1.0 → 0.2.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.
- package/README.md +175 -31
- package/dist/cli.js +3 -12
- package/dist/generator.js +6 -17
- package/dist/index.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# ar-saas
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>Generador de proyectos SaaS multi-tenant para startups argentinas</strong><br/>
|
|
5
|
+
Backend NestJS + Frontend Next.js listos para producción en minutos.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://www.npmjs.com/package/ar-saas"><img src="https://img.shields.io/npm/v/ar-saas.svg" alt="npm version" /></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/ar-saas"><img src="https://img.shields.io/npm/dm/ar-saas.svg" alt="npm downloads" /></a>
|
|
11
|
+
<a href="https://github.com/ignaciobecher/ar-saas/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license" /></a>
|
|
12
|
+
<img src="https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen" alt="node version" />
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
---
|
|
4
16
|
|
|
5
17
|
## Quickstart
|
|
6
18
|
|
|
@@ -8,55 +20,187 @@ Generador de proyectos SaaS multi-tenant para startups argentinas.
|
|
|
8
20
|
npx ar-saas mi-proyecto
|
|
9
21
|
```
|
|
10
22
|
|
|
11
|
-
|
|
23
|
+
Respondés 4 preguntas y en minutos tenés un proyecto completo corriendo localmente.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## ¿Qué genera?
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
mi-proyecto/
|
|
31
|
+
├── backend/ # NestJS 11 + MongoDB
|
|
32
|
+
│ ├── src/
|
|
33
|
+
│ │ ├── modules/
|
|
34
|
+
│ │ │ ├── auth/ # Auth completo (JWT en cookies HttpOnly)
|
|
35
|
+
│ │ │ ├── users/ # Usuarios con roles
|
|
36
|
+
│ │ │ ├── workspaces/ # Multi-tenancy por workspace
|
|
37
|
+
│ │ │ └── mail/ # Emails transaccionales con Resend
|
|
38
|
+
│ │ └── common/ # Guards, filtros, decoradores, base repository
|
|
39
|
+
│ ├── .env.example
|
|
40
|
+
│ └── package.json
|
|
41
|
+
├── frontend/ # Next.js 15 + Tailwind CSS 4 + shadcn/ui
|
|
42
|
+
│ ├── src/
|
|
43
|
+
│ │ ├── app/
|
|
44
|
+
│ │ │ ├── (auth)/ # Login, register, verify email, reset password
|
|
45
|
+
│ │ │ ├── (dashboard)/ # Rutas protegidas con layout
|
|
46
|
+
│ │ │ └── setup/ # Pantalla de onboarding al abrir por primera vez
|
|
47
|
+
│ │ ├── providers/ # AuthProvider con estado global
|
|
48
|
+
│ │ └── lib/api/ # Cliente axios con refresh automático
|
|
49
|
+
│ └── package.json
|
|
50
|
+
└── railway.toml / fly.toml / docker-compose.yml
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Stack
|
|
56
|
+
|
|
57
|
+
### Backend
|
|
58
|
+
| Tecnología | Versión | Uso |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| NestJS | 11 | Framework principal |
|
|
61
|
+
| MongoDB + Mongoose | 9 | Base de datos |
|
|
62
|
+
| JWT (passport) | — | Autenticación en cookies HttpOnly |
|
|
63
|
+
| Resend | — | Emails transaccionales |
|
|
64
|
+
| Swagger | — | Documentación automática en `/api/docs` |
|
|
12
65
|
|
|
13
|
-
|
|
66
|
+
### Frontend
|
|
67
|
+
| Tecnología | Versión | Uso |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| Next.js | 15 | App Router, Server Components |
|
|
70
|
+
| Tailwind CSS | 4 | Estilos |
|
|
71
|
+
| shadcn/ui | — | Componentes UI |
|
|
72
|
+
| react-hook-form | — | Formularios |
|
|
73
|
+
| axios | — | HTTP client con interceptor de refresh |
|
|
14
74
|
|
|
15
|
-
|
|
75
|
+
---
|
|
16
76
|
|
|
17
|
-
|
|
77
|
+
## Módulos incluidos
|
|
18
78
|
|
|
19
|
-
|
|
79
|
+
### Free (siempre incluidos)
|
|
20
80
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
81
|
+
| Módulo | Descripción |
|
|
82
|
+
|---|---|
|
|
83
|
+
| **Auth completo** | Registro, login, verificación de email, reset de password |
|
|
84
|
+
| **Multi-tenancy** | Aislamiento estricto por `workspaceId` en todas las queries |
|
|
85
|
+
| **Mail transaccional** | Verificación, bienvenida y reset con Resend. Fail-open si Resend falla |
|
|
24
86
|
|
|
25
|
-
|
|
87
|
+
### Opcionales
|
|
26
88
|
|
|
27
89
|
| Módulo | Descripción |
|
|
28
90
|
|---|---|
|
|
29
|
-
| OAuth + 2FA | Login con GitHub/Google + autenticación de dos factores |
|
|
30
|
-
| Notificaciones | Notificaciones in-app + Push Web (VAPID) |
|
|
31
|
-
| Invoices + Quotes | Facturación con generación de PDF |
|
|
32
|
-
| CRM | Kanban + Pipeline de ventas |
|
|
33
|
-
| MercadoPago | Suscripciones recurrentes con webhooks |
|
|
91
|
+
| **OAuth + 2FA** | Login con GitHub/Google + autenticación de dos factores TOTP |
|
|
92
|
+
| **Notificaciones** | Notificaciones in-app + Push Web (VAPID) |
|
|
93
|
+
| **Invoices + Quotes** | Facturación con generación de PDF |
|
|
94
|
+
| **CRM** | Kanban + Pipeline de ventas |
|
|
95
|
+
| **MercadoPago** | Suscripciones recurrentes con webhooks |
|
|
34
96
|
|
|
35
|
-
|
|
97
|
+
---
|
|
36
98
|
|
|
37
|
-
|
|
99
|
+
## Configuración
|
|
38
100
|
|
|
39
|
-
|
|
40
|
-
- **Fly.io** — `fly.toml` con región `gru` (São Paulo)
|
|
41
|
-
- **Docker** — `docker-compose.yml` con MongoDB incluido
|
|
101
|
+
Al ejecutar el CLI se copian automáticamente los archivos `.env.example` → `.env`.
|
|
42
102
|
|
|
43
|
-
|
|
103
|
+
### Backend — variables requeridas
|
|
104
|
+
|
|
105
|
+
| Variable | Descripción |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `MONGODB_URI` | URI de conexión a MongoDB |
|
|
108
|
+
| `JWT_ACCESS_SECRET` | Secreto para access tokens (`openssl rand -hex 64`) |
|
|
109
|
+
| `JWT_REFRESH_SECRET` | Secreto para refresh tokens (distinto al anterior) |
|
|
110
|
+
| `RESEND_API_KEY` | API Key de [Resend](https://resend.com) |
|
|
111
|
+
| `RESEND_FROM_EMAIL` | Email remitente verificado en Resend |
|
|
112
|
+
| `APP_URL` | URL del frontend (para links en emails) |
|
|
113
|
+
| `CORS_ORIGINS` | URL del frontend separada por comas |
|
|
44
114
|
|
|
45
|
-
|
|
46
|
-
- MongoDB (o usar el Docker Compose incluido)
|
|
47
|
-
- Cuenta en [Resend](https://resend.com) para emails
|
|
115
|
+
### Frontend — variables requeridas
|
|
48
116
|
|
|
49
|
-
|
|
117
|
+
| Variable | Descripción |
|
|
118
|
+
|---|---|
|
|
119
|
+
| `NEXT_PUBLIC_API_URL` | URL base del backend (ej: `http://localhost:3000`) |
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Deploy
|
|
50
124
|
|
|
51
|
-
El CLI
|
|
125
|
+
El CLI genera la configuración según el entorno elegido:
|
|
52
126
|
|
|
127
|
+
### Railway
|
|
128
|
+
```toml
|
|
129
|
+
# railway.toml generado automáticamente
|
|
130
|
+
[build]
|
|
131
|
+
builder = "nixpacks"
|
|
132
|
+
|
|
133
|
+
[deploy]
|
|
134
|
+
startCommand = "npm run start:prod"
|
|
135
|
+
healthcheckPath = "/api/health"
|
|
53
136
|
```
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
137
|
+
|
|
138
|
+
### Fly.io
|
|
139
|
+
```toml
|
|
140
|
+
# fly.toml generado automáticamente
|
|
141
|
+
app = "mi-proyecto"
|
|
142
|
+
primary_region = "gru" # São Paulo
|
|
58
143
|
```
|
|
59
144
|
|
|
145
|
+
### Docker
|
|
146
|
+
```yaml
|
|
147
|
+
# docker-compose.yml generado automáticamente
|
|
148
|
+
# Incluye backend + frontend + MongoDB
|
|
149
|
+
docker compose up
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Iniciar el proyecto generado
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# Backend
|
|
158
|
+
cd mi-proyecto/backend
|
|
159
|
+
npm install
|
|
160
|
+
npm run start:dev
|
|
161
|
+
# → http://localhost:3000
|
|
162
|
+
# → Swagger: http://localhost:3000/api/docs
|
|
163
|
+
|
|
164
|
+
# Frontend (en otra terminal)
|
|
165
|
+
cd mi-proyecto/frontend
|
|
166
|
+
npm install
|
|
167
|
+
npm run dev
|
|
168
|
+
# → http://localhost:3001
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
La primera vez que abrís el frontend aparece una pantalla de onboarding que guía la configuración completa.
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Flujos de autenticación implementados
|
|
176
|
+
|
|
177
|
+
- `POST /api/auth/register` — Registro con email de verificación
|
|
178
|
+
- `GET /api/auth/verify-email?token=` — Verificación de email
|
|
179
|
+
- `POST /api/auth/login` — Login (setea cookies HttpOnly)
|
|
180
|
+
- `POST /api/auth/refresh` — Refresh automático del access token
|
|
181
|
+
- `POST /api/auth/logout` — Logout (limpia cookies)
|
|
182
|
+
- `POST /api/auth/forgot-password` — Solicitud de reset
|
|
183
|
+
- `POST /api/auth/reset-password` — Reset de contraseña
|
|
184
|
+
- `GET /api/auth/me` — Datos del usuario autenticado
|
|
185
|
+
|
|
186
|
+
Los tokens JWT viajan **únicamente en cookies HttpOnly**. Nunca en `localStorage` ni en el body de las respuestas.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Requisitos
|
|
191
|
+
|
|
192
|
+
- **Node.js** 18+
|
|
193
|
+
- **MongoDB** local o [Atlas](https://www.mongodb.com/atlas) (free tier disponible)
|
|
194
|
+
- Cuenta en [Resend](https://resend.com) para emails (free tier: 100 emails/día)
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
60
198
|
## Licencia
|
|
61
199
|
|
|
62
|
-
MIT — el código generado es tuyo, sin restricciones.
|
|
200
|
+
MIT — el código generado es completamente tuyo, sin restricciones de uso comercial.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
<p align="center">
|
|
205
|
+
Hecho en Argentina 🇦🇷
|
|
206
|
+
</p>
|
package/dist/cli.js
CHANGED
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.runCli = runCli;
|
|
7
7
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
|
|
10
|
-
async function runCli() {
|
|
9
|
+
async function runCli(defaultName) {
|
|
11
10
|
console.log(chalk_1.default.bold('\n ar-saas'));
|
|
12
11
|
console.log(chalk_1.default.gray(' Backend NestJS + Frontend Next.js listos para producción\n'));
|
|
13
12
|
const answers = await inquirer_1.default.prompt([
|
|
@@ -15,7 +14,7 @@ async function runCli() {
|
|
|
15
14
|
type: 'input',
|
|
16
15
|
name: 'projectName',
|
|
17
16
|
message: 'Nombre del proyecto:',
|
|
18
|
-
default: 'my-saas',
|
|
17
|
+
default: defaultName ?? 'my-saas',
|
|
19
18
|
validate: (input) => {
|
|
20
19
|
if (!/^[a-z0-9][a-z0-9-]{1,}$/.test(input)) {
|
|
21
20
|
return 'Solo letras minúsculas, números y guiones (mínimo 2 caracteres)';
|
|
@@ -38,13 +37,10 @@ async function runCli() {
|
|
|
38
37
|
name: 'modules',
|
|
39
38
|
message: 'Módulos adicionales:',
|
|
40
39
|
choices: [
|
|
41
|
-
{ name: 'OAuth GitHub/Google + 2FA', value: 'auth-advanced' },
|
|
42
40
|
{ name: 'Notificaciones + Push Web', value: 'notifications' },
|
|
43
41
|
{ name: 'Invoices + Quotes + PDF', value: 'invoices' },
|
|
44
42
|
{ name: 'CRM + Kanban', value: 'crm' },
|
|
45
|
-
{ name: 'MercadoPago suscripciones', value: 'mercadopago' },
|
|
46
43
|
],
|
|
47
|
-
filter: (selected) => Array.from(new Set([...ALWAYS_INCLUDED, ...selected])),
|
|
48
44
|
},
|
|
49
45
|
{
|
|
50
46
|
type: 'list',
|
|
@@ -58,10 +54,5 @@ async function runCli() {
|
|
|
58
54
|
],
|
|
59
55
|
},
|
|
60
56
|
]);
|
|
61
|
-
return
|
|
62
|
-
projectName: answers.projectName,
|
|
63
|
-
stack: answers.stack,
|
|
64
|
-
modules: answers.modules,
|
|
65
|
-
deployTarget: answers.deployTarget,
|
|
66
|
-
};
|
|
57
|
+
return answers;
|
|
67
58
|
}
|
package/dist/generator.js
CHANGED
|
@@ -22,7 +22,6 @@ const TEXT_EXTENSIONS = new Set([
|
|
|
22
22
|
'Dockerfile', 'Makefile', 'Procfile',
|
|
23
23
|
]);
|
|
24
24
|
const SKIP_DIRS = new Set(['.git', 'node_modules', 'dist', '.next', '.turbo', 'build']);
|
|
25
|
-
const PRO_MODULES = new Set(['auth-advanced', 'notifications', 'invoices', 'crm', 'mercadopago']);
|
|
26
25
|
async function generate(config) {
|
|
27
26
|
const projectDir = path_1.default.join(process.cwd(), config.projectName);
|
|
28
27
|
const spinner = (0, ora_1.default)();
|
|
@@ -35,7 +34,6 @@ async function generate(config) {
|
|
|
35
34
|
fs_1.default.mkdirSync(projectDir, { recursive: true });
|
|
36
35
|
const hasBackend = config.stack === 'backend' || config.stack === 'backend-frontend';
|
|
37
36
|
const hasFrontend = config.stack === 'frontend' || config.stack === 'backend-frontend';
|
|
38
|
-
const hasValidPro = [...config.modules].some((m) => PRO_MODULES.has(m));
|
|
39
37
|
if (hasBackend) {
|
|
40
38
|
spinner.text = 'Copiando backend...';
|
|
41
39
|
const src = path_1.default.join(TEMPLATES_DIR, 'backend');
|
|
@@ -46,7 +44,7 @@ async function generate(config) {
|
|
|
46
44
|
}
|
|
47
45
|
else {
|
|
48
46
|
await fs_extra_1.default.copy(src, dest);
|
|
49
|
-
processDir(dest, config
|
|
47
|
+
processDir(dest, config);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
if (hasFrontend) {
|
|
@@ -59,7 +57,7 @@ async function generate(config) {
|
|
|
59
57
|
}
|
|
60
58
|
else {
|
|
61
59
|
await fs_extra_1.default.copy(src, dest);
|
|
62
|
-
processDir(dest, config
|
|
60
|
+
processDir(dest, config);
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
63
|
spinner.text = 'Generando configuración de deploy...';
|
|
@@ -69,12 +67,11 @@ async function generate(config) {
|
|
|
69
67
|
spinner.succeed(chalk_1.default.green(`Proyecto ${chalk_1.default.bold(config.projectName)} creado`));
|
|
70
68
|
printNextSteps(config);
|
|
71
69
|
}
|
|
72
|
-
function processDir(dir, config
|
|
70
|
+
function processDir(dir, config) {
|
|
73
71
|
for (const file of collectTextFiles(dir)) {
|
|
74
72
|
try {
|
|
75
73
|
let content = fs_1.default.readFileSync(file, 'utf-8');
|
|
76
74
|
content = applyNameReplacements(content, config.projectName);
|
|
77
|
-
content = applyProModuleHandling(content, hasValidPro);
|
|
78
75
|
fs_1.default.writeFileSync(file, content, 'utf-8');
|
|
79
76
|
}
|
|
80
77
|
catch {
|
|
@@ -102,17 +99,9 @@ function collectTextFiles(dir) {
|
|
|
102
99
|
}
|
|
103
100
|
function applyNameReplacements(content, projectName) {
|
|
104
101
|
return content
|
|
105
|
-
.replace(/
|
|
106
|
-
.replace(/
|
|
107
|
-
.replace(/
|
|
108
|
-
}
|
|
109
|
-
function applyProModuleHandling(content, hasValidPro) {
|
|
110
|
-
if (hasValidPro) {
|
|
111
|
-
// Uncomment PRO code: remove the "// [PRO] " prefix
|
|
112
|
-
return content.replace(/^(\s*)\/\/ \[PRO\] /gm, '$1');
|
|
113
|
-
}
|
|
114
|
-
// Add explanatory placeholder for PRO lines
|
|
115
|
-
return content.replace(/^(\s*)\/\/ \[PRO\] (.+)$/gm, '$1// [PRO MODULE] $2 — requiere licencia PRO: https://ar-saas.dev');
|
|
102
|
+
.replace(/ar-saas-backend/g, `${projectName}-backend`)
|
|
103
|
+
.replace(/ar-saas-frontend/g, `${projectName}-frontend`)
|
|
104
|
+
.replace(/ar-saas/g, projectName);
|
|
116
105
|
}
|
|
117
106
|
function generateDeployConfig(projectDir, config) {
|
|
118
107
|
if (config.deployTarget === 'later')
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const cli_1 = require("./cli");
|
|
5
5
|
const generator_1 = require("./generator");
|
|
6
6
|
async function main() {
|
|
7
|
-
const
|
|
7
|
+
const defaultName = process.argv[2];
|
|
8
|
+
const config = await (0, cli_1.runCli)(defaultName);
|
|
8
9
|
await (0, generator_1.generate)(config);
|
|
9
10
|
}
|
|
10
11
|
main().catch((error) => {
|