version: '3.8'

services:
  frontend:
    build: .
    container_name: pwa-frontend
    ports:
      - "3000:3000"
    volumes:
      - .:/app
      - /app/node_modules
    environment:
      - CHOKIDAR_USEPOLLING=true
    stdin_open: true
    tty: true
    depends_on:
      - backend
    networks:
      - pwa-network

  backend:
    build:
      context: ./backend
    container_name: pwa-backend
    command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
    volumes:
      - ./backend/app:/app/app
      - ./backend/.env:/app/.env
      - ./backend/data:/app/data
      - .:/workspace
    environment:
      - DATABASE_URL=mysql+mysqlconnector://pwa_user:pwa_pass@db:3306/pwa_db
      - SECRET_KEY=troque-esta-chave
      - ACCESS_TOKEN_EXPIRE_MINUTES=60
    ports:
      - "8000:8000"
    depends_on:
      db:
        condition: service_healthy
    networks:
      - pwa-network

  db:
    image: mysql:8.0
    container_name: pwa-db
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=pwa_db
      - MYSQL_USER=pwa_user
      - MYSQL_PASSWORD=pwa_pass
    ports:
      - "3307:3306"
    volumes:
      - db_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - pwa-network

networks:
  pwa-network:
    driver: bridge

volumes:
  db_data:
