# =====================================================
# SIMPUS Backend - Standalone Docker Compose
# =====================================================
# For full stack (backend + frontend), use root: ../docker-compose.yml
# This file allows backend-only development.
# =====================================================

version: '3.8'

services:
  postgres:
    image: postgres:16-alpine
    container_name: simpus-postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: simpus
      POSTGRES_USER: simpus_admin
      POSTGRES_PASSWORD: simpus_password_2024
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    networks:
      - simpus-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U simpus_admin -d simpus"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s

  redis:
    image: redis:7-alpine
    container_name: simpus-redis
    restart: unless-stopped
    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
    volumes:
      - redis_data:/data
    ports:
      - "6379:6379"
    networks:
      - simpus-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  api:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: simpus-api
    restart: unless-stopped
    environment:
      - APP_NAME=SIMPUS API
      - APP_ENV=development
      - APP_DEBUG=true
      - SERVER_HOST=0.0.0.0
      - SERVER_PORT=8080
      - DB_HOST=postgres
      - DB_PORT=5432
      - DB_NAME=simpus
      - DB_USER=simpus_admin
      - DB_PASSWORD=simpus_password_2024
      - DB_SSL_MODE=disable
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - JWT_SECRET_KEY=simpus-jwt-secret-key-development-only-32chars
      - JWT_ACCESS_EXPIRY=15m
      - JWT_REFRESH_EXPIRY=168h
      - APP_URL=http://localhost:5173
      # Email (optional - set EMAIL_ENABLED=true and SMTP_* for forgot password)
      - EMAIL_ENABLED=false
    ports:
      - "8080:8080"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - simpus-network
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/health/live"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: simpus-pgadmin
    restart: unless-stopped
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@simpus.local
      PGADMIN_DEFAULT_PASSWORD: admin123
      PGADMIN_CONFIG_SERVER_MODE: 'False'
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    ports:
      - "5050:80"
    depends_on:
      - postgres
    networks:
      - simpus-network
    profiles:
      - tools

volumes:
  postgres_data:
  redis_data:
  pgadmin_data:

networks:
  simpus-network:
    driver: bridge

