version: '3.9'

services:
  db:
    image: mariadb:10.11
    container_name: nexus_db
    restart: unless-stopped
    environment:
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-rootpass}
      MARIADB_DATABASE:      ${DB_NAME:-nexus_chat}
      MARIADB_USER:          ${DB_USER:-nexus}
      MARIADB_PASSWORD:      ${DB_PASSWORD:-changeme_secure_password}
    volumes:
      - db_data:/var/lib/mysql
      - ./database/schema.sql:/docker-entrypoint-initdb.d/01_schema.sql:ro
      - ./database/seeds.sql:/docker-entrypoint-initdb.d/02_seeds.sql:ro
    ports:
      - "3306:3306"
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 10

  app:
    build: .
    container_name: nexus_app
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    env_file: ./backend/.env
    environment:
      NODE_ENV:    production
      DB_HOST:     db
      DB_PORT:     "3306"
      PORT:        "3000"
    ports:
      - "3000:3000"
    volumes:
      - uploads:/app/backend/uploads
      - logs:/app/backend/logs

volumes:
  db_data:
  uploads:
  logs:
