Backlog MGN-004: Multi-Tenancy
Resumen del Modulo
| Campo |
Valor |
| Modulo |
MGN-004 |
| Nombre |
Multi-Tenancy |
| Total User Stories |
4 |
| Total Story Points |
47 |
| Estado |
Ready for Development |
| Fecha |
2025-12-05 |
User Stories
Arquitectura Multi-Tenant
┌─────────────────────────────────────────────────────────────────┐
│ Request Flow │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 1. HTTP Request │
│ └─> Authorization: Bearer {JWT} │
│ │
│ 2. JwtAuthGuard │
│ └─> Valida token, extrae user + tenant_id │
│ │
│ 3. TenantGuard (US-MGN004-003) │
│ └─> Verifica tenant activo │
│ └─> Inyecta tenant en request │
│ │
│ 4. TenantContextMiddleware (US-MGN004-003) │
│ └─> SET app.current_tenant_id = :tenantId │
│ │
│ 5. LimitGuard (US-MGN004-004) │
│ └─> Verifica limites de subscripcion │
│ │
│ 6. ModuleGuard (US-MGN004-004) │
│ └─> Verifica acceso al modulo │
│ │
│ 7. RbacGuard (MGN-003) │
│ └─> Valida permisos del usuario │
│ │
│ 8. Controller -> Service -> Repository │
│ │
│ 9. PostgreSQL RLS (US-MGN004-003) │
│ └─> WHERE tenant_id = current_tenant_id() │
│ │
└─────────────────────────────────────────────────────────────────┘
Estados del Tenant
┌──────────────┐
│ created │
└──────┬───────┘
│ (start trial)
▼
┌──────────────┐
┌──────────│ trial │──────────┐
│ └──────┬───────┘ │
│ │ │
│ (pay) │ (expire) │ (convert)
│ │ │
│ ▼ │
│ ┌──────────────┐ │
│ │trial_expired │ │
│ └──────────────┘ │
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│ active │◄────────────────────│ active │
└──────┬───────┘ (reactivate) └──────┬───────┘
│ │
│ (suspend) │
▼ │
┌──────────────┐ │
│ suspended │────────────────────────────┘
└──────┬───────┘
│ (schedule delete)
▼
┌──────────────────┐
│ pending_deletion │
└────────┬─────────┘
│ (30 days)
▼
┌──────────────┐
│ deleted │
└──────────────┘
Planes de Subscripcion
| Plan |
Usuarios |
Storage |
Precio |
| Trial |
5 |
1 GB |
Gratis (14 dias) |
| Starter |
10 |
5 GB |
$29/mes |
| Professional |
50 |
25 GB |
$99/mes |
| Enterprise |
Ilimitado |
100 GB |
$299/mes |
Distribucion de Story Points
US-MGN004-001 (Gestion Tenants): ████████████████████████████ 13 SP (28%)
US-MGN004-002 (Configuracion): █████████████████ 8 SP (17%)
US-MGN004-003 (Aislamiento RLS): ████████████████████████████ 13 SP (28%)
US-MGN004-004 (Subscripciones): ████████████████████████████ 13 SP (28%)
─────────────────────────────
Total: 47 SP
Orden de Implementacion Recomendado
-
US-MGN004-003 - Aislamiento de Datos (Base para todo)
- RLS policies
- TenantGuard
- TenantContextMiddleware
- TenantBaseEntity
-
US-MGN004-001 - Gestion de Tenants (CRUD basico)
- Entidad Tenant
- TenantsService
- Platform Admin endpoints
-
US-MGN004-002 - Configuracion de Tenant
- TenantSettings
- Upload de logos
- Merge con defaults
-
US-MGN004-004 - Subscripciones y Limites (Monetizacion)
- Plans, Subscriptions
- LimitGuard, ModuleGuard
- Billing integration
Dependencias con Otros Modulos
| Modulo |
Dependencia |
| MGN-001 Auth |
JWT debe incluir tenant_id claim |
| MGN-002 Users |
Users deben tener tenant_id |
| MGN-003 RBAC |
Roles son per-tenant, permisos de platform admin |
Riesgos Identificados
| Riesgo |
Mitigacion |
| RLS mal configurado expone datos |
Tests exhaustivos de aislamiento |
| Performance con muchos tenants |
Indices compuestos, caching |
| Migracion de datos existentes |
Script de migracion con tenant default |
| Complejidad de billing |
Integracion con Stripe (proven) |
Definition of Done del Modulo
Metricas de Exito
| Metrica |
Objetivo |
| Tiempo de respuesta (con RLS) |
< 100ms p95 |
| Tests de aislamiento |
100% pass |
| Cobertura de tests |
> 80% |
| Vulnerabilidades cross-tenant |
0 |
Historial
| Version |
Fecha |
Autor |
Cambios |
| 1.0 |
2025-12-05 |
System |
Creacion inicial con 4 US |