Production-Ready Java Backend Integration with ComfyUI: Architecture & Open-Source Solutions
This article reviews two open-source projects — comfy-flow-api and comfyui-openrouter-ai — and a three-layer production architecture for integrating ComfyUI AI image generation into Java backends, covering RESTful API wrapping, load balancing, workflow JSON templating, and deployment strategies.
Practical Solution: comfy-flow-api
For teams needing a quick production-ready integration, comfy-flow-api is a Spring Boot 3 + JDK 17 project that wraps ComfyUI's native API into cleaner RESTful endpoints.
1.1 Problems Solved
Provides AI drawing APIs for WeChat Mini Programs
Wraps a unified large-model API platform with multi-server load balancing
Allows custom workflows invoked via API
1.2 Core Configuration
Configure ComfyUI service IPs in application.properties: comfy.ips=127.0.0.1 Define workflows in comfyui.json with dynamic parameter replacement:
{
"name": "动漫风格转换",
"workflowPath": "/comfyui/workflow-api.json"
}Supported dynamic parameters: seed, prompt, negative_prompt, image, localDate, localTime, key.
1.3 Storage Extension
Local disk storage via file.storage.disk path; extension interfaces reserved for Alibaba Cloud OSS, AWS S3, SM.MS, etc.
1.4 Quick Start
# Build
./mvnw package -Dquarkus.package.type=uber-jar
# Run
java -jar target/comfy-flow-api-runner.jarAccess Swagger UI at http://127.0.0.1:8189/q/swagger-ui/.
Enterprise Solution: comfyui-openrouter-ai
For complex needs — user system, credit management, multi-node load balancing — this Spring Boot 3 multi-module project provides full admin capabilities.
2.1 Tech Stack
Backend: Spring Boot 3, Web + WebFlux (SSE streaming), Sa-Token (auth), MyBatis-Plus, Druid, MySQL, Redis + Redisson, WebSocket, Spring Mail.
Frontend: Vue 3 + Vite + TypeScript + Element Plus.
2.2 Core Features
Workflow Formulation: Converts ComfyUI workflow parameters into visual forms; users need not understand JSON structure.
Task Management: Submit, cancel, retry with timeout and retry policies.
Multi-Service Support: Configure multiple ComfyUI addresses with automatic load distribution.
Credit User System: Per-user generation quota deduction for commercial scenarios.
2.3 Deployment
Supports traditional servers, Docker, and Kubernetes. Standard Spring Boot multi-module packaged as executable JAR.
Production Architecture: Three-Layer Design
A scalable enterprise-grade ComfyUI + Java backend architecture consists of three layers:
Inference Layer — Responsibility: Run ComfyUI workflows, handle actual AI generation. Tech: GPU servers + Docker containerization.
Service Layer — Responsibility: Receive requests, load distribution, call inference layer APIs, return results. Tech: Spring Boot + WebClient/Apache HttpClient.
Access & Ops Layer — Responsibility: Load balancing, monitoring/alerting, service discovery. Tech: Nginx + Prometheus + Grafana.
Key advantage: each layer scales independently. When image request volume spikes, only inference layer (ComfyUI) containers need scaling; Java service layer remains unchanged.
Reference implementation on CSDN shows Spring Boot calling Qwen-Image-Edit-F2P model using CloseableHttpClient to build workflow JSON, replacing placeholders via String.format or JSON library, submitting to /prompt endpoint, and parsing responses.
Critical Detail: Generating Workflow JSON
The hardest part of integration is generating valid prompt JSON that ComfyUI accepts. Recommended process:
Manually configure workflow in ComfyUI UI, export full JSON template via "Save (API Format)".
Load this JSON as template in Java code; precisely replace parameter nodes (seed, prompt, image, etc.).
Debug API request format with Postman before porting to Java.
Conclusion
Integrating ComfyUI with Java backend boils down to two things: turning workflows into callable APIs, and wrapping the invocation process into a manageable service. Once done, AI image generation becomes a system capability accessible to Mini Programs, web apps, and internal systems. The mentioned open-source projects serve as practical starting points for teams evaluating AI image generation deployment.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Coder Trainee
Experienced in Java and Python, we share and learn together. For submissions or collaborations, DM us.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
