{"id":30216755,"url":"https://github.com/dimplesy/fastapi-ai-starter","last_synced_at":"2025-08-14T03:50:01.371Z","repository":{"id":294683535,"uuid":"987510775","full_name":"DimplesY/fastapi-ai-starter","owner":"DimplesY","description":"🚀 现代化 FastAPI 项目模板 | Modern FastAPI template with Celery + PostgreSQL + Redis + Docker. Production-ready starter kit.","archived":false,"fork":false,"pushed_at":"2025-08-05T05:09:57.000Z","size":381,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-05T07:09:08.171Z","etag":null,"topics":["ai","celery","fastapi","postgresql","template"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DimplesY.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-21T07:21:21.000Z","updated_at":"2025-08-05T07:06:35.000Z","dependencies_parsed_at":"2025-05-21T15:48:28.215Z","dependency_job_id":"6ee03553-4113-4c6b-9d33-27b17a0a3f7b","html_url":"https://github.com/DimplesY/fastapi-ai-starter","commit_stats":null,"previous_names":["dimplesy/fastapi_celery_test","dimplesy/fastapi_celery_starter","dimplesy/fastapi-ai-starter"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/DimplesY/fastapi-ai-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimplesY%2Ffastapi-ai-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimplesY%2Ffastapi-ai-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimplesY%2Ffastapi-ai-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimplesY%2Ffastapi-ai-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DimplesY","download_url":"https://codeload.github.com/DimplesY/fastapi-ai-starter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimplesY%2Ffastapi-ai-starter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270359005,"owners_count":24570445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","celery","fastapi","postgresql","template"],"created_at":"2025-08-14T03:49:58.761Z","updated_at":"2025-08-14T03:50:01.327Z","avatar_url":"https://github.com/DimplesY.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI AI Starter\n\n\u003e 🚀 一个现代化的 FastAPI 项目模板，集成 Celery 异步任务处理、PostgreSQL 数据库和 Redis 缓存\n\n![Python](https://img.shields.io/badge/Python-3.12+-blue.svg)\n![FastAPI](https://img.shields.io/badge/FastAPI-0.115+-green.svg)\n![License](https://img.shields.io/badge/License-MIT-yellow.svg)\n\n## ✨ 特性\n\n- 🌟 **现代 FastAPI** - 基于最新的 FastAPI 框架，支持自动 API 文档生成\n- ⚡ **异步任务处理** - 集成 Celery + Redis，支持后台任务和定时任务\n- 🗄️ **数据库集成** - PostgreSQL + SQLModel，支持自动迁移和类型安全\n- 🔐 **身份认证** - JWT Token 认证，密码加密存储\n- 📄 **分页查询** - 内置分页支持，优化大数据集查询性能\n- 🐳 **容器化部署** - 完整的 Docker 配置，支持一键部署\n- 📊 **进程管理** - Supervisord 配置，支持多进程管理\n- 🔧 **开发工具** - 集成 Ruff、MyPy、Pre-commit 等开发工具\n- 📝 **结构化日志** - Loguru 日志管理，支持结构化日志输出\n\n## 🏗️ 技术栈\n\n### 核心框架\n- **[FastAPI](https://fastapi.tiangolo.com/)** - 现代、快速的 Web 框架\n- **[Celery](https://docs.celeryq.dev/)** - 分布式任务队列\n- **[SQLModel](https://sqlmodel.tiangolo.com/)** - SQL 数据库的类型安全 ORM\n\n### 数据存储\n- **[PostgreSQL](https://www.postgresql.org/)** - 主数据库（支持向量扩展）\n- **[Redis](https://redis.io/)** - 缓存和消息代理\n\n### 开发工具\n- **[UV](https://github.com/astral-sh/uv)** - 现代 Python 包管理器\n- **[Alembic](https://alembic.sqlalchemy.org/)** - 数据库迁移工具\n- **[Ruff](https://github.com/astral-sh/ruff)** - 极速 Python 代码检查和格式化\n- **[Loguru](https://github.com/Delgan/loguru)** - 简单易用的日志库\n\n## 📦 项目结构\n\n```\nfastapi-ai-starter/\n├── app/                      # 主应用目录\n│   ├── api/                  # API 路由\n│   │   ├── v1/              # API 版本 1\n│   │   └── router.py        # 路由配置\n│   ├── services/            # 业务服务层\n│   │   ├── auth/            # 认证服务\n│   │   ├── database/        # 数据库服务\n│   │   └── settings/        # 配置管理\n│   └── main.py              # FastAPI 应用创建\n├── celery_tasks/            # Celery 任务\n│   ├── workers/             # 任务定义\n│   ├── celery.py           # Celery 应用\n│   └── celeryconfig.py     # Celery 配置\n├── alembic/                 # 数据库迁移文件\n├── scripts/                 # 辅助脚本\n├── nginx/                   # Nginx 配置\n├── compose.yaml             # Docker Compose 配置\n├── supervisord.conf         # 进程管理配置\n└── pyproject.toml          # 项目配置\n```\n\n## 🚀 快速开始\n\n### 环境要求\n\n- Python 3.12+\n- Docker \u0026 Docker Compose (推荐)\n- PostgreSQL 16+ (本地开发)\n- Redis 7+ (本地开发)\n\n### 1. 克隆项目\n\n```bash\ngit clone https://github.com/your-username/fastapi-ai-starter.git\ncd fastapi-ai-starter\n```\n\n### 2. 安装依赖\n\n使用 UV 安装依赖（推荐）：\n\n```bash\n# 安装 UV\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n\n# 安装项目依赖\nuv sync\n```\n\n### 3. 启动服务\n\n#### 方式一：Docker Compose（推荐）\n\n```bash\n# 启动所有服务\ndocker-compose up -d\n\n# 查看服务状态\ndocker-compose ps\n\n# 查看日志\ndocker-compose logs -f\n```\n\n#### 方式二：本地开发\n\n1. **启动数据库和 Redis**\n   ```bash\n   # 启动 PostgreSQL 和 Redis\n   docker-compose up -d pgvector redis\n   ```\n\n2. **数据库迁移**\n   ```bash\n   # 执行数据库迁移\n   alembic upgrade head\n   ```\n\n3. **启动应用**\n   ```bash\n   # 使用 Supervisord（推荐）\n   supervisord -c supervisord.conf\n   \n   # 或分别启动各个服务\n   uv run main.py                                    # FastAPI 应用\n   uv run celery -A celery_tasks worker --loglevel=INFO  # Celery Worker\n   uv run celery -A celery_tasks beat --loglevel=INFO    # Celery Beat\n   ```\n\n### 4. 验证安装\n\n访问以下地址验证服务是否正常：\n\n- **API 文档**: http://localhost:8000/docs\n- **ReDoc 文档**: http://localhost:8000/redoc\n\n## 🔧 开发指南\n\n### 数据库迁移\n\n```bash\n# 生成新的迁移文件\n./scripts/migration.sh \"添加新功能\"\n\n# 应用迁移\n./scripts/migrate.sh\n\n# 或直接使用 alembic\nalembic revision --autogenerate -m \"migration message\"\nalembic upgrade head\n```\n\n### 添加新的 API 端点\n\n1. 在 `app/api/v1/` 下创建新的路由文件\n2. 在 `app/api/v1/__init__.py` 中导入并注册路由\n3. 编写相应的业务逻辑和数据模型\n\n### 添加 Celery 任务\n\n1. 在 `celery_tasks/workers/` 下创建任务文件\n2. 在 `celery_tasks/celeryconfig.py` 中注册任务\n3. 使用 `@app.task` 装饰器定义任务\n\n### 代码质量检查\n\n```bash\n# 代码格式化和检查\nuv run ruff check .\nuv run ruff format .\n\n# 类型检查\nuv run mypy .\n\n# 运行 pre-commit 钩子\npre-commit run --all-files\n```\n\n## 📚 API 文档\n\n启动服务后，可以通过以下地址访问 API 文档：\n\n- **Swagger UI**: http://localhost:8000/docs\n- **ReDoc**: http://localhost:8000/redoc\n\n## 🐳 部署指南\n\n### Docker 部署\n\n```bash\n# 构建镜像\ndocker build -t fastapi-ai-starter .\n\n# 启动服务\ndocker-compose up -d\n\n# 扩展 Worker 数量\ndocker-compose up -d --scale web=3\n```\n\n### 生产环境配置\n\n1. 修改 `compose.yaml` 中的环境变量\n2. 配置 SSL 证书（nginx 配置）\n3. 设置数据库连接密码\n4. 配置日志持久化\n\n## 🤝 贡献指南\n\n1. Fork 本仓库\n2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)\n3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)\n4. 推送到分支 (`git push origin feature/AmazingFeature`)\n5. 创建 Pull Request\n\n## 📄 许可证\n\n本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情\n\n## 🆘 支持\n\n如果你遇到问题或有任何建议，请：\n\n1. 查看 [Issues](https://github.com/your-username/fastapi-ai-starter/issues)\n2. 创建新的 Issue\n3. 参与 [Discussions](https://github.com/your-username/fastapi-ai-starter/discussions)\n\n---\n\n⭐ 如果这个项目对你有帮助，请给它一个 Star！\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimplesy%2Ffastapi-ai-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdimplesy%2Ffastapi-ai-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimplesy%2Ffastapi-ai-starter/lists"}