Skip to content

Python API Service Integration

To handle heavy file parsing, complex Python libraries (like python-docx or ML utilities), and document generation, the Spring Boot application delegates specific tasks to an external FastAPI Python service.

Integration Architecture

  • Service: PythonApiService
  • Method: HTTP POST via Spring's RestTemplate or WebClient.
  • Target: The endpoint configured via PYTHON_API_URL (e.g., http://python-service:7002).

Communication Flow

  1. Request Formulation: AiServiceImpl calls PythonApiService.generate(), constructing a PythonGenerateRequest DTO containing files, parameters, and the base prompt.
  2. Execution: The HTTP call is made with a strict 5-minute timeout.
  3. Response Handling: The Python service replies with a PythonGenerateResponse containing the structured JSON or base64 encoded document files, which Spring Boot then relays to the frontend.

Network Routing in Docker

In local development, PYTHON_API_URL might be http://localhost:7002. In production via docker-compose, Docker's internal DNS routing applies, so the URL must be explicitly set to http://python-service:7002.