0


开源项目 `full-stack-fastapi-template` 使用教程

开源项目

  1. full-stack-fastapi-template

使用教程

项目地址:https://gitcode.com/gh_mirrors/fu/full-stack-fastapi-template

1. 项目的目录结构及介绍

  1. full-stack-fastapi-template/
  2. ├── backend/
  3. ├── app/
  4. ├── api/
  5. ├── api_v1/
  6. ├── endpoints/
  7. └── api.py
  8. └── api.py
  9. ├── core/
  10. ├── config.py
  11. └── security.py
  12. ├── db/
  13. ├── base.py
  14. ├── base_class.py
  15. ├── init_db.py
  16. └── session.py
  17. ├── models/
  18. ├── schemas/
  19. ├── services/
  20. ├── main.py
  21. └── __init__.py
  22. ├── tests/
  23. ├── .env
  24. ├── .gitignore
  25. ├── Dockerfile
  26. ├── requirements.txt
  27. └── setup.py
  28. ├── frontend/
  29. ├── public/
  30. ├── src/
  31. ├── assets/
  32. ├── components/
  33. ├── pages/
  34. ├── App.js
  35. ├── index.js
  36. └── ...
  37. ├── .gitignore
  38. ├── Dockerfile
  39. ├── package.json
  40. └── ...
  41. ├── .github/
  42. ├── workflows/
  43. └── ...
  44. ├── .env
  45. ├── .gitignore
  46. ├── docker-compose.yml
  47. ├── LICENSE
  48. └── README.md

目录结构介绍

  • backend/: 后端代码目录,包含 FastAPI 应用的所有文件。 - app/: 应用的主要代码目录。 - api/: API 路由和端点。- core/: 核心配置和安全相关文件。- db/: 数据库相关文件。- models/: 数据库模型。- schemas/: Pydantic 模型。- services/: 业务逻辑服务。- main.py: 应用的入口文件。- tests/: 测试代码目录。
  • frontend/: 前端代码目录,包含 React 应用的所有文件。 - public/: 公共资源文件。- src/: 源代码文件。
  • .github/: GitHub 配置文件,如 GitHub Actions 工作流。
  • .env: 环境变量配置文件。
  • docker-compose.yml: Docker 配置文件。
  • LICENSE: 项目许可证。
  • README.md: 项目说明文档。

2. 项目的启动文件介绍

后端启动文件

  • backend/app/main.py: 这是 FastAPI 应用的入口文件,包含应用的初始化和启动代码。
  1. from fastapi import FastAPI
  2. from app.api.api_v1.api import api_router
  3. from app.core.config import settings
  4. app = FastAPI(
  5. title=settings.PROJECT_NAME,
  6. openapi_url=f"{settings.API_V1_STR}/openapi.json"
  7. )
  8. app.include_router(api_router, prefix=settings.API_V1_STR)

前端启动文件

  • frontend/src/index.js: 这是 React 应用的入口文件,包含应用的初始化和启动代码。
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import './index.css';
  4. import App from './App';
  5. import reportWebVitals from './reportWebVitals';
  6. ReactDOM.render(
  7. <React.StrictMode>
  8. <App />
  9. </React.StrictMode>,
  10. document.getElementById('root')
  11. );
  12. reportWebVitals();

3. 项目的配置文件介绍

后端配置文件

  • backend/.env: 环境变量配置文件,包含数据库连接、密钥等敏感信息。
  1. # 数据库连接
  2. DATABASE_URL=postgresql://user:password@localhost:5432/dbname
  3. # 密钥
  4. SECRET

full-stack-fastapi-template 项目地址: https://gitcode.com/gh_mirrors/fu/full-stack-fastapi-template

标签:

本文转载自: https://blog.csdn.net/gitblog_00069/article/details/141049859
版权归原作者 平奇群Derek 所有, 如有侵权,请联系我们删除。

“开源项目 `full-stack-fastapi-template` 使用教程”的评论:

还没有评论