Jflow Backend README

项目结构

jflow/
├── frontend/          # Vue 3 前端
├── backend/           # FastAPI 后端
│   ├── app/
│   │   ├── __init__.py
│   │   ├── main.py         # FastAPI 应用入口
│   │   ├── routes/
│   │   │   ├── __init__.py
│   │   │   └── nodes.py    # 节点执行路由
│   │   ├── services/
│   │   │   ├── __init__.py
│   │   │   └── executor.py # 节点执行器
│   │   ├── models/
│   │   │   └── __init__.py
│   │   └── utils/
│   │       └── __init__.py
│   ├── nodes/         # 节点实现目录
│   │   ├── language_python/
│   │   │   ├── language_python.py
│   │   │   └── language_python.json
│   │   ├── language_go/
│   │   │   ├── language_go.go
│   │   │   └── language_go.json
│   │   ├── language_rust/
│   │   │   ├── language_rust.rs
│   │   │   └── language_rust.json
│   │   └── data_processing/
│   │       ├── data_processing.py
│   │       └── data_processing.json
│   ├── config.py      # 配置文件
│   ├── requirements.txt
│   └── run.py         # 启动脚本
└── README.md

核心特性

1. 统一执行路径

所有节点都使用统一的执行路径:

POST /api/action/nodes.{node_type}.{node_type}.execute

2. 多语言支持

  • Python节点:直接导入执行
  • Go节点:编译后执行
  • Rust节点:编译后执行

3. 异步执行

使用FastAPI的异步特性支持并发执行多个节点。

快速开始

1. 安装依赖

cd backend
pip install -r requirements.txt

2. 启动服务

python run.py

3. 访问API文档

打开浏览器访问:http://localhost:8000/docs

API使用示例

执行Python节点

curl -X POST "http://localhost:8000/api/action/nodes.language_python.language_python.execute" \
  -H "Content-Type: application/json" \
  -d '{
    "context": {"timestamp": "2024-01-01"},
    "inputs": {},
    "config": {
      "code": "print(\"Hello from Python!\")\noutput = \"Python执行成功\""
    }
  }'

执行Go节点

curl -X POST "http://localhost:8000/api/action/nodes.language_go.language_go.execute" \
  -H "Content-Type: application/json" \
  -d '{
    "context": {"timestamp": "2024-01-01"},
    "inputs": {},
    "config": {
      "code": "package main\nimport \"fmt\"\nfunc main() { fmt.Println(\"Hello from Go!\") }"
    }
  }'

执行Rust节点

curl -X POST "http://localhost:8000/api/action/nodes.language_rust.language_rust.execute" \
  -H "Content-Type: application/json" \
  -d '{
    "context": {"timestamp": "2024-01-01"},
    "inputs": {},
    "config": {
      "code": "fn main() { println!(\"Hello from Rust!\"); }"
    }
  }'

开发新节点

1. 创建节点目录

mkdir -p nodes/my_new_node

2. 实现节点逻辑

创建 my_new_node.py(或其他语言文件):

def execute(context=None, inputs=None, config=None):
    # 节点执行逻辑
    return {
        "success": True,
        "result": "节点执行成功"
    }

3. 创建节点配置

创建 my_new_node.json

{
  "name": "我的新节点",
  "description": "节点描述",
  "version": "1.0.0",
  "category": "custom"
}

4. 测试节点

curl -X POST "http://localhost:8000/api/action/nodes.my_new_node.my_new_node.execute" \
  -H "Content-Type: application/json" \
  -d '{"context": {}, "inputs": {}, "config": {}}'

环境要求

  • Python 3.8+
  • Go 1.19+ (用于Go节点)
  • Rust 1.70+ (用于Rust节点)

配置说明

config.py 中可以配置:

  • 节点超时时间
  • 内存限制
  • CORS设置
  • 日志级别