# fastapt-agent **Repository Path**: python_90/fastapt-agent ## Basic Information - **Project Name**: fastapt-agent - **Description**: fastapt-agent - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-09-24 - **Last Updated**: 2026-09-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🚀 fastapt-agent > 基于 **FastAPI** 的分层架构项目,异步 ORM + 邮件 + 数据库迁移。 --- ## 📦 技术栈 | 类别 | 选型 | | ---------- | ----------------------------- | | Web 框架 | FastAPI + Uvicorn | | ORM | SQLAlchemy 2.x(异步) | | 数据库 | MySQL(aiomysql 异步驱动) | | 数据库迁移 | Alembic(异步) | | 密码哈希 | pwdlib(argon2) | | 邮件 | fastapi-mail | | 包管理 | uv | | Python | ≥ 3.14 | --- ## 📁 目录结构 ```text . ├── main.py # 🚪 程序入口:FastAPI 实例 + 路由 ├── dependencies.py # 🔌 全局依赖:get_mail 邮件实例 ├── alembic.ini # 🔄 Alembic 迁移配置 │ ├── core/ # 🧱 核心层 │ └── mail.py # 邮件:FastMail 实例工厂 ├── models/ # 🗃️ 模型层:SQLAlchemy ORM │ ├── __init__.py # 异步引擎 + 会话工厂 + Base │ └── user.py # User 用户表 + EmailCode 验证码表 ├── settings/ # ⚙️ 配置层:DB / 邮件配置 │ └── __init__.py ├── migrations/ # 🔄 Alembic 迁移脚本 ├── routers/ # 🛣️ 路由层(待实现) └── repository/ # 💾 仓储层(待实现) ``` ### 🔗 分层调用链 ```text 请求 → main.py 路由 → dependencies(依赖注入) ↓ core(邮件等) / models → MySQL ``` --- ## 🚦 已实现接口 | 方法 | 路径 | 说明 | | ------ | ------------------- | -------------- | | GET | `/` | 健康检查 | | GET | `/hello/{name}` | 示例接口 | | POST | `/send-email-code` | 发送邮箱验证码 | --- ## 🗃️ 数据库表 | 表名 | 说明 | | ----------- | ---------------------- | | `user` | 用户表(密码自动哈希) | | `email_code`| 邮箱验证码表 | --- ## 🏁 快速开始 ```bash # 1. 安装依赖 uv sync # 2. 启动开发服务 uv run uvicorn main:app --reload # 3. 打开接口文档 # Swagger UI: http://127.0.0.1:8000/docs # ReDoc: http://127.0.0.1:8000/redoc ``` > 数据库默认连 `mysql+aiomysql://root:root@127.0.0.1:3306/ai_db`,配置在 `settings/__init__.py`。 --- ## 🔄 数据库迁移 ```bash # 生成迁移脚本 uv run alembic revision --autogenerate -m "描述" # 执行迁移 uv run alembic upgrade head # 回滚一步 uv run alembic downgrade -1 ``` --- ## 📌 约定 - **命名**:代码用英文,注释/文档用中文 - **编码**:全项目 UTF-8 - **分层**:路由不直接操作数据库,必须经 `repository` - **密码**:`User(password="明文")` 自动哈希,禁止明文入库 --- ## 🌐 仓库 | 平台 | 地址 | | ----- | --------------------------------------------- | | Gitee | https://gitee.com/python_90/fastapt-agent.git | --- ## 📄 License MIT