Wu Clan f21006000a Update user role interface to standalone (#177)
* Update user role interface to standalone

* Fix the userinfo schema department field type

* fix update userinfo values

* fix update user avatar value

* update readme docs

* update test data sql

* update readme typo

* update readme docs
2023-07-14 17:01:47 +08:00
2023-05-11 15:20:57 +08:00
2023-05-23 19:14:11 +08:00
2023-04-19 11:05:49 +08:00
2023-04-24 13:44:32 +08:00

FastAPI Best Architecture

English | 简体中文

This is a base project for the FastAPI framework, using a pseudo three-tier architecture, still in production.

It is intended to allow you to use it directly as your infrastructure to develop your project, this repository as a template library public, can be used directly

Support python3.10 and above

Pseudo three-tier architecture

In python web frameworks, the mvc architecture is the most common, but for restful users, the three-tier architecture is the way to go

But in python development, there is no universal standard for the concept of a three-tier architecture, so here I call it a pseudo three-tier architecture

workflow java fastapi_best_architecture
view controller api
data validation dto schema
business logic service + impl service
data access dao / mapper crud
model model / entity model

Features

  • FastAPI new features
  • Asynchronous design
  • Restful API specification
  • SQLAlchemy 2.0 syntax
  • Pydantic data validation
  • Casbin RBAC permission control
  • APScheduler timed tasks
  • JWT authentication
  • Redis caching
  • Docker deployment
  • Pytest testing

Getting started:

1: Legacy mode

  1. Install dependencies

    pip install -r requirements.txt
    
  2. Create a database fba, choose utf8mb4 encoding

  3. Install and start Redis

  4. Create a .env file in the backend/app/ directory

    cd backend/app/
    touch .env
    
  5. Copy .env.example to .env

    cp .env.example .env
    
  6. Database migration alembic

    cd backend/app/
    
    # Generate migration file
    alembic revision --autogenerate
    
    # Execute the migration
    alembic upgrade head
    
  7. Execute the backend/app/main.py file to start the service

  8. Browser access: http://127.0.0.1:8000/api/v1/docs


2: Docker

  1. Go to the directory where the docker-compose.yml file is located and create the environment variable file .env

    cd deploy/docker-compose/
    
    cp .env.server ../../backend/app/.env
    
    # This command is optional
    cp .env.docker .env
    
  2. Execute the one-click boot command

    docker-compose up -d -build
    
  3. Wait for the command to complete automatically

  4. Visit the browser: http://127.0.0.1:8000/api/v1/docs

Test data

Initialize the test data using the backend/sql/init_test_data.sql file

Development

Development process, for reference only

  1. Define the database model (model) and remember to perform database migration for each change
  2. Define the data validation model (schema)
  3. Define routes (router) and views (api)
  4. Define the business logic (service)
  5. Write database operations (crud)

Test

Execute tests via pytest

  1. Create the test database fba_test, select utf8mb4 encoding

  2. Enter the app directory

    cd backend/app/
    
  3. Initialize the test data using the backend/sql/init_test_data.sql file

  4. Execute the test command

    pytest -vs --disable-warnings
    

Contributors

Thanks

Sponsor

If this program has helped you, you can sponsor the author with some coffee beans

Wechat Pay Ali Pay

License

This project is licensed under the terms of the MIT license

Description
FastAPI Best Architecture is an enterprise-grade backend architecture solution built with FastAPI. FastAPI 最佳架构是使用 FastAPI 构建的企业级后端架构解决方案
Readme MIT 9.4 MiB
Languages
Python 96.8%
Jinja 2.2%
HTML 0.5%
Dockerfile 0.3%
Shell 0.1%