Some checks are pending
CI/CD Pipeline / Backend CI (push) Waiting to run
CI/CD Pipeline / Frontend CI (push) Waiting to run
CI/CD Pipeline / WhatsApp Service CI (push) Waiting to run
CI/CD Pipeline / Mobile CI (push) Waiting to run
CI/CD Pipeline / Docker Build (./apps/backend, ./apps/backend/Dockerfile, backend) (push) Blocked by required conditions
CI/CD Pipeline / Docker Build (./apps/frontend, ./apps/frontend/Dockerfile, frontend) (push) Blocked by required conditions
CI/CD Pipeline / Docker Build (./apps/whatsapp-service, ./apps/whatsapp-service/Dockerfile, whatsapp-service) (push) Blocked by required conditions
CI/CD Pipeline / Deploy to Production (push) Blocked by required conditions
- Move 7 non-standard folders to _archive/ - Archive 3 extra root files - Update _MAP.md with standardized structure Standard: SIMCO-ESTANDAR-ORCHESTRATION v1.0.0 Level: CONSUMER (L2) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
524 lines
12 KiB
Markdown
524 lines
12 KiB
Markdown
# GUIA DE CONFIGURACION - FASE 6
|
|
|
|
**Proyecto:** michangarrito
|
|
**Fecha:** 2026-01-10
|
|
**Version:** 1.0.0
|
|
**Sistema:** SIMCO - NEXUS v4.0
|
|
**Estado:** DOCUMENTADO
|
|
|
|
---
|
|
|
|
## 1. RESUMEN EJECUTIVO
|
|
|
|
| Servicio | Estado | Prioridad | Dependencia |
|
|
|----------|--------|-----------|-------------|
|
|
| Docker Deployment | LISTO | P0 | Servidor |
|
|
| SSL/Dominio | PENDIENTE | P0 | Servidor |
|
|
| Meta WhatsApp Business | PENDIENTE | P0 | Cuenta Meta verificada |
|
|
| Stripe Produccion | PENDIENTE | P0 | Cuenta Stripe |
|
|
| LLM API Key | PENDIENTE | P1 | OpenRouter/OpenAI |
|
|
|
|
---
|
|
|
|
## 2. DOCKER DEPLOYMENT
|
|
|
|
### 2.1 Requisitos del Servidor
|
|
|
|
```
|
|
Minimo:
|
|
- 2 vCPU
|
|
- 4 GB RAM
|
|
- 40 GB SSD
|
|
- Ubuntu 22.04 LTS
|
|
|
|
Recomendado:
|
|
- 4 vCPU
|
|
- 8 GB RAM
|
|
- 80 GB SSD
|
|
- Ubuntu 22.04 LTS
|
|
```
|
|
|
|
### 2.2 Instalacion de Docker
|
|
|
|
```bash
|
|
# Actualizar sistema
|
|
sudo apt update && sudo apt upgrade -y
|
|
|
|
# Instalar dependencias
|
|
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
|
|
|
|
# Agregar repositorio Docker
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
|
|
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
|
|
# Instalar Docker
|
|
sudo apt update
|
|
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
|
|
|
# Agregar usuario al grupo docker
|
|
sudo usermod -aG docker $USER
|
|
|
|
# Verificar instalacion
|
|
docker --version
|
|
docker compose version
|
|
```
|
|
|
|
### 2.3 Despliegue
|
|
|
|
```bash
|
|
# Clonar repositorio
|
|
git clone https://github.com/tu-org/michangarrito.git
|
|
cd michangarrito
|
|
|
|
# Copiar y configurar .env
|
|
cp .env.example .env
|
|
nano .env # Editar variables
|
|
|
|
# Construir e iniciar servicios
|
|
docker compose up -d --build
|
|
|
|
# Verificar estado
|
|
docker compose ps
|
|
docker compose logs -f
|
|
```
|
|
|
|
### 2.4 Variables de Entorno Produccion
|
|
|
|
Crear archivo `.env.production`:
|
|
|
|
```bash
|
|
# APLICACION
|
|
NODE_ENV=production
|
|
APP_NAME=michangarrito
|
|
|
|
# PUERTOS
|
|
WEB_PORT=3140
|
|
BACKEND_PORT=3141
|
|
MCP_PORT=3142
|
|
WHATSAPP_PORT=3143
|
|
|
|
# DATABASE - GENERAR PASSWORD SEGURO
|
|
DB_HOST=postgres
|
|
DB_PORT=5432
|
|
DB_NAME=michangarrito_prod
|
|
DB_USER=michangarrito_prod
|
|
DB_PASSWORD=<GENERAR: openssl rand -base64 32>
|
|
DB_SSL=true
|
|
|
|
# REDIS
|
|
REDIS_HOST=redis
|
|
REDIS_PORT=6379
|
|
REDIS_DATABASE=8
|
|
|
|
# JWT - GENERAR SECRET SEGURO
|
|
JWT_SECRET=<GENERAR: openssl rand -base64 64>
|
|
JWT_EXPIRES_IN=7d
|
|
JWT_REFRESH_EXPIRES_IN=30d
|
|
|
|
# CORS
|
|
FRONTEND_URL=https://tu-dominio.com
|
|
ALLOWED_ORIGINS=https://tu-dominio.com,https://api.tu-dominio.com
|
|
|
|
# LOGGING
|
|
LOG_LEVEL=info
|
|
LOG_FORMAT=json
|
|
```
|
|
|
|
---
|
|
|
|
## 3. SSL Y DOMINIO
|
|
|
|
### 3.1 Configurar DNS
|
|
|
|
Agregar registros DNS:
|
|
|
|
```
|
|
Tipo Nombre Valor
|
|
A @ <IP_SERVIDOR>
|
|
A api <IP_SERVIDOR>
|
|
A whatsapp <IP_SERVIDOR>
|
|
CNAME www @
|
|
```
|
|
|
|
### 3.2 Instalar Certbot
|
|
|
|
```bash
|
|
# Instalar certbot
|
|
sudo apt install -y certbot python3-certbot-nginx
|
|
|
|
# Obtener certificado
|
|
sudo certbot --nginx -d tu-dominio.com -d api.tu-dominio.com -d whatsapp.tu-dominio.com
|
|
|
|
# Verificar renovacion automatica
|
|
sudo certbot renew --dry-run
|
|
```
|
|
|
|
### 3.3 Configuracion Nginx
|
|
|
|
Crear `/deploy/nginx/conf.d/michangarrito.conf`:
|
|
|
|
```nginx
|
|
# Frontend
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name tu-dominio.com www.tu-dominio.com;
|
|
|
|
ssl_certificate /etc/letsencrypt/live/tu-dominio.com/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/tu-dominio.com/privkey.pem;
|
|
|
|
location / {
|
|
proxy_pass http://frontend:80;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection 'upgrade';
|
|
proxy_set_header Host $host;
|
|
proxy_cache_bypass $http_upgrade;
|
|
}
|
|
}
|
|
|
|
# Backend API
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name api.tu-dominio.com;
|
|
|
|
ssl_certificate /etc/letsencrypt/live/tu-dominio.com/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/tu-dominio.com/privkey.pem;
|
|
|
|
location / {
|
|
proxy_pass http://backend:3141;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header Host $host;
|
|
}
|
|
}
|
|
|
|
# WhatsApp Webhook
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name whatsapp.tu-dominio.com;
|
|
|
|
ssl_certificate /etc/letsencrypt/live/tu-dominio.com/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/tu-dominio.com/privkey.pem;
|
|
|
|
location / {
|
|
proxy_pass http://whatsapp-service:3143;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header Host $host;
|
|
}
|
|
}
|
|
|
|
# Redirect HTTP to HTTPS
|
|
server {
|
|
listen 80;
|
|
server_name tu-dominio.com www.tu-dominio.com api.tu-dominio.com whatsapp.tu-dominio.com;
|
|
return 301 https://$server_name$request_uri;
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## 4. META WHATSAPP BUSINESS
|
|
|
|
### 4.1 Requisitos Previos
|
|
|
|
- Cuenta de Facebook Business verificada
|
|
- Numero de telefono dedicado (no usado en WhatsApp personal)
|
|
- Tarjeta de credito para verificacion
|
|
|
|
### 4.2 Pasos de Configuracion
|
|
|
|
1. **Crear App en Meta for Developers**
|
|
- Ir a https://developers.facebook.com/apps
|
|
- Crear nueva app tipo "Business"
|
|
- Agregar producto "WhatsApp"
|
|
|
|
2. **Configurar WhatsApp Business**
|
|
- Ir a WhatsApp > Getting Started
|
|
- Agregar numero de telefono
|
|
- Verificar numero via SMS/llamada
|
|
|
|
3. **Obtener Credenciales**
|
|
```
|
|
WHATSAPP_ACCESS_TOKEN = Token de acceso permanente
|
|
WHATSAPP_PHONE_NUMBER_ID = ID del numero de telefono
|
|
WHATSAPP_BUSINESS_ACCOUNT_ID = ID de cuenta de negocio
|
|
WHATSAPP_VERIFY_TOKEN = Token personalizado para webhook
|
|
WHATSAPP_APP_SECRET = Secret de la app
|
|
```
|
|
|
|
4. **Configurar Webhook**
|
|
- URL: `https://whatsapp.tu-dominio.com/webhook`
|
|
- Verify token: El mismo valor de WHATSAPP_VERIFY_TOKEN
|
|
- Suscribirse a: messages, message_echoes, message_reactions
|
|
|
|
5. **Crear Templates de Mensajes**
|
|
- Ir a WhatsApp > Message Templates
|
|
- Crear templates para:
|
|
- Recordatorio de pago
|
|
- Confirmacion de pedido
|
|
- Pedido listo
|
|
- Esperar aprobacion (24-48 horas)
|
|
|
|
### 4.3 Variables de Entorno
|
|
|
|
```bash
|
|
# WhatsApp Business API
|
|
WHATSAPP_ACCESS_TOKEN=EAAxxxxxxxxxx
|
|
WHATSAPP_PHONE_NUMBER_ID=123456789012345
|
|
WHATSAPP_BUSINESS_ACCOUNT_ID=123456789012345
|
|
WHATSAPP_VERIFY_TOKEN=mi_token_verificacion_secreto
|
|
WHATSAPP_APP_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
WHATSAPP_WEBHOOK_URL=https://whatsapp.tu-dominio.com/webhook
|
|
```
|
|
|
|
---
|
|
|
|
## 5. STRIPE PRODUCCION
|
|
|
|
### 5.1 Crear Cuenta Stripe
|
|
|
|
1. Ir a https://stripe.com
|
|
2. Crear cuenta
|
|
3. Verificar identidad (requiere documento oficial)
|
|
4. Activar modo produccion
|
|
|
|
### 5.2 Configurar Productos
|
|
|
|
En Stripe Dashboard > Products, crear:
|
|
|
|
**Planes de Suscripcion:**
|
|
| Producto | Precio | Intervalo |
|
|
|----------|--------|-----------|
|
|
| Changarrito | $99 MXN | Mensual |
|
|
| Tiendita | $249 MXN | Mensual |
|
|
|
|
**Paquetes de Tokens:**
|
|
| Producto | Precio | Tokens |
|
|
|----------|--------|--------|
|
|
| Pack Basico | $49 MXN | 1,000 |
|
|
| Pack Estandar | $129 MXN | 3,000 |
|
|
| Pack Pro | $299 MXN | 8,000 |
|
|
| Pack Empresarial | $699 MXN | 20,000 |
|
|
|
|
### 5.3 Configurar Webhook
|
|
|
|
En Stripe Dashboard > Developers > Webhooks:
|
|
|
|
1. Agregar endpoint: `https://api.tu-dominio.com/api/v1/payments/webhook/stripe`
|
|
2. Eventos a suscribir:
|
|
- `checkout.session.completed`
|
|
- `customer.subscription.created`
|
|
- `customer.subscription.updated`
|
|
- `customer.subscription.deleted`
|
|
- `invoice.paid`
|
|
- `invoice.payment_failed`
|
|
- `payment_intent.succeeded`
|
|
|
|
### 5.4 Variables de Entorno
|
|
|
|
```bash
|
|
# Stripe (Produccion)
|
|
STRIPE_SECRET_KEY=sk_live_xxxxxxxxxxxxxxxx
|
|
STRIPE_PUBLISHABLE_KEY=pk_live_xxxxxxxxxxxxxxxx
|
|
STRIPE_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxx
|
|
|
|
# IDs de productos (obtener de Stripe Dashboard)
|
|
STRIPE_PRICE_CHANGARRITO=price_xxxxxxxxxxxxxxxx
|
|
STRIPE_PRICE_TIENDITA=price_xxxxxxxxxxxxxxxx
|
|
STRIPE_PRICE_TOKENS_1000=price_xxxxxxxxxxxxxxxx
|
|
STRIPE_PRICE_TOKENS_3000=price_xxxxxxxxxxxxxxxx
|
|
STRIPE_PRICE_TOKENS_8000=price_xxxxxxxxxxxxxxxx
|
|
STRIPE_PRICE_TOKENS_20000=price_xxxxxxxxxxxxxxxx
|
|
|
|
# OXXO
|
|
STRIPE_OXXO_ENABLED=true
|
|
```
|
|
|
|
---
|
|
|
|
## 6. LLM API KEY
|
|
|
|
### 6.1 Opciones de Proveedor
|
|
|
|
| Proveedor | Modelo Recomendado | Costo Aprox |
|
|
|-----------|-------------------|-------------|
|
|
| OpenRouter | claude-3-haiku | $0.25/1M tokens |
|
|
| OpenAI | gpt-4o-mini | $0.15/1M input |
|
|
| Anthropic | claude-3-haiku | $0.25/1M tokens |
|
|
| Ollama | llama3 | Gratuito (self-hosted) |
|
|
|
|
### 6.2 Configurar OpenRouter (Recomendado)
|
|
|
|
1. Ir a https://openrouter.ai
|
|
2. Crear cuenta
|
|
3. Ir a Keys > Create Key
|
|
4. Copiar API Key
|
|
|
|
```bash
|
|
LLM_PROVIDER=openrouter
|
|
LLM_API_KEY=sk-or-v1-xxxxxxxxxxxxxxxx
|
|
LLM_MODEL=anthropic/claude-3-haiku
|
|
LLM_BASE_URL=https://openrouter.ai/api/v1
|
|
LLM_MAX_TOKENS=4096
|
|
```
|
|
|
|
### 6.3 Configurar OpenAI (Alternativa)
|
|
|
|
1. Ir a https://platform.openai.com
|
|
2. Crear cuenta
|
|
3. Ir a API Keys > Create new secret key
|
|
4. Copiar API Key
|
|
|
|
```bash
|
|
LLM_PROVIDER=openai
|
|
LLM_API_KEY=sk-xxxxxxxxxxxxxxxx
|
|
LLM_MODEL=gpt-4o-mini
|
|
LLM_BASE_URL=https://api.openai.com/v1
|
|
```
|
|
|
|
### 6.4 Multi-Tenant LLM
|
|
|
|
El sistema soporta credenciales LLM por tenant:
|
|
|
|
```sql
|
|
-- Tabla tenant_integration_credentials
|
|
INSERT INTO public.tenant_integration_credentials
|
|
(tenant_id, integration_type, provider, credentials)
|
|
VALUES
|
|
('uuid-del-tenant', 'llm', 'openai',
|
|
'{"api_key": "sk-tenant-key", "model": "gpt-4o"}');
|
|
```
|
|
|
|
Si el tenant no tiene credenciales propias, se usa el fallback de la plataforma.
|
|
|
|
---
|
|
|
|
## 7. CHECKLIST DE DESPLIEGUE
|
|
|
|
### Pre-Despliegue
|
|
|
|
- [ ] Servidor aprovisionado
|
|
- [ ] Docker instalado
|
|
- [ ] Repositorio clonado
|
|
- [ ] Dominio configurado (DNS)
|
|
- [ ] Cuenta Meta Business verificada
|
|
- [ ] Cuenta Stripe activada
|
|
- [ ] API Key LLM obtenida
|
|
|
|
### Configuracion
|
|
|
|
- [ ] `.env.production` creado
|
|
- [ ] Secretos generados (JWT_SECRET, DB_PASSWORD)
|
|
- [ ] SSL configurado (Certbot)
|
|
- [ ] Nginx configurado
|
|
- [ ] Webhook WhatsApp configurado
|
|
- [ ] Webhook Stripe configurado
|
|
- [ ] Templates WhatsApp aprobados
|
|
|
|
### Validacion
|
|
|
|
- [ ] `docker compose ps` - todos los servicios running
|
|
- [ ] Frontend accesible via HTTPS
|
|
- [ ] API responde en /api/v1/health
|
|
- [ ] WhatsApp webhook verificado
|
|
- [ ] Stripe webhook recibe eventos
|
|
- [ ] LLM responde correctamente
|
|
|
|
---
|
|
|
|
## 8. COMANDOS UTILES
|
|
|
|
### Docker
|
|
|
|
```bash
|
|
# Ver logs de todos los servicios
|
|
docker compose logs -f
|
|
|
|
# Ver logs de un servicio especifico
|
|
docker compose logs -f backend
|
|
|
|
# Reiniciar un servicio
|
|
docker compose restart backend
|
|
|
|
# Reconstruir un servicio
|
|
docker compose up -d --build backend
|
|
|
|
# Ejecutar comando en contenedor
|
|
docker compose exec backend sh
|
|
|
|
# Ver uso de recursos
|
|
docker stats
|
|
```
|
|
|
|
### Mantenimiento
|
|
|
|
```bash
|
|
# Backup de base de datos
|
|
docker compose exec postgres pg_dump -U michangarrito_prod michangarrito_prod > backup.sql
|
|
|
|
# Restaurar backup
|
|
docker compose exec -T postgres psql -U michangarrito_prod michangarrito_prod < backup.sql
|
|
|
|
# Limpiar imagenes no usadas
|
|
docker system prune -af
|
|
|
|
# Ver espacio en disco
|
|
df -h
|
|
```
|
|
|
|
---
|
|
|
|
## 9. TROUBLESHOOTING
|
|
|
|
### WhatsApp no recibe mensajes
|
|
|
|
1. Verificar URL del webhook en Meta Dashboard
|
|
2. Verificar que el token de verificacion coincida
|
|
3. Revisar logs: `docker compose logs -f whatsapp-service`
|
|
4. Verificar que el servidor responda con 200 OK
|
|
|
|
### Stripe webhooks fallan
|
|
|
|
1. Verificar URL del webhook en Stripe Dashboard
|
|
2. Verificar STRIPE_WEBHOOK_SECRET
|
|
3. Revisar logs: `docker compose logs -f backend | grep stripe`
|
|
4. Usar Stripe CLI para testing local
|
|
|
|
### LLM no responde
|
|
|
|
1. Verificar API key valida
|
|
2. Verificar creditos/saldo en proveedor
|
|
3. Revisar logs del MCP server
|
|
4. Probar con curl directo al proveedor
|
|
|
|
---
|
|
|
|
## 10. PROXIMOS PASOS
|
|
|
|
Una vez completada la configuracion:
|
|
|
|
1. **Testing E2E**
|
|
- Probar flujo completo de registro
|
|
- Probar ventas desde POS
|
|
- Probar chat WhatsApp
|
|
- Probar suscripciones
|
|
|
|
2. **Monitoreo**
|
|
- Configurar Sentry para errores
|
|
- Configurar alertas de uptime
|
|
- Configurar metricas de uso
|
|
|
|
3. **Backups**
|
|
- Configurar backup automatico de BD
|
|
- Configurar backup de volumenes Docker
|
|
|
|
---
|
|
|
|
**Documentado por:** Agente Orquestador
|
|
**Fecha:** 2026-01-10
|
|
**Version:** 1.0.0
|