# TRACEABILITY_MATRIX.yml - ERP Core
# Matriz de trazabilidad global: Documentacion -> Codigo
# Ubicacion Canonica: orchestration/inventarios/
# Ultima actualizacion: 2025-12-05

version: "2.1"
project: erp-core
updated_at: "2025-12-05"
updated_by: Requirements-Analyst

# =============================================================================
# PROPOSITO
# =============================================================================
# Este archivo consolida la trazabilidad de TODOS los modulos.
# Cada modulo tiene su propio TRACEABILITY.yml en:
#   docs/XX-fase-YYY/MGN-XXX-name/implementacion/TRACEABILITY.yml
#
# Este archivo es el INDICE MAESTRO que referencia todos.

# =============================================================================
# RESUMEN GLOBAL
# =============================================================================

summary:
  total_modules: 10  # Actualizados en estructura GAMILIT

  requirements:
    total: 46        # 21 Fase 01 + 25 Fase 02
    documented: 46
    implemented: 0
    coverage: 100%

  specifications:
    total: 9         # Solo Fase 01 documentadas
    documented: 9
    implemented: 0
    coverage: 100%

  user_stories:
    total: 17        # Solo Fase 01 documentadas
    documented: 17
    implemented: 0
    coverage: 100%

  implementation:
    database_tables: 59
    backend_endpoints: 148
    frontend_pages: 30
    test_coverage: 0%

# =============================================================================
# MATRIZ POR FASE
# =============================================================================

