version: '3.8'

services:
  backend:
    build: ./backend
    ports:
      - "5000:5000"
    volumes:
      - ./backend:/app
    environment:
      - FLASK_ENV=development
      - SECRET_KEY=dev-secret-key
      - DATABASE_URL=mysql://user:password@db/route_planner
      - OSRM_API_URL=http://router.project-osrm.org
      - OPENCELLID_API_KEY=${OPENCELLID_API_KEY}
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - PIPER_SERVER_URL=http://tts:5002/api/tts
    depends_on:
      - db
      - tts

  db:
    image: mysql:8.0
    environment:
      - MYSQL_ROOT_PASSWORD=rootpassword
      - MYSQL_DATABASE=route_planner
      - MYSQL_USER=user
      - MYSQL_PASSWORD=password
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./backend/schema.sql:/docker-entrypoint-initdb.d/schema.sql

  tts:
    image: rhasspy/piper:latest
    ports:
      - "5002:5002"
    command: --model_dir /usr/share/piper/voices/ --server_address 0.0.0.0 --server_port 5002

  frontend:
    build: ./frontend
    ports:
      - "3000:3000"
    volumes:
      - ./frontend:/app
      - /app/node_modules
    environment:
      - REACT_APP_API_URL=http://localhost:5000/api
    depends_on:
      - backend

volumes:
  mysql_data: