Sistema de marketing multinivel para redes de distribuidores/afiliados. Soporta estructuras jerarquicas (binario, unilevel, matriz), comisiones por niveles, bonos por objetivos, y visualizacion de red. Extiende el modulo de Commissions.
Objetivos
Estructuras de red configurables
Comisiones por niveles (downline)
Bonos por rangos y objetivos
Visualizacion de arbol de red
Reportes de estructura y earnings
Alcance
Incluido
Estructuras: Unilevel, Binario, Matriz
Comisiones multinivel (N niveles)
Sistema de rangos/calificaciones
Bonos por rango y periodo
Visualizacion de red (arbol)
Dashboard de distribuidor
Reportes de red y earnings
Excluido
Planes de compensacion predefinidos
Integracion con pagos automaticos
Compliance regulatorio automatico
Modelo de Datos
Schema: mlm
-- Configuracion de estructura
CREATETABLEmlm.structures(idUUIDPRIMARYKEYDEFAULTgen_random_uuid(),tenant_idUUIDNOTNULLREFERENCEStenants.tenants(id),nameVARCHAR(100)NOTNULL,typemlm.structure_typeNOTNULL,-- Configuracion por tipo
configJSONBNOTNULLDEFAULT'{}',-- Unilevel: { max_width: null, max_depth: 10 }
-- Binary: { spillover: 'left_first' | 'weak_leg' }
-- Matrix: { width: 3, depth: 7 }
-- Comisiones por nivel
level_ratesJSONBNOTNULLDEFAULT'[]',-- [{ level: 1, rate: 0.10 }, { level: 2, rate: 0.05 }, ...]
is_activeBOOLEANDEFAULTtrue,created_atTIMESTAMPTZDEFAULTNOW());-- Nodos de la red (distribuidores)
CREATETABLEmlm.nodes(idUUIDPRIMARYKEYDEFAULTgen_random_uuid(),tenant_idUUIDNOTNULLREFERENCEStenants.tenants(id),structure_idUUIDNOTNULLREFERENCESmlm.structures(id),user_idUUIDNOTNULLREFERENCESusers.users(id),-- Jerarquia
parent_idUUIDREFERENCESmlm.nodes(id),sponsor_idUUIDREFERENCESmlm.nodes(id),-- Quien lo refirio
positionINTEGER,-- Para binario: 1=left, 2=right
-- Path materializado para consultas eficientes
pathLTREE,depthINTEGERDEFAULT0,-- Rango actual
rank_idUUIDREFERENCESmlm.ranks(id),highest_rank_idUUIDREFERENCESmlm.ranks(id),-- Metricas
personal_volumeDECIMAL(15,2)DEFAULT0,group_volumeDECIMAL(15,2)DEFAULT0,direct_referralsINTEGERDEFAULT0,total_downlineINTEGERDEFAULT0,-- Estado
statusmlm.node_statusNOTNULLDEFAULT'active',joined_atTIMESTAMPTZDEFAULTNOW(),created_atTIMESTAMPTZDEFAULTNOW(),updated_atTIMESTAMPTZDEFAULTNOW(),CONSTRAINTunique_user_structureUNIQUE(structure_id,user_id));-- Rangos/Calificaciones
CREATETABLEmlm.ranks(idUUIDPRIMARYKEYDEFAULTgen_random_uuid(),tenant_idUUIDNOTNULLREFERENCEStenants.tenants(id),structure_idUUIDNOTNULLREFERENCESmlm.structures(id),nameVARCHAR(100)NOTNULL,levelINTEGERNOTNULL,-- 1=Bronze, 2=Silver, etc.
badge_urlVARCHAR(500),-- Requisitos para alcanzar
requirementsJSONBNOTNULLDEFAULT'{}',-- {
-- personal_volume: 1000,
-- group_volume: 10000,
-- direct_referrals: 3,
-- active_legs: 2,
-- rank_in_legs: { rank_level: 2, count: 1 }
-- }
-- Beneficios
bonus_rateDECIMAL(10,4),-- Bono adicional por rango
benefitsJSONBDEFAULT'{}',is_activeBOOLEANDEFAULTtrue,created_atTIMESTAMPTZDEFAULTNOW());-- Comisiones MLM (extiende commissions.entries)
CREATETABLEmlm.commissions(idUUIDPRIMARYKEYDEFAULTgen_random_uuid(),tenant_idUUIDNOTNULLREFERENCEStenants.tenants(id),node_idUUIDNOTNULLREFERENCESmlm.nodes(id),source_node_idUUIDNOTNULLREFERENCESmlm.nodes(id),-- Quien genero
-- Tipo de comision
typemlm.commission_typeNOTNULL,-- Nivel de diferencia
levelINTEGERNOTNULL,-- 1 = directo, 2 = segundo nivel, etc.
-- Montos
source_amountDECIMAL(15,2)NOTNULL,rate_appliedDECIMAL(10,4)NOTNULL,commission_amountDECIMAL(15,2)NOTNULL,currencyVARCHAR(3)DEFAULT'USD',-- Periodo
period_idUUIDREFERENCEScommissions.periods(id),statusmlm.commission_statusNOTNULLDEFAULT'pending',created_atTIMESTAMPTZDEFAULTNOW());-- Bonos por rango
CREATETABLEmlm.bonuses(idUUIDPRIMARYKEYDEFAULTgen_random_uuid(),tenant_idUUIDNOTNULLREFERENCEStenants.tenants(id),node_idUUIDNOTNULLREFERENCESmlm.nodes(id),rank_idUUIDNOTNULLREFERENCESmlm.ranks(id),typemlm.bonus_typeNOTNULL,amountDECIMAL(15,2)NOTNULL,currencyVARCHAR(3)DEFAULT'USD',period_idUUIDREFERENCEScommissions.periods(id),statusmlm.commission_statusNOTNULLDEFAULT'pending',achieved_atTIMESTAMPTZDEFAULTNOW(),created_atTIMESTAMPTZDEFAULTNOW());-- Historial de rangos
CREATETABLEmlm.rank_history(idUUIDPRIMARYKEYDEFAULTgen_random_uuid(),node_idUUIDNOTNULLREFERENCESmlm.nodes(id),rank_idUUIDNOTNULLREFERENCESmlm.ranks(id),achieved_atTIMESTAMPTZDEFAULTNOW());-- Enums
CREATETYPEmlm.structure_typeASENUM('unilevel','binary','matrix','hybrid');CREATETYPEmlm.node_statusASENUM('pending','active','inactive','suspended');CREATETYPEmlm.commission_typeASENUM('level','matching','infinity','leadership','pool');CREATETYPEmlm.commission_statusASENUM('pending','approved','paid','cancelled');CREATETYPEmlm.bonus_typeASENUM('rank_achievement','rank_maintenance','fast_start','pool_share');
Indices especiales
-- Indice para LTREE (path materializado)
CREATEINDEXidx_nodes_pathONmlm.nodesUSINGGIST(path);-- Para buscar downline
CREATEINDEXidx_nodes_parentONmlm.nodes(parent_id);CREATEINDEXidx_nodes_sponsorONmlm.nodes(sponsor_id);
Endpoints API
Structures
Metodo
Endpoint
Descripcion
GET
/mlm/structures
Listar estructuras
POST
/mlm/structures
Crear estructura
GET
/mlm/structures/:id
Obtener estructura
PATCH
/mlm/structures/:id
Actualizar estructura
Nodes
Metodo
Endpoint
Descripcion
GET
/mlm/nodes
Listar nodos
POST
/mlm/nodes
Crear nodo (registrar)
GET
/mlm/nodes/:id
Obtener nodo
GET
/mlm/nodes/:id/downline
Obtener downline
GET
/mlm/nodes/:id/upline
Obtener upline
GET
/mlm/nodes/:id/tree
Arbol visual
PATCH
/mlm/nodes/:id/status
Cambiar estado
Ranks
Metodo
Endpoint
Descripcion
GET
/mlm/ranks
Listar rangos
POST
/mlm/ranks
Crear rango
GET
/mlm/ranks/:id
Obtener rango
PATCH
/mlm/ranks/:id
Actualizar rango
POST
/mlm/ranks/evaluate
Evaluar calificaciones
Commissions
Metodo
Endpoint
Descripcion
GET
/mlm/commissions
Listar comisiones MLM
POST
/mlm/commissions/calculate
Calcular comisiones
GET
/mlm/commissions/by-level
Por nivel
My Network (Distribuidor)
Metodo
Endpoint
Descripcion
GET
/mlm/my/dashboard
Dashboard personal
GET
/mlm/my/network
Mi red
GET
/mlm/my/earnings
Mis ganancias
GET
/mlm/my/rank
Mi rango y progreso
POST
/mlm/my/invite
Generar link de invitacion
Frontend
Paginas
/mlm - Dashboard MLM
/mlm/network - Visualizacion de red
/mlm/structures - Configuracion estructuras
/mlm/ranks - Gestion de rangos
/mlm/commissions - Comisiones MLM
/mlm/my - Portal distribuidor
Componentes
NetworkTree - Arbol de red interactivo
BinaryTree - Visualizacion binaria
UnivelTree - Visualizacion unilevel
NodeCard - Tarjeta de nodo
RankBadge - Badge de rango
RankProgress - Progreso hacia siguiente rango
DownlineList - Lista de downline
EarningsBreakdown - Desglose de ganancias
InviteLink - Generador de link
StructureConfig - Configuracion de estructura
LevelRatesEditor - Editor de comisiones por nivel
Hooks
useStructures - CRUD estructuras
useNodes - CRUD nodos
useRanks - CRUD rangos
useMyNetwork - Red del usuario actual
useNetworkTree - Datos del arbol
useMLMCommissions - Comisiones MLM
Dependencias
Modulos Requeridos
SAAS-001 Auth
SAAS-002 Tenants
SAAS-003 Users
SAAS-020 Commissions (base)
Modulos Opcionales
SAAS-018 Sales (ventas como fuente)
SAAS-019 Portfolio (productos)
SAAS-022 Goals (objetivos por rango)
Criterios de Aceptacion
Estructuras unilevel y binario funcionales
Registro de nodos con sponsor
Calculo de comisiones por niveles
Sistema de rangos con requisitos
Visualizacion de arbol interactivo
Dashboard de distribuidor completo
Reportes de red y earnings
Tests unitarios (>70% coverage)
Estimacion
Componente
SP
DDL + Entities
4
Backend Services
6
Controllers + DTOs
3
Frontend Pages
4
Frontend Components (Tree)
3
Tests
1
Total
21
Ultima actualizacion: 2026-01-24
Autor: Claude Opus 4.5