erp-core/docs/01-fase-foundation/MGN-004-tenants/_MAP.md

3.9 KiB

_MAP: MGN-004 - Multi-tenant

Modulo: MGN-004 Nombre: Multi-tenant Fase: 01 - Foundation Story Points: 35 SP Estado: Migrado GAMILIT Ultima actualizacion: 2025-12-05


Resumen

Sistema de multi-tenancy que permite aislar datos por organizacion/empresa, con configuracion independiente por tenant y soporte para planes de suscripcion.


Metricas

Metrica Valor
Story Points 35 SP
Requerimientos (RF) 4
Especificaciones (ET) 2
User Stories (US) 4
Tablas DB 4
Endpoints API 25

Requerimientos Funcionales (4)

ID Archivo Titulo Prioridad Estado
RF-TENANT-001 RF-TENANT-001.md CRUD de Tenants P0 Migrado
RF-TENANT-002 RF-TENANT-002.md Configuracion por Tenant P0 Migrado
RF-TENANT-003 RF-TENANT-003.md Planes y Suscripciones P1 Migrado
RF-TENANT-004 RF-TENANT-004.md Aislamiento RLS P0 Migrado

Indice: INDICE-RF-TENANT.md


Especificaciones Tecnicas (2)

ID Archivo Titulo RF Asociados Estado
ET-TENANTS-001 ET-tenants-backend.md Backend Tenants RF-TENANT-001 a RF-TENANT-004 Migrado
ET-TENANTS-002 ET-TENANT-database.md Database Tenants RF-TENANT-001 a RF-TENANT-004 Migrado

Historias de Usuario (4)

ID Archivo Titulo RF SP Estado
US-MGN004-001 US-MGN004-001.md Crear Tenant RF-TENANT-001 8 Migrado
US-MGN004-002 US-MGN004-002.md Configurar Tenant RF-TENANT-002 5 Migrado
US-MGN004-003 US-MGN004-003.md Gestionar Suscripcion RF-TENANT-003 8 Migrado
US-MGN004-004 US-MGN004-004.md Cambiar Plan RF-TENANT-003 5 Migrado

Backlog: BACKLOG-MGN004.md


Implementacion

Database

Objeto Tipo Schema
tenants Tabla core_tenants
tenant_settings Tabla core_tenants
plans Tabla core_tenants
subscriptions Tabla core_tenants
RLS Policies Policy Todos los schemas

Backend

Objeto Tipo Path
TenantsModule Module src/modules/tenants/
TenantsService Service src/modules/tenants/tenants.service.ts
SubscriptionsService Service src/modules/tenants/subscriptions.service.ts
TenantMiddleware Middleware src/modules/tenants/tenant.middleware.ts
TenantGuard Guard src/modules/tenants/guards/tenant.guard.ts

Frontend

Objeto Tipo Path
TenantsPage Page src/features/tenants/pages/TenantsPage.tsx
TenantSettingsPage Page src/features/tenants/pages/TenantSettingsPage.tsx
OnboardingPage Page src/features/tenants/pages/OnboardingPage.tsx

Aislamiento RLS

-- Cada tabla con tenant_id tiene RLS policy:
CREATE POLICY tenant_isolation ON {table}
    USING (tenant_id = current_setting('app.current_tenant_id')::uuid);

-- El middleware establece el contexto:
SET LOCAL app.current_tenant_id = '{tenant_uuid}';

Dependencias

Depende de: MGN-001 (Auth), MGN-002 (Users), MGN-003 (Roles)

Requerido por: Todos los modulos de negocio (catalogos, ventas, compras, etc.)


Trazabilidad

Ver: TRACEABILITY.yml


Generado por: Requirements-Analyst Fecha: 2025-12-05