# full-stack-fastapi-template **Repository Path**: mrzed/full-stack-fastapi-template ## Basic Information - **Project Name**: full-stack-fastapi-template - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-09-03 - **Last Updated**: 2024-09-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Full Stack FastAPI Template Test Coverage **中文** | [English](./README.en-US.md) ## 技术栈和特点 - ⚡ [**FastAPI**](https://fastapi.tiangolo.com) 用于Python后端API开发. - 🧰 [SQLModel](https://sqlmodel.tiangolo.com) 用于Python数据库交互 (ORM). - 🔍 [Pydantic](https://docs.pydantic.dev), 由FastAPI使用,用于数据验证和设置管理。 - 💾 [PostgreSQL](https://www.postgresql.org) 作为数据库。 - 🚀 [React](https://react.dev) 用于前端UI开发. - 💃 使用TypeScript、hooks、Vite和其他现代前端栈的部分 - 🎨 [Chakra UI](https://chakra-ui.com) 为前端UI组件库. - 🤖 自动生成前端客户端。 - 🧪 [Playwright](https://playwright.dev) 为端到端测试. - 🦇 支持黑暗模式。 - 🐋 [Docker Compose](https://www.docker.com) 用于容器化开发环境和生产环境。 - 🔒 安全性:默认使用安全的密码哈希算法。 - 🔑 JWT (JSON Web Token) 身份验证。 - 📫 基于电子邮件的密码恢复。 - ✅ 使用 [Pytest](https://pytest.org)进行测试. - 📞 [Traefik](https://traefik.io) 作为反向代理/负载平衡器。 - 🚢 使用Docker Compose的部署说明,包括如何设置前端Traefik代理来处理自动HTTPS证书。 - 🏭 基于GitHub Actions的CI(持续集成)和CD(持续部署)。 ### 后台登录页面 [![API docs](img/login.png)](https://github.com/fastapi/full-stack-fastapi-template) ### 后台-管理面板 [![API docs](img/dashboard.png)](https://github.com/fastapi/full-stack-fastapi-template) ### 后台-创建用户 [![API docs](img/dashboard-create.png)](https://github.com/fastapi/full-stack-fastapi-template) ### 后台 - Items [![API docs](img/dashboard-items.png)](https://github.com/fastapi/full-stack-fastapi-template) ### 后台 - 用户设置 [![API docs](img/dashboard-user-settings.png)](https://github.com/fastapi/full-stack-fastapi-template) ### 后台-黑暗模式 [![API docs](img/dashboard-dark.png)](https://github.com/fastapi/full-stack-fastapi-template) ### 交互式API文档 [![API docs](img/docs.png)](https://github.com/fastapi/full-stack-fastapi-template) ## 使用方法 你可以 **Fork或Clone** 该仓库到你的本地机器,然后使用。 ✨ It just works. ✨ ### 如何使用私有仓库 如果你想拥有一个私有存储库,GitHub不允许你简单地分叉它,因为它不允许改变分叉的可见性。 但是你可以这样做: - 创建一个新的GitHub仓库,例如“my-full-stack”。 - 手动克隆此存储库,使用要使用的项目名称设置名称,例如my-full-stack: ```bash git clone git@github.com:fastapi/full-stack-fastapi-template.git my-full-stack ``` - 进入新目录: ```bash cd my-full-stack ``` - 设置新的源到你的新存储库,从GitHub接口复制它,例如: ```bash git remote set-url origin git@github.com:octocat/my-full-stack.git ``` - 将此repo添加为另一个“远程”,以允许您稍后获得更新: ```bash git remote add upstream git@github.com:fastapi/full-stack-fastapi-template.git ``` - 将代码推送到新的存储库: ```bash git push -u origin master ``` ### 从原始模板更新 在克隆存储库并进行更改之后,您可能希望从这个原始模板获得最新的更改。 - 确保你将原始存储库添加为远程存储库,你可以使用: ```bash git remote -v origin git@github.com:octocat/my-full-stack.git (fetch) origin git@github.com:octocat/my-full-stack.git (push) upstream git@github.com:fastapi/full-stack-fastapi-template.git (fetch) upstream git@github.com:fastapi/full-stack-fastapi-template.git (push) ``` - 拉取最新的更改而不合并: ```bash git pull --no-commit upstream master ``` 这将从这个模板下载最新的更改而不提交它们,这样你就可以在提交之前检查一切是否正确。 - 如果有冲突,请在编辑器中解决它们。 - 完成后,提交更改: ```bash git merge --continue ``` ### 配置 然后,您可以在`.env`文件来定制您的配置。 在部署它之前,请确保您至少更改了以下值: - `SECRET_KEY` - `FIRST_SUPERUSER_PASSWORD` - `POSTGRES_PASSWORD` 您可以(也应该)将这些作为环境变量从secrets传递。 阅读[deployment.md](./deploy .md)文档了解更多细节。 ### 生成密钥 `.env`文件中的某些环境变量的默认值是`changethis`。 您必须使用密钥来更改它们,要生成密钥,可以运行以下命令: ```bash python -c "import secrets; print(secrets.token_urlsafe(32))" ``` 复制的内容用作密码/密钥,并再次运行一次以生成另一个安全密钥。 ## 如何使用 Copier 生成项目 此存储库还支持使用[Copier](https://copier.readthedocs.io)生成新项目。 它将复制所有文件,询问您配置问题,并将答案更新到`.env`文件中。 ### 安装 Copier 你可以使用以下命令安装 Copier: ```bash pip install copier ``` 或者,如果你有[`pipx`](https://pipx.pypa.io/),你可以运行它: ```bash pipx install copier ``` **注意**:如果你有`pipx`,安装Copier是可选的,你可以直接运行它。 ### 使用 Copier 生成项目 决定一个新项目的目录名称,你将在下面使用它。例如,`my-awesome-project`。 在终端中,切换到将成为项目父目录的目录,并运行以下命令: ```bash copier copy https://github.com/fastapi/full-stack-fastapi-template my-awesome-project --trust ``` 如果您有`pipx`,并且没有安装`copier`,您可以直接运行它: ```bash pipx run copier copy https://github.com/fastapi/full-stack-fastapi-template my-awesome-project --trust ``` **注意**:`--trust`选项是必需的,以便可以执行[后期创建脚本](https://github.com/fastapi/full-stack-fastapi-template/blob/master/.copier/update_dotenv.py),该脚本将更新`.env`文件。 ### 输入变量 Copier将要求您提供一些数据,在生成项目之前,您可能需要有所准备。 但是不要担心,您可以在生成项目后随时更新`.env`文件中的任何变量。 输入变量及其默认值(有些自动生成)如下: - `project_name`: (default: `"FastAPI Project"`) 项目名称,显示给API用户。 - `stack_name`: (default: `"fastapi-project"`) 堆栈名称,用于Docker Compose标签和项目名称(没有空格,没有句点)(在.env中)。 - `secret_key`: (default: `"changethis"`) 项目的密钥,用于安全,存储在.env中,可以使用上述方法生成。 - `first_superuser`: (default: `"admin@example.com"`) 超级用户的电子邮件(在.env中)。 - `first_superuser_password`: (default: `"changethis"`) 第一个超级用户的密码(在.env中)。 - `smtp_host`: (default: "") 发送电子邮件的SMTP服务器主机,可以在.env中稍后设置。 - `smtp_user`: (default: "") 发送电子邮件的SMTP服务器用户,可以在.env中稍后设置。 - `smtp_password`: (default: "") 发邮件的SMTP服务器密码,可以在.env中稍后设置。 - `emails_from_email`: (default: `"info@example.com"`) 发送邮件的电子邮件帐户,可以在.env中稍后设置。 - `postgres_password`: (default: `"changethis"`) PG数据库的密码,存储在.env中,可以使用上述方法生成。 - `sentry_dsn`: (default: "") The DSN for Sentry, if you are using it, you can set it later in .env. ## 后端开发文档 Backend docs: [backend/README.md](./backend/README.md). ## 前端开发文档 Frontend docs: [frontend/README.md](./frontend/README.md). ## 部署文档 Deployment docs: [deployment.md](./deployment.md). ## 开发文档 通用开发文档: [development.md](./development.md). 包括使用Docker Compose、自定义本地域、`.env`配置等。 ## 发布说明 发布说明: [release-notes.md](./release-notes.md). ## 许可证 Full Stack FastAPI Template 在MIT许可证下授权。