phases:

  # ---------------------------------------------------------------------------
  # FASE 1: FOUNDATION
  # ---------------------------------------------------------------------------
  - id: "01"
    name: Foundation
    path: docs/01-fase-foundation/
    status: documented
    story_points: 150

    modules:
      # MGN-001: Autenticacion
      - id: MGN-001
        name: Autenticacion
        path: docs/01-fase-foundation/MGN-001-auth/
        status: documented
        story_points: 40
        traceability_file: docs/01-fase-foundation/MGN-001-auth/implementacion/TRACEABILITY.yml

        requirements:
          - {id: RF-AUTH-001, title: "Login Email/Password", status: documented}
          - {id: RF-AUTH-002, title: "Manejo de Tokens JWT", status: documented}
          - {id: RF-AUTH-003, title: "Recuperacion de Password", status: documented}
          - {id: RF-AUTH-004, title: "Proteccion Brute Force", status: documented}
          - {id: RF-AUTH-005, title: "OAuth Social Login", status: documented}
          - {id: RF-AUTH-006, title: "Logout y Revocacion", status: documented}

        specifications:
          - {id: ET-AUTH-001, title: "Backend Auth", rf: [RF-AUTH-001, RF-AUTH-002], status: documented}
          - {id: ET-AUTH-002, title: "Frontend Auth", rf: [RF-AUTH-001], status: documented}
          - {id: ET-AUTH-003, title: "Database Auth", rf: [RF-AUTH-001, RF-AUTH-002], status: documented}

        user_stories:
          - {id: US-MGN001-001, title: "Login con Email/Password", rf: RF-AUTH-001, sp: 8}
          - {id: US-MGN001-002, title: "Logout de Sesion", rf: RF-AUTH-006, sp: 3}
          - {id: US-MGN001-003, title: "Recuperar Password", rf: RF-AUTH-003, sp: 5}
          - {id: US-MGN001-004, title: "Refresh de Token", rf: RF-AUTH-002, sp: 5}
          - {id: US-MGN001-005, title: "Login con Google", rf: RF-AUTH-005, sp: 8}

      # MGN-002: Usuarios
      - id: MGN-002
        name: Usuarios
        path: docs/01-fase-foundation/MGN-002-users/
        status: documented
        story_points: 35
        traceability_file: docs/01-fase-foundation/MGN-002-users/implementacion/TRACEABILITY.yml

        requirements:
          - {id: RF-USERS-001, title: "CRUD de Usuarios", status: documented}
          - {id: RF-USERS-002, title: "Perfil de Usuario", status: documented}
          - {id: RF-USERS-003, title: "Preferencias de Usuario", status: documented}
          - {id: RF-USERS-004, title: "Activacion/Desactivacion", status: documented}
          - {id: RF-USERS-005, title: "Busqueda de Usuarios", status: documented}

      # MGN-003: Roles y Permisos
      - id: MGN-003
        name: Roles y Permisos
        path: docs/01-fase-foundation/MGN-003-roles/
        status: documented
        story_points: 40
        traceability_file: docs/01-fase-foundation/MGN-003-roles/implementacion/TRACEABILITY.yml

        requirements:
          - {id: RF-RBAC-001, title: "Gestion de Roles", status: documented}
          - {id: RF-RBAC-002, title: "Gestion de Permisos", status: documented}
          - {id: RF-RBAC-003, title: "Asignacion Usuario-Rol", status: documented}
          - {id: RF-RBAC-004, title: "Verificacion de Permisos", status: documented}
          - {id: RF-RBAC-005, title: "Roles de Sistema", status: documented}

      # MGN-004: Multi-tenant
      - id: MGN-004
        name: Multi-tenant
        path: docs/01-fase-foundation/MGN-004-tenants/
        status: documented
        story_points: 35
        traceability_file: docs/01-fase-foundation/MGN-004-tenants/implementacion/TRACEABILITY.yml

        requirements:
          - {id: RF-TENANTS-001, title: "CRUD de Tenants", status: documented}
          - {id: RF-TENANTS-002, title: "Configuracion por Tenant", status: documented}
          - {id: RF-TENANTS-003, title: "Planes y Suscripciones", status: documented}
          - {id: RF-TENANTS-004, title: "Aislamiento RLS", status: documented}
          - {id: RF-TENANTS-005, title: "Onboarding de Tenant", status: documented}

  # ---------------------------------------------------------------------------
  # FASE 2: CORE BUSINESS (RF Documentados v2.1)
  # ---------------------------------------------------------------------------
  - id: "02"
    name: Core Business
    path: docs/02-fase-core-business/
    status: rf_documented
    story_points: 190

    modules:
      # MGN-005: Catalogos
      - id: MGN-005
        name: Catalogos Maestros
        path: docs/02-fase-core-business/MGN-005-catalogs/
        status: rf_documented
        story_points: 30
        traceability_file: docs/02-fase-core-business/MGN-005-catalogs/implementacion/TRACEABILITY.yml
        requirements:
          - {id: RF-CATALOG-001, title: "CRUD de Catalogos", status: documented, sp: 8}
          - {id: RF-CATALOG-002, title: "Items de Catalogo", status: documented, sp: 5}
          - {id: RF-CATALOG-003, title: "Catalogos Jerarquicos", status: documented, sp: 5}
          - {id: RF-CATALOG-004, title: "Catalogos de Sistema", status: documented, sp: 5}
          - {id: RF-CATALOG-005, title: "Busqueda y Filtrado", status: documented, sp: 5}

      # MGN-006: Settings
      - id: MGN-006
        name: Settings
        path: docs/02-fase-core-business/MGN-006-settings/
        status: rf_documented
        story_points: 25
        traceability_file: docs/02-fase-core-business/MGN-006-settings/implementacion/TRACEABILITY.yml
        requirements:
          - {id: RF-SETTINGS-001, title: "Configuracion del Sistema", status: documented, sp: 8}
          - {id: RF-SETTINGS-002, title: "Configuracion por Tenant", status: documented, sp: 8}
          - {id: RF-SETTINGS-003, title: "Preferencias de Usuario", status: documented, sp: 5}
          - {id: RF-SETTINGS-004, title: "Feature Flags", status: documented, sp: 5}

      # MGN-007: Audit
      - id: MGN-007
        name: Audit
        path: docs/02-fase-core-business/MGN-007-audit/
        status: rf_documented
        story_points: 30
        traceability_file: docs/02-fase-core-business/MGN-007-audit/implementacion/TRACEABILITY.yml
        requirements:
          - {id: RF-AUDIT-001, title: "Audit Trail", status: documented, sp: 10}
          - {id: RF-AUDIT-002, title: "Access Logs", status: documented, sp: 8}
          - {id: RF-AUDIT-003, title: "Security Events", status: documented, sp: 8}
          - {id: RF-AUDIT-004, title: "Consultas y Reportes", status: documented, sp: 5}

      # MGN-008: Notifications
      - id: MGN-008
        name: Notifications
        path: docs/02-fase-core-business/MGN-008-notifications/
        status: rf_documented
        story_points: 25
        traceability_file: docs/02-fase-core-business/MGN-008-notifications/implementacion/TRACEABILITY.yml
        requirements:
          - {id: RF-NOTIF-001, title: "Notificaciones In-App", status: documented, sp: 8}
          - {id: RF-NOTIF-002, title: "Notificaciones Email", status: documented, sp: 8}
          - {id: RF-NOTIF-003, title: "Notificaciones Push", status: documented, sp: 5}
          - {id: RF-NOTIF-004, title: "Preferencias de Notificacion", status: documented, sp: 5}

      # MGN-009: Reports
      - id: MGN-009
        name: Reports
        path: docs/02-fase-core-business/MGN-009-reports/
        status: rf_documented
        story_points: 35
        traceability_file: docs/02-fase-core-business/MGN-009-reports/implementacion/TRACEABILITY.yml
        requirements:
          - {id: RF-REPORT-001, title: "Reportes Predefinidos", status: documented, sp: 10}
          - {id: RF-REPORT-002, title: "Dashboards", status: documented, sp: 10}
          - {id: RF-REPORT-003, title: "Report Builder", status: documented, sp: 10}
          - {id: RF-REPORT-004, title: "Reportes Programados", status: documented, sp: 5}

      # MGN-010: Financial
      - id: MGN-010
        name: Financial Base
        path: docs/02-fase-core-business/MGN-010-financial/
        status: rf_documented
        story_points: 45
        traceability_file: docs/02-fase-core-business/MGN-010-financial/implementacion/TRACEABILITY.yml
        requirements:
          - {id: RF-FIN-001, title: "Plan de Cuentas", status: documented, sp: 13}
          - {id: RF-FIN-002, title: "Monedas y Tipos de Cambio", status: documented, sp: 10}
          - {id: RF-FIN-003, title: "Periodos Contables", status: documented, sp: 10}
          - {id: RF-FIN-004, title: "Asientos Contables", status: documented, sp: 13}

  # ---------------------------------------------------------------------------
  # FASES FUTURAS - Pendiente Definicion
  # ---------------------------------------------------------------------------
  # Las fases Extended y SaaS seran definidas cuando se complete
  # la documentacion de Fase 02 Core Business

