OpenCode Backend
基于 Python + FastAPI 的后端服务项目
项目结构
OpenCode-backend/
├── app/
│ ├── __init__.py
│ ├── main.py # 应用主入口
│ ├── core/ # 核心配置
│ │ ├── __init__.py
│ │ └── config.py # 应用配置
│ ├── routers/ # 路由模块
│ │ ├── __init__.py
│ │ └── fs.py # 文件系统路由
│ └── schemas/ # Pydantic 模式
│ ├── __init__.py
│ └── project.py # 项目相关模式
├── requirements.txt
└── README.md
快速开始
1. 安装依赖
pip install -r requirements.txt
2. 启动服务
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
3. 访问 API 文档
启动后访问:http://localhost:8000/docs
API 接口
创建项目
接口: POST /fs/project/create
请求体:
{
"project_name": "我的项目"
}
响应:
{
"success": true,
"message": "项目 '我的项目' 创建成功",
"project_path": "/root/workspace/我的项目"
}
校验规则:
- 项目名称仅允许:中英文、数字、下划线 (_)、横杠 (-)
- 禁止包含路径逃逸字符:
../、/、\ - 所有项目被锁定在
/root/workspace目录内