version: '3.8'

services:
  # Core Service (Go)
  core-service:
    build:
      context: ./core-service
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    environment:
      - SERVER_HOST=0.0.0.0
      - SERVER_PORT=8080
      - DB_HOST=postgres
      - DB_PORT=5432
      - DB_USER=erp_user
      - DB_PASSWORD=erp_pass
      - DB_NAME=erp_mvp
      - DB_SSLMODE=disable
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - REDIS_PASSWORD=
      - REDIS_DB=0
      - JWT_SECRET=your-super-secret-jwt-key-change-in-production
      - JWT_EXPIRATION=24
      - DOC_SERVICE_URL=http://doc-service:8000
      - LOG_LEVEL=info
    depends_on:
      - postgres
      - redis
    networks:
      - erp-network
    restart: unless-stopped

  # Document Service (Python)
  doc-service:
    build:
      context: ./doc-service
      dockerfile: Dockerfile
    ports:
      - "8000:8000"
    environment:
      - HOST=0.0.0.0
      - PORT=8000
      - DEBUG=false
      - LOG_LEVEL=INFO
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - REDIS_PASSWORD=
      - REDIS_DB=1
      - CORE_SERVICE_URL=http://core-service:8080
      - DOCUMENTS_CACHE_TTL=86400
      - MAX_DOCUMENT_SIZE=10485760
      - TEMPLATES_DIR=/app/templates
      - OUTPUT_DIR=/app/output
      - QR_CODE_SIZE=10
      - QR_CODE_BORDER=2
    volumes:
      - doc_templates:/app/templates
      - doc_output:/app/output
    depends_on:
      - redis
    networks:
      - erp-network
    restart: unless-stopped

  # Frontend (Angular)
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "3000:80"
    environment:
      - API_URL=http://localhost:8080
      - DOC_SERVICE_URL=http://localhost:8000
    depends_on:
      - core-service
    networks:
      - erp-network
    restart: unless-stopped

  # Database (PostgreSQL)
  postgres:
    image: postgres:15-alpine
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=erp_mvp
      - POSTGRES_USER=erp_user
      - POSTGRES_PASSWORD=erp_pass
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./docker/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - erp-network
    restart: unless-stopped

  # Cache (Redis)
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    command: redis-server --appendonly yes
    volumes:
      - redis_data:/data
    networks:
      - erp-network
    restart: unless-stopped

  # API Gateway (Traefik) - опционально
  traefik:
    image: traefik:v2.10
    command:
      - --api.insecure=true
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
    ports:
      - "80:80"
      - "443:443"
      - "8081:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - erp-network
    restart: unless-stopped
    profiles:
      - gateway

  # Monitoring (Prometheus)
  prometheus:
    image: prom/prometheus:latest
    ports:
      - "9090:9090"
    volumes:
      - ./docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--storage.tsdb.retention.time=200h'
      - '--web.enable-lifecycle'
    networks:
      - erp-network
    restart: unless-stopped
    profiles:
      - monitoring

  # Monitoring (Grafana)
  grafana:
    image: grafana/grafana:latest
    ports:
      - "3001:3000"
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=admin
    volumes:
      - grafana_data:/var/lib/grafana
      - ./docker/grafana/provisioning:/etc/grafana/provisioning
    networks:
      - erp-network
    restart: unless-stopped
    profiles:
      - monitoring

volumes:
  postgres_data:
  redis_data:
  doc_templates:
  doc_output:
  prometheus_data:
  grafana_data:

networks:
  erp-network:
    driver: bridge
