返回 MCP 目录
public公开dns本地运行

FastAPI最佳架构

FastAPI 最佳架构是一个企业级后端架构解决方案,基于 Python 3.10+ 和 FastAPI 框架构建。它采用类三层架构,提供清晰的分层结构,包括 API 层、Schema 层、服务层和 CRUD 层,支持 MySQL、PostgreSQL 等数据库,并集成了 SQLAlchemy、Pydantic 等工具。该架构旨在简化开发流程,提升代码可维护性,适用于中大型项目的快速开发。此外,项目支持 Docker 部署,并提供详细的文档和社区支持,帮助开发者快速上手。

article

README

FastAPI Best Architecture - Backend

Docker

  1. Make sure you're at the root of the project

  2. Run the following Docker command to build container:

    docker build -f Dockerfile -t fba_backend_independent .
    
  3. Start container

    Native boot needs to change 127.0.0.1 in .env to host.docker.internal

    docker run -d -p 8000:8000 --name fba_server fba_backend_independent
    

Contributing

  1. Prerequisites

    • Python >= 3.10
    • Git
    • uv
    • Fork this repository to your GitHub account
  2. Installation and setup

    Clone your forked repository:

    git clone https://github.com/<your account>/fastapi_best_architecture.git
    

    Go to the root directory of the project, open the terminal, and run the following command:

    uv sync --frozen
    
  3. Checkout

    Checkout a new branch and make your changes

    git checkout -b your-new-feature-branch
    
  4. Format and Lint

    Auto-formatting and lint via pre-commit

    pre-commit run --all-files
    
  5. Commit and push

    Commit your changes and push your branch to the GitHub.

  6. PR

    Create a PR via GitHub

Scripts

[!WARNING]

The following script may not apply to the Windows platform

It is recommended to execute under the backend directory, and chmod authorization may be required

  • pre_start.sh: Perform automatic database migration and create database tables

  • celery-start.sh: For celery docker script, implementation is not recommended

  • scripts/format.sh: Perform ruff format check

  • scripts/lint.sh: Perform pre-commit formatting

  • scripts/export.sh: Execute uv export dependency package

help

运行方式说明

cloud

托管运行

托管运行通常表示这个 MCP Server 由服务方环境承载,用户一般按页面提供的连接方式或授权流程接入,不需要在本地长期启动一个 MCP 进程

  1. 打开服务方连接页
  2. 完成授权或复制端点
  3. 在 MCP 客户端中连接
terminal

本地运行 / 其它方式

本地运行通常需要用户在自己的电脑或服务器上安装依赖,把 server_config 复制到 MCP 客户端,并按 env_schema 补齐环境变量、密钥或其它配置

  1. 复制 server_config
  2. 安装所需依赖
  3. 补齐环境变量后重启客户端