version: '3.8'

services:
  # Main application
  app:
    build: .
    container_name: qwen-nodejs-app
    ports:
      - "19000:19000"
    environment:
      - NODE_ENV=production
      - PORT=19000
      - DB_HOST=postgres
      - DB_PORT=5432
      - DB_NAME=${DB_NAME:-moh_portal}
      - DB_USER=${DB_USER:-postgres}
      - DB_PASSWORD=${DB_PASSWORD:-postgres}
      - JWT_SECRET=${JWT_SECRET:-secret_key_for_jwt_tokens}
      - SESSION_SECRET=${SESSION_SECRET:-secret_key_for_session}
    depends_on:
      - postgres
      - redis
    networks:
      - moh-network
    restart: unless-stopped

  # PostgreSQL database
  postgres:
    image: postgres:15-alpine
    container_name: qwen-nodejs-postgres
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=${DB_NAME:-moh_portal}
      - POSTGRES_USER=${DB_USER:-postgres}
      - POSTGRES_PASSWORD=${DB_PASSWORD:-postgres}
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - moh-network
    restart: unless-stopped

  # Redis for session storage and caching
  redis:
    image: redis:7-alpine
    container_name: qwen-nodejs-redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - moh-network
    restart: unless-stopped
    command: redis-server --appendonly yes

  # Nginx as reverse proxy (optional, can be added later)
  nginx:
    image: nginx:alpine
    container_name: qwen-nodejs-nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./ssl:/etc/nginx/ssl
    depends_on:
      - app
    networks:
      - moh-network
    restart: unless-stopped

volumes:
  postgres_data:
  redis_data:

networks:
  moh-network:
    driver: bridge