feat: Implement Phase 1 & 2 - Full monorepo architecture
## Backend API (apps/api) - Express.js server with TypeScript - JWT authentication with access/refresh tokens - Multi-tenant middleware (schema per tenant) - Complete CRUD routes: auth, cfdis, transactions, contacts, categories, metrics, alerts - SAT integration: CFDI 4.0 XML parser, FIEL authentication - Metrics engine: 50+ financial metrics (Core, Startup, Enterprise) - Rate limiting, CORS, Helmet security ## Frontend Web (apps/web) - Next.js 14 with App Router - Authentication pages: login, register, forgot-password - Dashboard layout with Sidebar and Header - Dashboard pages: overview, cash-flow, revenue, expenses, metrics - Zustand stores for auth and UI state - Theme support with flash prevention ## Database Package (packages/database) - PostgreSQL migrations with multi-tenant architecture - Public schema: plans, tenants, users, sessions, subscriptions - Tenant schema: sat_credentials, cfdis, transactions, contacts, accounts, alerts - Tenant management functions - Seed data for plans and super admin ## Shared Package (packages/shared) - TypeScript types: auth, tenant, financial, metrics, reports - Zod validation schemas for all entities - Utility functions for formatting ## UI Package (packages/ui) - Chart components: LineChart, BarChart, AreaChart, PieChart - Data components: DataTable, MetricCard, KPICard, AlertBadge - PeriodSelector and Skeleton components ## Infrastructure - Docker Compose: PostgreSQL 15, Redis 7, MinIO, Mailhog - Makefile with 25+ development commands - Development scripts: dev-setup.sh, dev-down.sh - Complete .env.example template Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
281
scripts/dev-setup.sh
Executable file
281
scripts/dev-setup.sh
Executable file
@@ -0,0 +1,281 @@
|
||||
#!/bin/bash
|
||||
# =============================================================================
|
||||
# Horux Strategy - Script de Setup para Desarrollo
|
||||
# =============================================================================
|
||||
# Este script prepara el entorno de desarrollo local:
|
||||
# 1. Verifica dependencias (Docker, Node.js, pnpm)
|
||||
# 2. Copia archivos de configuracion
|
||||
# 3. Levanta servicios de infraestructura
|
||||
# 4. Espera a que los servicios esten listos
|
||||
# 5. Ejecuta migraciones de base de datos
|
||||
#
|
||||
# Uso:
|
||||
# ./scripts/dev-setup.sh # Setup completo
|
||||
# ./scripts/dev-setup.sh --skip-migrations # Sin migraciones
|
||||
# =============================================================================
|
||||
|
||||
set -e # Salir si hay errores
|
||||
|
||||
# Colores para output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # Sin color
|
||||
|
||||
# Directorio del proyecto (relativo al script)
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
# Funciones de utilidad
|
||||
print_header() {
|
||||
echo ""
|
||||
echo -e "${BLUE}=============================================${NC}"
|
||||
echo -e "${BLUE}$1${NC}"
|
||||
echo -e "${BLUE}=============================================${NC}"
|
||||
}
|
||||
|
||||
print_step() {
|
||||
echo -e "${GREEN}[✓]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[!]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[✗]${NC} $1"
|
||||
}
|
||||
|
||||
check_command() {
|
||||
if command -v "$1" &> /dev/null; then
|
||||
print_step "$1 encontrado: $(command -v $1)"
|
||||
return 0
|
||||
else
|
||||
print_error "$1 no encontrado"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Inicio del script
|
||||
# =============================================================================
|
||||
|
||||
print_header "Horux Strategy - Setup de Desarrollo"
|
||||
|
||||
cd "$PROJECT_DIR"
|
||||
echo "Directorio del proyecto: $PROJECT_DIR"
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Paso 1: Verificar dependencias
|
||||
# -----------------------------------------------------------------------------
|
||||
print_header "Paso 1: Verificando dependencias"
|
||||
|
||||
# Docker
|
||||
if ! check_command docker; then
|
||||
print_error "Docker no esta instalado."
|
||||
echo " Instala Docker Desktop desde: https://www.docker.com/products/docker-desktop"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Docker Compose (integrado en Docker Desktop)
|
||||
if ! docker compose version &> /dev/null; then
|
||||
print_error "Docker Compose no esta disponible."
|
||||
echo " Asegurate de tener Docker Desktop actualizado."
|
||||
exit 1
|
||||
fi
|
||||
print_step "Docker Compose disponible"
|
||||
|
||||
# Verificar que Docker esta corriendo
|
||||
if ! docker info &> /dev/null; then
|
||||
print_error "Docker no esta corriendo."
|
||||
echo " Inicia Docker Desktop e intenta de nuevo."
|
||||
exit 1
|
||||
fi
|
||||
print_step "Docker esta corriendo"
|
||||
|
||||
# Node.js (opcional pero recomendado para verificar)
|
||||
if check_command node; then
|
||||
NODE_VERSION=$(node --version)
|
||||
echo " Version: $NODE_VERSION"
|
||||
fi
|
||||
|
||||
# pnpm (opcional)
|
||||
if check_command pnpm; then
|
||||
PNPM_VERSION=$(pnpm --version)
|
||||
echo " Version: $PNPM_VERSION"
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Paso 2: Configurar archivos de entorno
|
||||
# -----------------------------------------------------------------------------
|
||||
print_header "Paso 2: Configurando archivos de entorno"
|
||||
|
||||
if [ -f "$PROJECT_DIR/.env" ]; then
|
||||
print_warning "Archivo .env ya existe, no se sobreescribira"
|
||||
else
|
||||
if [ -f "$PROJECT_DIR/.env.example" ]; then
|
||||
cp "$PROJECT_DIR/.env.example" "$PROJECT_DIR/.env"
|
||||
print_step "Archivo .env creado desde .env.example"
|
||||
print_warning "Revisa y ajusta los valores en .env segun tu entorno"
|
||||
else
|
||||
print_error "No se encontro .env.example"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Paso 3: Levantar servicios de Docker
|
||||
# -----------------------------------------------------------------------------
|
||||
print_header "Paso 3: Levantando servicios de Docker"
|
||||
|
||||
echo "Construyendo y levantando contenedores..."
|
||||
docker compose up -d --build
|
||||
|
||||
print_step "Contenedores iniciados"
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Paso 4: Esperar a que los servicios esten listos
|
||||
# -----------------------------------------------------------------------------
|
||||
print_header "Paso 4: Esperando a que los servicios esten listos"
|
||||
|
||||
# Funcion para esperar un servicio
|
||||
wait_for_service() {
|
||||
local service=$1
|
||||
local max_attempts=$2
|
||||
local attempt=1
|
||||
|
||||
echo -n " Esperando $service"
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
if docker compose exec -T "$service" echo "ok" &> /dev/null; then
|
||||
echo -e " ${GREEN}[listo]${NC}"
|
||||
return 0
|
||||
fi
|
||||
echo -n "."
|
||||
sleep 2
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
echo -e " ${RED}[timeout]${NC}"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Esperar PostgreSQL usando healthcheck
|
||||
echo "Esperando PostgreSQL..."
|
||||
attempt=1
|
||||
max_attempts=30
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
if docker compose exec -T postgres pg_isready -U horux -d horux_strategy &> /dev/null; then
|
||||
print_step "PostgreSQL listo"
|
||||
break
|
||||
fi
|
||||
echo -n "."
|
||||
sleep 2
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
|
||||
if [ $attempt -gt $max_attempts ]; then
|
||||
print_error "PostgreSQL no respondio a tiempo"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Esperar Redis
|
||||
echo "Esperando Redis..."
|
||||
attempt=1
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
if docker compose exec -T redis redis-cli ping 2>/dev/null | grep -q "PONG"; then
|
||||
print_step "Redis listo"
|
||||
break
|
||||
fi
|
||||
echo -n "."
|
||||
sleep 2
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
|
||||
if [ $attempt -gt $max_attempts ]; then
|
||||
print_error "Redis no respondio a tiempo"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Esperar MinIO
|
||||
echo "Esperando MinIO..."
|
||||
attempt=1
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
if curl -sf http://localhost:9000/minio/health/live &> /dev/null; then
|
||||
print_step "MinIO listo"
|
||||
break
|
||||
fi
|
||||
echo -n "."
|
||||
sleep 2
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
|
||||
if [ $attempt -gt $max_attempts ]; then
|
||||
print_warning "MinIO no respondio, pero puede seguir inicializandose"
|
||||
fi
|
||||
|
||||
# Esperar a que minio-setup termine
|
||||
echo "Esperando configuracion de MinIO..."
|
||||
sleep 5
|
||||
print_step "MinIO configurado (buckets creados)"
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Paso 5: Ejecutar migraciones (opcional)
|
||||
# -----------------------------------------------------------------------------
|
||||
if [[ "$1" != "--skip-migrations" ]]; then
|
||||
print_header "Paso 5: Ejecutando migraciones de base de datos"
|
||||
|
||||
# Verificar si pnpm esta instalado
|
||||
if command -v pnpm &> /dev/null; then
|
||||
echo "Instalando dependencias..."
|
||||
pnpm install
|
||||
|
||||
echo "Ejecutando migraciones..."
|
||||
if pnpm db:migrate:dev; then
|
||||
print_step "Migraciones ejecutadas correctamente"
|
||||
else
|
||||
print_warning "Las migraciones fallaron o no hay migraciones pendientes"
|
||||
echo " Puedes ejecutarlas manualmente con: pnpm db:migrate:dev"
|
||||
fi
|
||||
else
|
||||
print_warning "pnpm no encontrado, saltando migraciones"
|
||||
echo " Instala pnpm con: npm install -g pnpm"
|
||||
echo " Luego ejecuta: pnpm install && pnpm db:migrate:dev"
|
||||
fi
|
||||
else
|
||||
print_header "Paso 5: Migraciones saltadas (--skip-migrations)"
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Resumen final
|
||||
# -----------------------------------------------------------------------------
|
||||
print_header "Setup completado!"
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}Servicios disponibles:${NC}"
|
||||
echo ""
|
||||
echo " PostgreSQL:"
|
||||
echo " - Host: localhost:5432"
|
||||
echo " - Usuario: horux"
|
||||
echo " - Base de datos: horux_strategy"
|
||||
echo ""
|
||||
echo " Redis:"
|
||||
echo " - Host: localhost:6379"
|
||||
echo ""
|
||||
echo " MinIO:"
|
||||
echo " - API: http://localhost:9000"
|
||||
echo " - Consola: http://localhost:9001"
|
||||
echo " - Usuario: horux_minio"
|
||||
echo ""
|
||||
echo " Mailhog:"
|
||||
echo " - SMTP: localhost:1025"
|
||||
echo " - Web UI: http://localhost:8025"
|
||||
echo ""
|
||||
echo -e "${GREEN}Comandos utiles:${NC}"
|
||||
echo ""
|
||||
echo " make dev - Levantar todos los servicios"
|
||||
echo " make down - Detener todos los servicios"
|
||||
echo " make logs - Ver logs de los servicios"
|
||||
echo " make migrate - Ejecutar migraciones"
|
||||
echo " pnpm dev - Iniciar aplicacion en modo desarrollo"
|
||||
echo ""
|
||||
echo -e "${BLUE}Happy coding! 🚀${NC}"
|
||||
Reference in New Issue
Block a user