version: '3.8'

services:
  # PostgreSQL Database (Development)
  postgres-dev:
    image: postgres:15-alpine
    container_name: maternal-postgres-dev
    restart: unless-stopped
    ports:
      - "5555:5432"
    environment:
      POSTGRES_DB: maternal_app
      POSTGRES_USER: maternal_user
      POSTGRES_PASSWORD: maternal_dev_password_2024
    volumes:
      - postgres_dev_data:/var/lib/postgresql/data
      - ./maternal-app/maternal-app-backend/src/database/migrations:/docker-entrypoint-initdb.d:ro
    networks:
      - maternal-dev-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U maternal_user"]
      interval: 10s
      timeout: 5s
      retries: 5

  # Redis Cache (Development)
  redis-dev:
    image: redis:7-alpine
    container_name: maternal-redis-dev
    restart: unless-stopped
    ports:
      - "6666:6379"
    volumes:
      - redis_dev_data:/data
    networks:
      - maternal-dev-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5

  # MongoDB for AI Chat History (Development)
  mongodb-dev:
    image: mongo:7
    container_name: maternal-mongodb-dev
    restart: unless-stopped
    ports:
      - "27777:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: maternal_admin
      MONGO_INITDB_ROOT_PASSWORD: maternal_mongo_password_2024
      MONGO_INITDB_DATABASE: maternal_ai_chat
    volumes:
      - mongo_dev_data:/data/db
    networks:
      - maternal-dev-network
    healthcheck:
      test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
      interval: 10s
      timeout: 5s
      retries: 5

  # MinIO Object Storage (Development)
  minio-dev:
    image: minio/minio:latest
    container_name: maternal-minio-dev
    restart: unless-stopped
    ports:
      - "9002:9000"
      - "9003:9001"  # Console
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: maternal_minio_admin
      MINIO_ROOT_PASSWORD: maternal_minio_password_2024
    volumes:
      - minio_dev_data:/data
    networks:
      - maternal-dev-network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  # Backend API (Development)
  backend-dev:
    build:
      context: ./maternal-app/maternal-app-backend
      dockerfile: Dockerfile
    container_name: maternal-backend-dev
    restart: unless-stopped
    ports:
      - "3015:3015"
    environment:
      - NODE_ENV=development
      - API_PORT=3015
      - DATABASE_HOST=postgres-dev
      - REDIS_HOST=redis-dev
      - MONGODB_HOST=mongodb-dev
      - MINIO_ENDPOINT=http://minio-dev:9000
    env_file:
      - ./maternal-app/maternal-app-backend/.env
    volumes:
      - ./maternal-app/maternal-app-backend:/app
      - /app/node_modules
    depends_on:
      postgres-dev:
        condition: service_healthy
      redis-dev:
        condition: service_healthy
      mongodb-dev:
        condition: service_healthy
    networks:
      - maternal-dev-network
    command: npm run start:dev

  # Frontend Application (Development)
  frontend-dev:
    build:
      context: ./maternal-web
      dockerfile: Dockerfile
    container_name: maternal-frontend-dev
    restart: unless-stopped
    ports:
      - "3005:3005"
    environment:
      - NODE_ENV=development
      - PORT=3005
      - NEXT_PUBLIC_API_URL=https://maternal-api.noru1.ro
    env_file:
      - ./maternal-web/.env.local
    volumes:
      - ./maternal-web:/app
      - /app/node_modules
      - /app/.next
    depends_on:
      - backend-dev
    networks:
      - maternal-dev-network
    command: npm run dev -- -p 3005

networks:
  maternal-dev-network:
    driver: bridge

volumes:
  postgres_dev_data:
    driver: local
  redis_dev_data:
    driver: local
  mongo_dev_data:
    driver: local
  minio_dev_data:
    driver: local