# =============================================================================
# RESUMEN DE RF POR FASE
# =============================================================================

requirements_summary:
  fase_01_foundation:
    total_rf: 21
    total_et: 9
    total_us: 17
    modules:
      - {id: MGN-001, name: Auth, rf: 6, et: 3, us: 5}
      - {id: MGN-002, name: Users, rf: 5, et: 2, us: 4}
      - {id: MGN-003, name: Roles, rf: 5, et: 2, us: 4}
      - {id: MGN-004, name: Tenants, rf: 5, et: 2, us: 4}

  fase_02_core_business:
    total_rf: 25
    total_et: 0
    total_us: 0
    modules:
      - {id: MGN-005, name: Catalogs, rf: 5, et: 0, us: 0}
      - {id: MGN-006, name: Settings, rf: 4, et: 0, us: 0}
      - {id: MGN-007, name: Audit, rf: 4, et: 0, us: 0}
      - {id: MGN-008, name: Notifications, rf: 4, et: 0, us: 0}
      - {id: MGN-009, name: Reports, rf: 4, et: 0, us: 0}
      - {id: MGN-010, name: Financial, rf: 4, et: 0, us: 0}

# =============================================================================
# VALIDACIONES
# =============================================================================

validations:
  orphan_requirements:
    description: "RF sin ET ni US asociada"
    count: 25
    items:
      - {module: MGN-005, rf: 5, reason: "Fase 02 - ET pendiente"}
      - {module: MGN-006, rf: 4, reason: "Fase 02 - ET pendiente"}
      - {module: MGN-007, rf: 4, reason: "Fase 02 - ET pendiente"}
      - {module: MGN-008, rf: 4, reason: "Fase 02 - ET pendiente"}
      - {module: MGN-009, rf: 4, reason: "Fase 02 - ET pendiente"}
      - {module: MGN-010, rf: 4, reason: "Fase 02 - ET pendiente"}

  orphan_code:
    description: "Codigo sin traza a RF"
    count: 0
    items: []

  incomplete_traces:
    description: "Cadenas RF->ET->US incompletas"
    count: 5
    items:
      - {rf: RF-AUTH-005, missing: "US completa"}
      - {rf: RF-USERS-004, missing: "ET, US"}
      - {rf: RF-USERS-005, missing: "ET, US"}
      - {rf: RF-RBAC-004, missing: "US completa"}
      - {rf: RF-RBAC-005, missing: "US completa"}

# =============================================================================
# METRICAS
# =============================================================================

metrics:
  traceability_coverage:
    rf_to_et: 46%       # 21/46 RF tienen ET
    et_to_us: 100%      # Todas las ET tienen US
    us_to_code: 0%      # Sin implementacion
    overall: 49%

  documentation_status:
    complete: 4         # MGN-001 a MGN-004 (RF+ET+US)
    rf_documented: 6    # MGN-005 a MGN-010 (solo RF)
    planned: 0          # Fases futuras a definir

  implementation_status:
    implemented: 0
    in_progress: 0
    pending: 10

# =============================================================================
# HISTORIAL
# =============================================================================

history:
  - date: "2025-12-05"
    action: "Creacion de matriz de trazabilidad global"
    author: Requirements-Analyst
    changes:
      - "Documentada trazabilidad de Fase Foundation (MGN-001 a MGN-004)"
      - "Agregadas validaciones de trazas huerfanas"
      - "Definidas metricas de cobertura"

  - date: "2025-12-05"
    action: "Actualizacion v2.0 - Reestructuracion GAMILIT"
    author: Requirements-Analyst
    changes:
      - "Actualizada Fase 02 Core Business (MGN-005 a MGN-010)"
      - "Simplificadas fases futuras (pendiente definicion)"
      - "Actualizadas metricas de cobertura"

  - date: "2025-12-05"
    action: "Actualizacion v2.1 - RF Documentados Fase 02"
    author: Requirements-Analyst
    changes:
      - "RF-SETTINGS-001 a 004: Configuraciones"
      - "RF-AUDIT-001 a 004: Auditoria"
      - "RF-NOTIF-001 a 004: Notificaciones"
      - "RF-REPORT-001 a 004: Reportes"
      - "RF-FIN-001 a 004: Base Financiera"
      - "Total: 25 RF documentados en Fase 02"
      - "Total global: 46 RF documentados"
