# SAMMS ENTERPRISE SOVEREIGN OPERATING SYSTEM - Docker Compose
# Local development environment
version: '3.8'

services:
  # ============== Backend API ==============
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
      target: development
    container_name: sesos-backend
    restart: unless-stopped
    ports:
      - "8000:8000"
    environment:
      - ENVIRONMENT=development
      - DATABASE_URL=postgresql://sesos:sesos_dev_password@postgres:5432/sesos_dev
      - REDIS_URL=redis://redis:6379/0
      - SECRET_KEY=dev-secret-key-change-in-production
      - JWT_SECRET=dev-jwt-secret-change-in-production
      - ENCRYPTION_KEY=dev-encryption-key-32-characters!
      - CORS_ORIGINS=http://localhost:3000
      - LOG_LEVEL=DEBUG
    volumes:
      - ./backend:/app
      - backend_venv:/app/.venv
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - sesos-network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # ============== Frontend ==============
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
      target: development
    container_name: sesos-frontend
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=development
      - NEXT_PUBLIC_API_URL=http://localhost:8000
      - NEXT_PUBLIC_APP_URL=http://localhost:3000
      - NEXT_PUBLIC_ENVIRONMENT=development
    volumes:
      - ./frontend:/app
      - /app/node_modules
      - /app/.next
    depends_on:
      - backend
    networks:
      - sesos-network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  # ============== PostgreSQL Database ==============
  postgres:
    image: postgres:15-alpine
    container_name: sesos-postgres
    restart: unless-stopped
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=sesos
      - POSTGRES_PASSWORD=sesos_dev_password
      - POSTGRES_DB=sesos_dev
      - PGDATA=/var/lib/postgresql/data/pgdata
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./backend/migrations:/docker-entrypoint-initdb.d
    networks:
      - sesos-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U sesos -d sesos_dev"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s

  # ============== Redis Cache ==============
  redis:
    image: redis:7-alpine
    container_name: sesos-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
    volumes:
      - redis_data:/data
    networks:
      - sesos-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ============== Mailhog (Email Testing) ==============
  mailhog:
    image: mailhog/mailhog:latest
    container_name: sesos-mailhog
    restart: unless-stopped
    ports:
      - "1025:1025"  # SMTP
      - "8025:8025"  # Web UI
    networks:
      - sesos-network

  # ============== Adminer (Database Admin) ==============
  adminer:
    image: adminer:latest
    container_name: sesos-adminer
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      - ADMINER_DEFAULT_SERVER=postgres
      - ADMINER_DESIGN=pepa-linha-dark
    networks:
      - sesos-network
    depends_on:
      - postgres

  # ============== Redis Commander (Redis Admin) ==============
  redis-commander:
    image: rediscommander/redis-commander:latest
    container_name: sesos-redis-commander
    restart: unless-stopped
    ports:
      - "8081:8081"
    environment:
      - REDIS_HOSTS=local:redis:6379
    networks:
      - sesos-network
    depends_on:
      - redis

networks:
  sesos-network:
    driver: bridge
    name: sesos-network

volumes:
  postgres_data:
    name: sesos-postgres-data
  redis_data:
    name: sesos-redis-data
  backend_venv:
    name: sesos-backend-venv