邮件数据监控系统:自动拉取邮箱邮件,通过 AI 提取结构化信息,生成每日汇总报告并发送。
- Python >= 3.12
- Node.js >= 18
- MySQL 8.0+
- Git
git clone https://github.com/gnitiaw/mail_ds_monitor.git
cd mail_ds_monitorcd back_end
# Create virtual environment
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # Linux/macOS
# Install dependencies (includes dev tools: pytest, ruff)
pip install -e ".[dev]"
# Configure environment
cp .env.example .env
# Edit .env — at minimum set MySQL credentials and LLM API keyKey .env fields to configure:
| Field | Description |
|---|---|
MYSQL_HOST / MYSQL_PORT / MYSQL_DATABASE / MYSQL_USER / MYSQL_PASSWORD |
Database connection |
LLM_BASE_URL / LLM_API_KEY / LLM_MODEL |
AI extraction (OpenAI-compatible endpoint) |
SECRET_KEY |
JWT signing key (change from default!) |
Set DB_AUTO_CREATE_TABLES=true for auto table creation on first run.
# Start backend
uvicorn app.main:app --reloadBackend runs at http://localhost:8000, API docs at http://localhost:8000/docs.
cd front_end
npm install
npm run devFrontend runs at http://localhost:5173, proxies /api to backend.
cd back_end
.venv\Scripts\activate
python scripts/seed_pilot_data.pyCreates demo users: admin / admin123 (admin role), operator / operator123 (operator role).
Open http://localhost:5173, log in with admin / admin123.
Monorepo, 前后端分离,REST API 通信。
Backend (FastAPI + SQLAlchemy + MySQL):
app/api/v1/— REST 路由,按领域组织app/services/— 业务逻辑层(IMAP、AI 提取、SMTP、调度)app/models/— SQLAlchemy ORM 模型app/schemas/— Pydantic 请求/响应 schemaapp/core/— 配置、安全(JWT)、异常处理
Frontend (React 19 + TypeScript + Ant Design 6 + Vite 8):
src/pages/— 按功能域组织的页面组件src/components/— 共享组件(Layout、AuthRoute)src/api/— Axios API 客户端
cd back_end
uvicorn app.main:app --reload # Dev server :8000
pytest # Run tests
pytest app/tests/test_xxx.py -k "test_name" # Single test
ruff check . # Lint
ruff check . --fix # Auto-fix lint issuescd front_end
npm run dev # Dev server :5173
npm run build # Production build (tsc + vite)
npm run lint # ESLint
npm run test # Vitest (watch mode)
npm run test:run # Vitest (single run)- IMAP 拉取邮件 →
mail_messages表 - AI (LLM) 提取结构化数据 →
archive_records表 - 提取失败的邮件进入
failure_mail_queue,支持重试 - 每日汇总按
summary_configs配置生成并发送 - 发件人画像关联客户分析
- 服务报告聚合多源数据(巡检、漏洞、工时、禅道缺陷)
mail_ds_monitor/
├─ back_end/ # Backend (FastAPI)
├─ front_end/ # Frontend (React + Vite)
├─ scripts/ # Utility scripts (seed data, migrations)
├─ docs/
│ ├─ features/ # Feature specifications
│ ├─ contracts/ # API contracts
│ ├─ reviews/ # Review records
│ └─ release-notes/ # Release notes
├─ CLAUDE.md # AI assistant instructions
└─ DESIGN.md # Clay design system spec
- 新功能先完成
docs/features/功能说明和docs/contracts/接口契约 - 接口契约变更需输出 diff、影响分析、兼容性说明
- 所有变更可 review、可测试、可回滚