services:
  frontend:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        VITE_FIREBASE_API_KEY: ${VITE_FIREBASE_API_KEY}
        VITE_FIREBASE_AUTH_DOMAIN: ${VITE_FIREBASE_AUTH_DOMAIN}
        VITE_FIREBASE_PROJECT_ID: ${VITE_FIREBASE_PROJECT_ID}
        VITE_FIREBASE_STORAGE_BUCKET: ${VITE_FIREBASE_STORAGE_BUCKET}
        VITE_FIREBASE_MESSAGING_SENDER_ID: ${VITE_FIREBASE_MESSAGING_SENDER_ID}
        VITE_FIREBASE_APP_ID: ${VITE_FIREBASE_APP_ID}
        VITE_API_URL: ${VITE_API_URL:-/api}
    depends_on:
      backend:
        condition: service_started
    ports:
      - "127.0.0.1:8000:80"
    restart: unless-stopped
    networks:
      app_net:
      workspace_web:
        aliases:
          - gratefuljournal-app

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    env_file:
      - ./backend/.env
    expose:
      - "8001"
    depends_on:
      mongo:
        condition: service_healthy
    restart: unless-stopped
    networks:
      - app_net

  mongo:
    image: mongo:6
    command: ["mongod", "--bind_ip", "0.0.0.0", "--auth"]
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_USERNAME}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}
    volumes:
      - mongo_data:/data/db
    healthcheck:
      test: ["CMD", "mongosh", "--quiet", "-u", "${MONGO_USERNAME}", "-p", "${MONGO_PASSWORD}", "--authenticationDatabase", "admin", "--eval", "db.adminCommand('ping').ok"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
    restart: unless-stopped
    networks:
      - app_net

volumes:
  mongo_data:

networks:
  app_net:
    driver: bridge
  workspace_web:
    external: true