erp-core/docs/02-fase-core-business/MGN-006-settings/requerimientos/RF-SETTINGS-001.md

5.4 KiB

RF-SETTINGS-001: Configuraciones del Sistema

Identificacion

Campo Valor
ID RF-SETTINGS-001
Modulo MGN-006 Settings
Titulo Configuraciones del Sistema
Prioridad P0 - Critica
Estado Draft
Fecha 2025-12-05

Descripcion

El sistema debe permitir gestionar configuraciones globales a nivel de sistema que afectan el comportamiento de la aplicacion para todos los tenants. Estas configuraciones son administradas exclusivamente por super-administradores.


Requisitos Funcionales

RF-SETTINGS-001.1: Estructura de Configuracion

Cada configuracion del sistema tiene la siguiente estructura:

Campo Tipo Descripcion
id UUID Identificador unico
key VARCHAR(100) Clave unica de configuracion
value JSONB Valor de la configuracion
data_type ENUM Tipo de dato (string, number, boolean, json, array)
category VARCHAR(50) Categoria agrupadora
description TEXT Descripcion para UI
is_public BOOLEAN Visible para tenants (solo lectura)
is_editable BOOLEAN Puede ser modificado en runtime
default_value JSONB Valor por defecto
validation_rules JSONB Reglas de validacion

RF-SETTINGS-001.2: Categorias de Configuracion

Las configuraciones se organizan en categorias:

Categoria Descripcion Ejemplo
security Configuraciones de seguridad Intentos de login, duracion token
email Configuracion de correo SMTP, templates
storage Almacenamiento Limites de archivos, paths
features Feature flags Habilitar/deshabilitar funciones
integrations Integraciones externas API keys, webhooks
performance Rendimiento Cache TTL, pagination limits

RF-SETTINGS-001.3: Tipos de Datos Soportados

enum SettingDataType {
  STRING = 'string',
  NUMBER = 'number',
  BOOLEAN = 'boolean',
  JSON = 'json',
  ARRAY = 'array',
  SECRET = 'secret'  // Encriptado en BD
}

Reglas:

  • Tipo SECRET se almacena encriptado y nunca se retorna completo
  • Tipo JSON debe cumplir con schema definido en validation_rules
  • Tipo ARRAY puede contener elementos de cualquier tipo primitivo

RF-SETTINGS-001.4: Validacion de Valores

Cada configuracion puede tener reglas de validacion:

interface ValidationRules {
  required?: boolean;
  min?: number;          // Para numeros
  max?: number;          // Para numeros
  minLength?: number;    // Para strings
  maxLength?: number;    // Para strings
  pattern?: string;      // Regex para strings
  enum?: any[];          // Valores permitidos
  schema?: object;       // JSON Schema para objetos
}

RF-SETTINGS-001.5: Configuraciones Predefinidas

El sistema incluye configuraciones iniciales:

const SYSTEM_SETTINGS = [
  {
    key: 'security.max_login_attempts',
    value: 5,
    dataType: 'number',
    category: 'security',
    isEditable: true
  },
  {
    key: 'security.lockout_duration_minutes',
    value: 15,
    dataType: 'number',
    category: 'security'
  },
  {
    key: 'security.token_expiry_hours',
    value: 24,
    dataType: 'number',
    category: 'security'
  },
  {
    key: 'email.smtp_host',
    value: '',
    dataType: 'string',
    category: 'email'
  },
  {
    key: 'storage.max_file_size_mb',
    value: 10,
    dataType: 'number',
    category: 'storage'
  },
  {
    key: 'features.enable_oauth',
    value: true,
    dataType: 'boolean',
    category: 'features'
  }
];

Operaciones CRUD

Listar Configuraciones

GET /api/v1/settings/system?category=security

Response:
{
  "data": [
    {
      "key": "security.max_login_attempts",
      "value": 5,
      "dataType": "number",
      "category": "security",
      "description": "Numero maximo de intentos de login",
      "isEditable": true
    }
  ]
}

Obtener Configuracion

GET /api/v1/settings/system/:key

Response:
{
  "key": "security.max_login_attempts",
  "value": 5,
  "dataType": "number",
  "isEditable": true,
  "defaultValue": 5,
  "validationRules": { "min": 1, "max": 10 }
}

Actualizar Configuracion

PUT /api/v1/settings/system/:key
{
  "value": 3
}

Response:
{
  "key": "security.max_login_attempts",
  "value": 3,
  "previousValue": 5,
  "updatedAt": "2025-12-05T10:00:00Z",
  "updatedBy": "admin-uuid"
}

Restaurar Valor por Defecto

POST /api/v1/settings/system/:key/reset

Response:
{
  "key": "security.max_login_attempts",
  "value": 5,
  "restoredFrom": 3
}

Reglas de Negocio

ID Regla Severidad
BR-001 Solo super-admin puede modificar configuraciones del sistema Error
BR-002 Configuraciones no editables no pueden modificarse Error
BR-003 Valor debe cumplir reglas de validacion Error
BR-004 Tipo SECRET nunca se retorna completo (solo ****) Security
BR-005 Cambios se registran en audit log Info

Criterios de Aceptacion

  • CRUD completo de configuraciones del sistema
  • Validacion de tipos de datos
  • Encriptacion de valores tipo SECRET
  • Solo super-admin puede modificar
  • Restaurar a valor por defecto
  • Agrupacion por categorias en UI
  • Audit log de cambios

Historial

Version Fecha Autor Cambios
1.0 2025-12-05 Requirements-Analyst Creacion inicial