feat(backend): 搭建 FastAPI 分层骨架 — 配置加载 / 健康检查 / SQLAlchemy+Alembic 就位

- uv 工程(Python 3.12,pyproject + uv.lock,dev: pytest/ruff)
- 分层包结构:api / application / domain / infrastructure / quant(qlib_adapter) / agent / core
- app.core.config:加载根 config.yaml + .env,sqlite 相对路径解析到项目根 data/
- SQLAlchemy Base + Session 工厂(Infrastructure 层,业务走 Repository)
- Alembic 迁移环境就位(env.py 复用应用配置,render_as_batch 兼容 SQLite)
- GET /api/health + pytest 冒烟 6 项通过 / ruff clean / uvicorn 启动验证
This commit is contained in:
Simon
2026-09-06 16:09:10 +08:00
parent 8eb3b4ac2a
commit 2a52ee5e83
32 changed files with 1443 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
"""HTTP API 层。
约束(AGENT.md §17/§18):
- 路由面向业务对象(/api/stocks、/api/factors、/api/backtests ...),不暴露 Qlib / SQL
- 输入输出一律 Pydantic DTO,禁止把 ORM Model 直接暴露
- 耗时任务返回 job_id,不长时间阻塞 HTTP
"""
+19
View File
@@ -0,0 +1,19 @@
"""系统健康检查。"""
from __future__ import annotations
from fastapi import APIRouter
from app.core.config import get_settings
router = APIRouter(tags=["system"])
@router.get("/health", summary="健康检查")
def health() -> dict:
settings = get_settings()
return {
"status": "ok",
"app": settings.app_name,
"version": settings.app_version,
}
+14
View File
@@ -0,0 +1,14 @@
"""API 路由聚合。
后续业务路由按 AGENT.md §17 面向业务对象挂载:
/api/stocks /api/universes /api/factors /api/strategies /api/backtests /api/experiments /api/jobs
"""
from __future__ import annotations
from fastapi import APIRouter
from app.api import health
api_router = APIRouter()
api_router.include_router(health.router)