# Analisis de Dependencias entre Archivos - FASE 4 **Fecha**: 2026-01-06 **Ejecutor**: PERFIL_ORQUESTADOR --- ## Objetivo Documentar las dependencias entre archivos que seran modificados en FASE 2, identificando el orden correcto de modificacion y posibles conflictos. --- ## 1. MAPA DE ARCHIVOS A MODIFICAR ### 1.1 Backend (apps/backend/) ``` apps/backend/ ├── src/ │ ├── main.ts [MODIFICAR - Puerto] │ ├── app.module.ts [MODIFICAR - TypeORM config] │ ├── common/ │ │ └── middleware/ │ │ └── tenant.middleware.ts [CREAR - RLS] │ └── modules/ │ └── auth/ │ └── entities/ │ ├── tenant.entity.ts [VERIFICAR - Schema sync] │ └── user.entity.ts [VERIFICAR - Schema sync] ├── .env [CREAR/MODIFICAR] └── .env.example [ACTUALIZAR] ``` ### 1.2 Frontend (apps/frontend/) ``` apps/frontend/ ├── src/ │ ├── main.tsx [SIN CAMBIOS] │ ├── App.tsx [MODIFICAR - Rutas auth] │ ├── lib/ │ │ └── api.ts [MODIFICAR - Interceptors] │ ├── contexts/ │ │ └── AuthContext.tsx [CREAR] │ ├── pages/ │ │ ├── Login.tsx [CREAR] │ │ ├── Register.tsx [CREAR] │ │ ├── Dashboard.tsx [MODIFICAR - API real] │ │ ├── Products.tsx [MODIFICAR - API real] │ │ ├── Orders.tsx [MODIFICAR - API real] │ │ ├── Customers.tsx [MODIFICAR - API real] │ │ ├── Fiado.tsx [MODIFICAR - API real] │ │ ├── Inventory.tsx [MODIFICAR - API real] │ │ └── Settings.tsx [MODIFICAR - API real] │ └── components/ │ └── Layout.tsx [MODIFICAR - Auth nav] ├── vite.config.ts [MODIFICAR - Proxy] └── .env [CREAR] ``` ### 1.3 WhatsApp Service (apps/whatsapp-service/) ``` apps/whatsapp-service/ ├── src/ │ ├── main.ts [MODIFICAR - Puerto] │ └── webhook/ │ └── webhook.service.ts [MODIFICAR - Backend calls] └── .env [ACTUALIZAR] ``` ### 1.4 MCP Server (apps/mcp-server/) ``` apps/mcp-server/ ├── src/ │ └── index.ts [MODIFICAR - Backend URL] └── .env [CREAR/ACTUALIZAR] ``` --- ## 2. GRAFO DE DEPENDENCIAS ### 2.1 Dependencias Backend ``` .env (DB credentials) │ ▼ app.module.ts (TypeORM import) │ ├──────────────────────────────────┐ │ │ ▼ ▼ tenant.middleware.ts entity/*.ts │ │ └──────────┬───────────────────────┘ │ ▼ main.ts (middleware registration) ``` **Orden de modificacion Backend**: 1. `.env` - Credenciales DB 2. `app.module.ts` - TypeORM config 3. `*.entity.ts` - Verificar schemas 4. `tenant.middleware.ts` - Crear nuevo 5. `main.ts` - Puerto y middleware ### 2.2 Dependencias Frontend ``` .env (API URL) │ ▼ vite.config.ts (proxy) │ ▼ api.ts (axios config) │ ▼ AuthContext.tsx (estado auth) │ ├────────────────────────────────────────────┐ │ │ ▼ ▼ App.tsx (rutas) Layout.tsx (nav) │ ├──► Login.tsx ├──► Register.tsx ├──► Dashboard.tsx ├──► Products.tsx ├──► Orders.tsx ├──► Customers.tsx ├──► Fiado.tsx ├──► Inventory.tsx └──► Settings.tsx ``` **Orden de modificacion Frontend**: 1. `.env` - API URL 2. `vite.config.ts` - Proxy 3. `api.ts` - Interceptors 4. `AuthContext.tsx` - Crear 5. `Login.tsx` - Crear 6. `Register.tsx` - Crear 7. `App.tsx` - Rutas 8. `Layout.tsx` - Nav auth 9. Pages (paralelo) ### 2.3 Dependencias WhatsApp Service ``` .env (Backend URL, WhatsApp tokens) │ ▼ main.ts (puerto) │ ▼ webhook.service.ts (backend calls) ``` **Orden**: `.env` → `main.ts` → `webhook.service.ts` ### 2.4 Dependencias MCP Server ``` .env (Backend URL) │ ▼ index.ts (URL config) ``` **Orden**: `.env` → `index.ts` --- ## 3. DEPENDENCIAS CROSS-PROJECT ### 3.1 Backend ← Otros Servicios ``` ┌── Frontend (api.ts) │ Backend (main.ts) ◄─┼── WhatsApp Service (webhook.service.ts) │ └── MCP Server (index.ts) ``` **Implicacion**: Backend DEBE estar funcionando antes de probar otros servicios ### 3.2 Database ← Backend ``` PostgreSQL (schemas DDL) │ ▼ Backend (TypeORM) ``` **Implicacion**: Database DEBE tener schemas creados antes de iniciar backend --- ## 4. ARCHIVOS CRITICOS Y SU IMPACTO ### 4.1 Archivos de Alto Impacto (Riesgo Alto) | Archivo | Impacto | Razon | |---------|---------|-------| | app.module.ts | CRITICO | Configuracion central NestJS | | api.ts | ALTO | Todas las llamadas API pasan aqui | | AuthContext.tsx | ALTO | Estado de autenticacion global | | vite.config.ts | MEDIO | Proxy afecta todas las llamadas | | main.ts (backend) | MEDIO | Puerto y bootstrap | ### 4.2 Archivos de Bajo Riesgo | Archivo | Impacto | Razon | |---------|---------|-------| | Dashboard.tsx | BAJO | Cambio aislado | | Products.tsx | BAJO | Cambio aislado | | Settings.tsx | BAJO | Cambio aislado | --- ## 5. CONFLICTOS POTENCIALES ### 5.1 Conflictos de Configuracion | Conflicto | Archivos | Resolucion | |-----------|----------|------------| | Puerto duplicado | main.ts (backend vs whatsapp) | Usar 3141 y 3143 | | DB credentials | .env en multiples proyectos | Centralizar en root | | API URL | api.ts vs webhook.service.ts | Usar variable de entorno | ### 5.2 Conflictos de Versionado | Item | Backend | Frontend | Accion | |------|---------|----------|--------| | TypeORM | 0.3.19 | N/A | OK | | Axios | 1.6.5 | 1.13.2 | Actualizar backend | | TypeScript | 5.3.3 | 5.9.3 | OK (compatible) | --- ## 6. ORDEN DE MODIFICACION RECOMENDADO ### 6.1 Dia 1: Preparacion y Backend Core ``` Hora 1-2: [1] database/.env.example → Verificar/crear [2] apps/backend/.env → Crear con credenciales Hora 3-4: [3] apps/backend/src/app.module.ts → TypeORM config Hora 5-6: [4] apps/backend/src/modules/**/entities/*.ts → Verificar sync Hora 7-8: [5] apps/backend/src/common/middleware/tenant.middleware.ts → Crear [6] apps/backend/src/main.ts → Puerto + middleware ``` ### 6.2 Dia 2: Frontend Auth ``` Hora 1-2: [7] apps/frontend/.env → Crear [8] apps/frontend/vite.config.ts → Proxy Hora 3-4: [9] apps/frontend/src/lib/api.ts → Interceptors Hora 5-8: [10] apps/frontend/src/contexts/AuthContext.tsx → Crear [11] apps/frontend/src/pages/Login.tsx → Crear [12] apps/frontend/src/pages/Register.tsx → Crear [13] apps/frontend/src/App.tsx → Rutas [14] apps/frontend/src/components/Layout.tsx → Nav ``` ### 6.3 Dia 3: Frontend Pages + Services ``` Hora 1-4 (paralelo): [15] Dashboard.tsx [16] Products.tsx [17] Orders.tsx [18] Customers.tsx Hora 5-6: [19] Fiado.tsx [20] Inventory.tsx [21] Settings.tsx Hora 7-8: [22] apps/whatsapp-service/.env [23] apps/whatsapp-service/src/main.ts [24] apps/mcp-server/.env [25] apps/mcp-server/src/index.ts ``` ### 6.4 Dia 4: WhatsApp + MCP Integration ``` Hora 1-4: [26] apps/whatsapp-service/src/webhook/webhook.service.ts Hora 5-8: Testing y ajustes ``` --- ## 7. MATRIZ DE IMPACTO | # | Archivo | Depende de | Afecta a | Riesgo | |---|---------|------------|----------|--------| | 1 | .env (db) | - | 3 | BAJO | | 2 | .env (backend) | 1 | 3 | BAJO | | 3 | app.module.ts | 2 | 4,5,6 | ALTO | | 4 | entities/*.ts | 3 | 5 | MEDIO | | 5 | tenant.middleware.ts | 3 | 6 | MEDIO | | 6 | main.ts (backend) | 3,5 | 9,23,25 | ALTO | | 7 | .env (frontend) | - | 8 | BAJO | | 8 | vite.config.ts | 7 | 9 | MEDIO | | 9 | api.ts | 6,8 | 10-21 | ALTO | | 10 | AuthContext.tsx | 9 | 11-14 | ALTO | | 11 | Login.tsx | 10 | 13 | MEDIO | | 12 | Register.tsx | 10 | 13 | MEDIO | | 13 | App.tsx | 10,11,12 | 15-21 | ALTO | | 14 | Layout.tsx | 10 | 15-21 | MEDIO | | 15-21 | Pages | 9,10,13,14 | - | BAJO | | 22-23 | WhatsApp .env/main | 6 | 26 | BAJO | | 24-25 | MCP .env/index | 6 | - | BAJO | | 26 | webhook.service.ts | 22,23 | - | MEDIO | --- ## 8. ROLLBACK PLAN ### 8.1 Puntos de Checkpoint | Checkpoint | Despues de | Verificacion | |------------|------------|--------------| | CP1 | Paso 6 | Backend inicia, DB conectada | | CP2 | Paso 14 | Frontend login funciona | | CP3 | Paso 21 | Todas las paginas cargan | | CP4 | Paso 26 | WhatsApp webhook responde | ### 8.2 Rollback por Checkpoint | Fallo en | Rollback a | Accion | |----------|------------|--------| | CP1 | Sin cambios | Revisar .env y app.module | | CP2 | CP1 | Revisar api.ts y AuthContext | | CP3 | CP2 | Revisar paginas individuales | | CP4 | CP3 | Revisar webhook.service.ts | --- ## 9. CONCLUSIONES ### 9.1 Archivos Criticos (No modificar sin backup) 1. `apps/backend/src/app.module.ts` 2. `apps/frontend/src/lib/api.ts` 3. `apps/frontend/src/contexts/AuthContext.tsx` ### 9.2 Orden Inviolable 1. Database schemas primero 2. Backend .env segundo 3. Backend TypeORM tercero 4. Backend middleware cuarto 5. Frontend despues de backend funcionando ### 9.3 Recomendaciones - Hacer commit despues de cada checkpoint - Probar backend aislado antes de frontend - Usar branch feature para cambios --- **Fin de Analisis de Dependencias FASE 4**