version: '3.8'

services:
  # MySQL Database
  db:
    image: mysql:8.0
    container_name: radionica_db
    restart: always
    environment:
      MYSQL_DATABASE: radionica3d
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-very_strong_password}
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - radionica_net

  # Redis for sessions and rate limiting
  redis:
    image: redis:alpine
    container_name: radionica_redis
    restart: always
    networks:
      - radionica_net

  # Backend (FastAPI)
  backend:
    build:
      context: .
      dockerfile: backend.Dockerfile
    container_name: radionica_backend
    restart: always
    environment:
      - DB_HOST=db
      - DB_NAME=radionica3d
      - DB_USER=root
      - DB_PASS=${DB_ROOT_PASSWORD:-very_strong_password}
      - REDIS_HOST=redis
      - SYNC_SLICING=True
      - RADIONICA_DEBUG=False
    depends_on:
      - db
      - redis
    volumes:
      - uploads_data:/app/uploads
    networks:
      - radionica_net

  # Frontend (Nginx)
  proxy:
    image: nginx:alpine
    container_name: radionica_proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
      - ./dist:/usr/share/nginx/html:ro
      - uploads_data:/app/uploads:ro
    depends_on:
      - backend
    networks:
      - radionica_net

networks:
  radionica_net:
    driver: bridge

volumes:
  db_data:
  uploads_data:
