将框架从 Flask 迁移到 FastAPI

主要改动:
- 更新依赖:使用 fastapi、uvicorn 替代 Flask
- 数据库层:从 Flask-SQLAlchemy 迁移到纯 SQLAlchemy
- 新增 database.py 管理数据库连接和会话
- 路由层:从 Blueprint 迁移到 APIRouter,添加 Pydantic 模型验证
- 应用层:使用 FastAPI 中间件替代 Flask 插件
- 启动方式:使用 uvicorn 替代 Flask 开发服务器
- 更新 Docker 配置以支持 FastAPI

优势:
- 更高的性能和异步支持
- 自动生成 OpenAPI 文档
- 更好的类型安全和数据验证
- 所有 API 端点保持向后兼容

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-31 10:12:22 +00:00
parent ebd31e2716
commit 6ecd95ad5d
10 changed files with 423 additions and 352 deletions

View File

@@ -38,7 +38,7 @@ OPENAI_API_KEY=your_openai_api_key_here
# 数据库配置
DATABASE_URL=sqlite:///worklist.db
# Flask配置
# FastAPI配置
SECRET_KEY=your-secret-key-here
""")
print("✓ 环境变量文件已创建: backend/.env")
@@ -49,8 +49,8 @@ def start_server():
print("正在启动服务器...")
os.chdir("backend")
try:
# 启动Flask应用
subprocess.run([sys.executable, "app.py"])
# 启动FastAPI应用 (使用uvicorn)
subprocess.run([sys.executable, "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "5000", "--reload"])
except KeyboardInterrupt:
print("\n服务器已停止")
except Exception as e: