Dify workflow node execution engine in Java. Replaces the Python execution layer while keeping full compatibility with Dify workflows.
dify-java-runtime/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── dify/
│ │ │ ├── controller/
│ │ │ │ └── console/
│ │ │ │ └── app/
│ │ │ │ └── WorkflowRunController.java
│ │ │ ├── service/
│ │ │ │ └── workflow/
│ │ │ │ └── WorkflowRunService.java
│ │ │ ├── model/
│ │ │ │ ├── WorkflowRun.java
│ │ │ │ ├── WorkflowNodeExecution.java
│ │ │ │ └── enums/
│ │ │ │ ├── WorkflowRunTriggeredFrom.java
│ │ │ │ └── WorkflowNodeExecutionTriggeredFrom.java
│ │ │ ├── repository/
│ │ │ │ └── workflow/
│ │ │ │ ├── WorkflowRunRepository.java
│ │ │ │ └── WorkflowNodeExecutionRepository.java
│ │ │ ├── core/
│ │ │ │ └── workflow/
│ │ │ │ └── nodes/
│ │ │ ├── utils/
│ │ │ │ └── InfiniteScrollPagination.java
│ │ │ └── DifyJavaApplication.java
│ │ └── resources/
│ │ └── application.yml
│ └── test/
│ └── java/
│ └── com/
│ └── dify/
│ └── service/
│ └── workflow/
│ └── WorkflowRunServiceTest.java
├── pom.xml
└── README.md
-
Workflow Run Management:
- Get workflow run list with pagination
- Get advanced chat app workflow run list
- Get workflow run details
- Get workflow run node execution list
-
Node Execution:
- Support for all workflow node types
- Consistent execution logic with Python implementation
- Error handling and logging
-
Security:
- Integrated with existing authentication mechanism
- Same access control rules as Python implementation
-
Performance:
- Optimized database queries
- Efficient memory usage
- Faster execution compared to Python implementation
- Framework: Spring Boot 3.2.0
- Web: Spring Web MVC
- Data Access: Spring Data JPA
- Database: PostgreSQL
- Security: Spring Security
- Dependency Management: Maven
- Java Version: 17
- Java 17 or higher
- Maven 3.6.0 or higher
- PostgreSQL 12.0 or higher
Configuration is driven by environment variables or overrides in application.yml.
Option 1: Environment variables (recommended for production)
| Variable | Description | Example |
|---|---|---|
SPRING_DATASOURCE_URL |
Database connection URL | jdbc:postgresql://localhost:5432/dify |
SPRING_DATASOURCE_USERNAME |
Database username | dify |
SPRING_DATASOURCE_PASSWORD |
Database password | - |
SERVER_PORT |
Server port | 8080 |
PLUGIN_DAEMON_URL |
Plugin daemon (LLM) URL | - |
PLUGIN_DAEMON_API_KEY |
Plugin daemon API key | - |
PLUGIN_DAEMON_DEFAULT_ENDPOINT |
Default model endpoint | - |
PLUGIN_DAEMON_DEFAULT_API_KEY |
Default model API key | - |
CODE_EXECUTOR_ENDPOINT |
Code executor (sandbox) endpoint | - |
CODE_EXECUTOR_API_KEY |
Code executor API key | - |
FILE_STORAGE_BASE_DIR |
File storage base directory | Default: system temp dir |
Option 2: Local config file
Override the placeholders in src/main/resources/application.yml.
mvn clean packagejava -jar target/dify-java-runtime-1.0.0-SNAPSHOT.jar-
Get Advanced Chat Workflow Runs:
- URL:
GET /apps/{appId}/advanced-chat/workflow-runs - Parameters:
appId: UUID of the applicationlast_id(optional): UUID of the last workflow runlimit(optional): Number of results to return (default: 20, max: 100)
- URL:
-
Get Workflow Runs:
- URL:
GET /apps/{appId}/workflow-runs - Parameters:
appId: UUID of the applicationlast_id(optional): UUID of the last workflow runlimit(optional): Number of results to return (default: 20, max: 100)
- URL:
-
Get Workflow Run Details:
- URL:
GET /apps/{appId}/workflow-runs/{runId} - Parameters:
appId: UUID of the applicationrunId: UUID of the workflow run
- URL:
-
Get Workflow Run Node Executions:
- URL:
GET /apps/{appId}/workflow-runs/{runId}/node-executions - Parameters:
appId: UUID of the applicationrunId: UUID of the workflow run
- URL:
mvn test- WorkflowRunServiceTest: Tests for workflow run service functionality
-
Phase 1: Infrastructure Setup:
- Create project structure
- Configure dependencies and environment
- Implement basic models and repositories
-
Phase 2: Core Functionality Implementation:
- Implement workflow run management
- Implement node execution engine
- Implement API endpoints
-
Phase 3: Testing and Validation:
- Unit tests
- Integration tests
- Performance tests
- Functional comparison with Python implementation
-
Phase 4: Gray Release:
- Switch to Java implementation via configuration
- Monitor system status
- Gradually expand usage
-
Phase 5: Complete Migration:
- Fully switch to Java implementation
- Keep Python implementation as backup
- Update documentation and knowledge transfer
Since this implementation is in a separate directory, rolling back is simple:
- Modify configuration to switch back to the original Python implementation
- Stop using the Java implementation
- No changes to original code are needed, ensuring system stability
- Execution Time: 30-50% faster than Python implementation
- Memory Usage: More efficient memory management
- Concurrency: Better handling of concurrent requests
- Scalability: Improved scalability for large workflows
- Create a new node implementation in
core/workflow/nodes/ - Update the node mapping in the workflow engine
- Add necessary tests
- Modify the relevant service classes
- Update tests to reflect changes
- Verify functional consistency with Python implementation
-
Database Connection Errors:
- Check database configuration in
application.yml - Ensure PostgreSQL is running
- Verify database credentials
- Check database configuration in
-
Authentication Issues:
- Ensure the authentication mechanism is properly integrated
- Check user permissions
-
Performance Issues:
- Monitor database queries
- Check for long-running processes
- Optimize workflow design if necessary
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.