services:
  # Application
  app:
    build:
      context: .
      dockerfile: Dockerfile
      target: builder
    container_name: suggestbet-app-local
    restart: unless-stopped
    ports:
      - '3005:3000'
    environment:
      - PORT=3000
      - NODE_ENV=development
      - DATABASE_URL=postgresql://suggestbet:SuGGesT2026SecuRe@postgres:5432/boilerplate_db?schema=public
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - REDIS_PASSWORD=RedisSecure2026
      - REDIS_ENABLED=true
      - JWT_SECRET=9bfa42fbdc6031da6d7c0bd30e9f5b6378a071613d0c02acf95eb576249c3a25
      - JWT_ACCESS_EXPIRATION=15m
      - JWT_REFRESH_EXPIRATION=7d
      - DEFAULT_LANGUAGE=en
      - FALLBACK_LANGUAGE=en
      - AI_ENGINE_URL=http://ai-engine:8000
    volumes:
      - .:/app
      - /app/node_modules
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    command: /bin/sh -c "apk add --no-cache openssl && npx prisma generate && node dist/src/main.js"
    networks:
      - suggestbet-network

  # Frontend (Next.js)
  frontend:
    build:
      context: ../GitHub/Suggest-Bet-FE
      dockerfile: Dockerfile
      args:
        - NEXT_PUBLIC_API_URL=http://localhost:3005/api
    container_name: suggestbet-frontend-local
    restart: unless-stopped
    ports:
      - '3001:3000'
    environment:
      - NEXT_PUBLIC_API_URL=http://localhost:3005/api
    depends_on:
      - app
    networks:
      - suggestbet-network

  # PostgreSQL Database
  postgres:
    image: postgres:16-alpine
    container_name: suggestbet-postgres-local
    restart: unless-stopped
    ports:
      - '15432:5432' # Host port 15432 mapped to container standard port 5432
    environment:
      POSTGRES_USER: suggestbet
      POSTGRES_PASSWORD: SuGGesT2026SecuRe
      POSTGRES_DB: boilerplate_db
    volumes:
      - ./data/postgres-local:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U suggestbet -d boilerplate_db']
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - suggestbet-network

  # Redis
  redis:
    image: redis:7-alpine
    container_name: suggestbet-redis-local
    restart: unless-stopped
    ports:
      - '6379:6379'
    command: redis-server --requirepass RedisSecure2026
    volumes:
      - ./data/redis-local:/data
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - suggestbet-network

  # Adminer (Database UI)
  adminer:
    image: adminer:latest
    container_name: suggestbet-adminer-local
    restart: unless-stopped
    ports:
      - '8080:8080'
    depends_on:
      - postgres
    networks:
      - suggestbet-network

  # Redis Insight (Redis GUI)
  redis-insight:
    image: redis/redisinsight:latest
    container_name: suggestbet-redis-insight-local
    restart: unless-stopped
    ports:
      - '5540:5540'
    depends_on:
      - redis
    networks:
      - suggestbet-network

  # AI Engine (Python FastAPI)
  ai-engine:
    build:
      context: ./ai-engine
      dockerfile: Dockerfile
    container_name: suggestbet-ai-engine-local
    restart: unless-stopped
    ports:
      - '8000:8000'
    environment:
      - DATABASE_URL=postgresql://suggestbet:SuGGesT2026SecuRe@postgres:5432/boilerplate_db?schema=public
    volumes:
      - ./ai-engine:/app
    depends_on:
      postgres:
        condition: service_healthy
    command: uvicorn main:app --host 0.0.0.0 --port 8000 --reload
    networks:
      - suggestbet-network

networks:
  suggestbet-network:
    driver: bridge
