FastAPI Best Architecture
English | 简体中文
This is a basic project of the FastAPI framework, using a pseudo three-tier architecture, still in production
It‘s purpose is to allow you to develop your project directly with it as your base project
Support python3.10 and above
Skill
- FastAPI
- Pydantic
- SQLAlchemy
- Alembic
- Casbin
- MySQL
- Redis
- APScheduler
- Docker
Clone
git clone https://github.com/wu-clan/fastapi_best_architecture.git
Use:
1:Tradition
-
Install dependencies
pip install -r requirements.txt -
Create a database
fba, choose utf8mb4 encode -
Install and start Redis
-
create a
.envfile in thebackend/app/directorycd backend/app/ touch .env -
Copy
.env.exampleto.envcp .env.example .env -
Perform a database migration alembic
cd backend/app/ # Generate the migration file alembic revision --autogenerate # Perform the migration alembic upgrade head -
Execute the
backend/app/main.pyfile startup service -
Browser access: http://127.0.0.1:8000/v1/docs
2:Docker
-
Go to the directory where the
docker-compose.ymlfile is located and create the environment variable file.envcp .env.server ../../backend/app/.env # This command is optional cp .env.docker .env -
Execute the one-click start command
docker-compose up -d -build -
Wait for the command to finish automatically
-
Browser access: http://127.0.0.1:8000/v1/docs
Init the test data
Execute the backend/app/init_test_data.py file
Test
Perform tests via pytest
-
Create a database
fba_test, choose utf8mb4 encode -
First, go to the app directory
cd backend/app/ -
Init the test data
python tests/init_test_data.py -
Execute the test command
pytest -vs --disable-warnings