version: '3.8'

services:
  api:
    build:
      context: .
      target: builder
    ports:
      - "3366:3366"
    environment:
      - NODE_ENV=development
      - DATABASE_URL=postgresql://postgres:postgres@db:5432/currency_exchange
      - JWT_ACCESS_SECRET=dev_access_secret
      - JWT_REFRESH_SECRET=dev_refresh_secret
      - ENCRYPTION_KEY=dev_32_character_encryption_keyx
    volumes:
      - ./:/app
      - /app/node_modules
    command: npm run dev
    depends_on:
      - db
    networks:
      - app-network

  db:
    image: postgres:14-alpine
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=currency_exchange
    ports:
      - "5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - app-network

  # Redis for caching, rate limiting, and queues (optional)
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - app-network

  # Prisma Studio for database management
  prisma-studio:
    build:
      context: .
      target: builder
    ports:
      - "5555:5555"
    environment:
      - DATABASE_URL=postgresql://postgres:postgres@db:5432/currency_exchange
    command: npx prisma studio
    depends_on:
      - db
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

volumes:
  postgres_data:
  redis_data: