Files
mindfulness/spec_kit/Project Bootstrap/tasks.md
吕新雨 049995692d init
2026-01-28 20:50:17 +08:00

126 lines
5.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Project Bootstrap任务清单
> 说明:本清单用于把 `plan.md` 拆成“可逐条执行”的任务。执行完成后请把对应项从 `[ ]` 勾选为 `[x]`。
## 0. 约定与前置
- [ ] **确认后端依赖管理方式**:使用 `requirements.txt + pip`
- [ ] **确认环境**:仅 dev / prod
- [ ] **确认 Redis 方案**:单实例 + ACL`dev:*`/`pro:*`+ prod `maxmemory=256mb`(硬限制)
- [ ] **确认迁移工具**Alembic
- [ ] **确认部署方式**MySQL/Redis 已部署,后端通过环境变量连接(不做 Docker 起 MySQL/Redis
## A. 现有 MySQL/Redis 验证与环境隔离确认
### A1. MySQLschema确认
- [ ] 确认 dev schema`mindfulness_dev` 已存在(字符集 `utf8mb4`
- [ ] 确认 prod schema`mindfulness` 已存在(字符集 `utf8mb4`
### A2. RedisACL + maxmemory=256MB确认
- [ ] 确认 Redis 已启用 ACL并存在账号
- [ ] `dev_user` 仅允许访问 `~dev:*`
- [ ] `pro_user` 仅允许访问 `~pro:*`
- [ ] 确认生产环境 Redis 内存限制:
- [ ] `maxmemory=256mb` 生效
- [ ] `maxmemory-policy=noeviction` 生效(队列优先,不丢任务)
### A3. Redis ACL 验收(必须可复现)
- [ ] 使用 `dev_user` 写入 `dev:test=1` 成功
- [ ] 使用 `dev_user` 写入 `pro:test=1` 失败(权限不足)
- [ ] 使用 `pro_user` 写入 `pro:test=1` 成功
- [ ] 使用 `pro_user` 写入 `dev:test=1` 失败(权限不足)
### A4. 可选:把现有配置“备份到仓库”(不参与部署)
- [ ] (可选)新建 `infra/redis/users.acl`(把线上 ACL 规则复制备份,注意去掉真实密码)
- [ ] (可选)新建 `infra/redis/redis.prod.conf`把线上关键参数备份maxmemory/noeviction/aclfile 等)
- [ ] (可选)新建 `infra/mysql/init/00-create-schemas.sql`(备份 schema 创建脚本)
## B. 后端工程骨架server/)落地
> 当前 `server/` 目录可能尚未创建代码文件,本阶段目标是“能启动、能连库、能跑迁移、能跑 Celery”。
### B1. 依赖与环境变量模板
- [ ] 新增 `server/requirements.txt`
- [ ] FastAPI、uvicorn
- [ ] SQLAlchemy 2.x异步+ MySQL driver`aiomysql`
- [ ] pydantic-settingspydantic v2
- [ ] alembic
- [ ] celery、redisPython 客户端)
- [ ] pytest
- [ ] 新增 `server/.env.example`(仅字段结构,不含真实值)
- [ ] `APP_ENV=dev|prod`
- [ ] `DATABASE_URL=.../mindfulness_dev`dev`.../mindfulness`prod
- [ ] `REDIS_URL=redis://<user>:<pass>@<REDIS_HOST>:6379/0`
- [ ] `CELERY_BROKER_URL=redis://<user>:<pass>@<REDIS_HOST>:6379/0`
- [ ] (默认不写)`CELERY_RESULT_BACKEND`
### B2. FastAPI 最小入口
- [ ] 新增 `server/app/main.py`
- [ ] 创建 FastAPI 实例 `app`
- [ ] 增加健康检查接口 `/healthz`
- [ ] 新增 `server/app/core/config.py`
- [ ] 使用 `pydantic-settings`
- [ ] 根据 `APP_ENV` 加载 `.env.dev` / `.env.prod`
### B3. SQLAlchemy 与数据库连接
- [ ] 新增 `server/app/db/`(目录)
- [ ] 新增 `server/app/db/session.py`
- [ ]`DATABASE_URL` 创建 async engine
- [ ] 提供 session 工厂
### B4. Alembic 初始化
- [ ] 初始化 Alembic
- [ ] 生成 `server/alembic.ini`
- [ ] 生成 `server/alembic/`env.py / versions/
- [ ] 配置从环境变量读取数据库连接
- [ ] 验收:
- [ ] 能执行 `alembic revision -m "init"`(即使空迁移也可)
- [ ] 能执行 `alembic upgrade head`
## C. Celery 最小闭环Redis broker + 队列前缀)
### C1. Celery 入口与任务示例
- [ ] 新增 `server/app/worker.py`
- [ ] Celery 初始化使用 `CELERY_BROKER_URL`
- [ ] 默认 **不启用** result backend或仅 dev 可选)
- [ ] 配置默认队列名带环境前缀(例如 `dev:push` / `pro:push`
- [ ] 新增 1 个示例任务(例如 `server/app/tasks/ping.py`
- [ ] 任务只传小参数(如字符串/ID
### C2. Worker/Beat 启动与验收
- [ ] Worker 验收:
- [ ] `celery -A app.worker:celery_app worker -l info` 可启动
- [ ] 发送任务后能被消费
- [ ] Beat如需要定时
- [ ] `celery -A app.worker:celery_app beat -l info` 可启动
- [ ] 能按周期触发示例任务
## D. 文档与验收补全
### D1. 更新 README 与约定一致
- [ ] 更新 `server/README.md`
- [ ] 明确:`requirements.txt + pip` 作为依赖安装方式
- [ ] 明确dev/pro MySQL schema`mindfulness_dev`/`mindfulness`
- [ ] 明确Redis ACL + key 前缀、prod `maxmemory=256mb` 硬限制
- [ ] 明确Celery 默认不启用 result backend或启用需 TTL
- [ ] (可选)更新根 `README.md`
- [ ] 追加:基础设施依赖与 dev/pro 隔离约定摘要
### D2. 最终验收清单(完成后统一勾选)
- [ ] **环境隔离**dev/pro MySQL schema 与 Redis ACL 均生效
- [ ] **资源约束**prod Redis `maxmemory=256mb` 生效
- [ ] **可运行性**FastAPI/Celery 可启动并完成最小任务闭环(依赖通过环境变量连接现有 MySQL/Redis