services:
  mariadb:
    image: mariadb:11.4
    container_name: tmaker-mariadb
    restart: unless-stopped
    environment:
      MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
      MARIADB_DATABASE: ${MARIADB_DATABASE}
      MARIADB_USER: ${MARIADB_USER}
      MARIADB_PASSWORD: ${MARIADB_PASSWORD}
    command:
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
    volumes:
      - tmaker_mariadb_data:/var/lib/mysql
    healthcheck:
      test: ["CMD-SHELL", "mariadb-admin ping -h 127.0.0.1 -uroot -p$$MARIADB_ROOT_PASSWORD --silent"]
      start_period: 150s
      interval: 10s
      timeout: 5s
      retries: 20

  backend:
    build:
      context: .
      dockerfile: backend/Dockerfile
    container_name: tmaker-backend
    restart: unless-stopped
    depends_on:
      mariadb:
        condition: service_healthy
    environment:
      PORT: 5179
      DB_HOST: mariadb
      DB_PORT: 3306
      DB_USER: ${MARIADB_USER}
      DB_PASSWORD: ${MARIADB_PASSWORD}
      DB_NAME: ${MARIADB_DATABASE}
      SESSION_SECRET: ${SESSION_SECRET}
      SESSION_COOKIE_SECURE: "true"
      SESSION_COOKIE_SAME_SITE: "lax"
      CORS_ORIGINS: https://tmaker.sori.studio
      TRUST_PROXY: 1
      APP_ORIGIN: https://tmaker.sori.studio
      SMTP_HOST: ${SMTP_HOST}
      SMTP_PORT: ${SMTP_PORT}
      SMTP_SECURE: ${SMTP_SECURE}
      SMTP_USER: ${SMTP_USER}
      SMTP_PASS: ${SMTP_PASS}
      SMTP_FROM: ${SMTP_FROM}
    volumes:
      - tmaker_uploads:/app/uploads
      - tmaker_sessions:/app/.sessions

  frontend:
    build:
      context: .
      dockerfile: frontend/Dockerfile
      args:
        VITE_API_ORIGIN: https://tmaker.sori.studio
    container_name: tmaker-frontend
    restart: unless-stopped
    depends_on:
      - backend
    ports:
      - "18080:80"

  phpmyadmin:
    image: phpmyadmin:5.2-apache
    container_name: tmaker-phpmyadmin
    restart: unless-stopped
    profiles: ["admin"]
    depends_on:
      mariadb:
        condition: service_healthy
    environment:
      PMA_HOST: mariadb
      PMA_PORT: 3306
      PMA_USER: ${MARIADB_USER}
      PMA_PASSWORD: ${MARIADB_PASSWORD}
    ports:
      - "18081:80"

volumes:
  tmaker_mariadb_data:
  tmaker_uploads:
  tmaker_sessions:
