services:
  db:
    image: postgres:18.3-alpine3.23
    container_name: stock_db
    environment:
      POSTGRES_USER: ${DB_USER:-stock}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-stock}
      POSTGRES_DB: ${DB_NAME:-stock}
    volumes:
      - postgres_data:/var/lib/postgresql
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-stock} -d ${DB_NAME:-stock}"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - stock_network

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: stock_backend
    environment:
      DATABASE_URL: postgres://${DB_USER:-stock}:${DB_PASSWORD:-stock}@db:5432/${DB_NAME:-stock}
      JWT_SECRET: ${JWT_SECRET:-change-me-in-production}
      JWT_EXPIRATION_HOURS: ${JWT_EXPIRATION_HOURS:-168}
      GIN_MODE: ${GIN_MODE:-release}
      PORT: 3019
    ports:
      - "3019:3019"
    depends_on:
      db:
        condition: service_healthy
    networks:
      - stock_network
    restart: unless-stopped

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: stock_frontend
    ports:
      - "3018:80"
    depends_on:
      - backend
    networks:
      - stock_network
    restart: unless-stopped

volumes:
  postgres_data:

networks:
  stock_network:
    driver: bridge
