version: '3.8'

services:
  # MySQL 8.0 Database
  mysql:
    image: mysql:8.0
    container_name: trust_tax_db
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root_password_trust2026
      MYSQL_DATABASE: trust_tax_advisor
      MYSQL_USER: taxadvisor
      MYSQL_PASSWORD: pass_taxadvisor_2026
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./database/schema.sql:/docker-entrypoint-initdb.d/schema.sql
    networks:
      - trust_tax_network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      timeout: 20s
      retries: 10

  # Backend API - Express.js
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: trust_tax_backend
    restart: always
    depends_on:
      mysql:
        condition: service_healthy
    environment:
      NODE_ENV: production
      PORT: 5000
      DB_HOST: mysql
      DB_PORT: 3306
      DB_USER: taxadvisor
      DB_PASSWORD: pass_taxadvisor_2026
      DB_NAME: trust_tax_advisor
      CORS_ORIGIN: http://localhost:3000
      JWT_SECRET: your_super_secret_jwt_key_change_in_production_12345
      TWILIO_ACCOUNT_SID: your_twilio_sid
      TWILIO_AUTH_TOKEN: your_twilio_token
      TWILIO_WHATSAPP_NUMBER: +14155552671
      SMTP_HOST: smtp.gmail.com
      SMTP_PORT: 587
      SMTP_USER: your-email@gmail.com
      SMTP_PASSWORD: your-app-password
      SMTP_FROM_EMAIL: noreply@trusttaxadvisor.com
    ports:
      - "5000:5000"
    volumes:
      - ./backend/uploads:/app/uploads
      - ./backend/logs:/app/logs
    networks:
      - trust_tax_network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5000/api/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # Frontend - React Vite SPA
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
      args:
        VITE_API_URL: http://localhost:5000/api
    container_name: trust_tax_frontend
    restart: always
    environment:
      VITE_API_URL: http://localhost:5000/api
    ports:
      - "3000:3000"
    depends_on:
      - backend
    networks:
      - trust_tax_network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

# Named volumes for persistent data
volumes:
  mysql_data:
    driver: local

# Networks for service communication
networks:
  trust_tax_network:
    driver: bridge
