English | 简体中文
FastAPI framework based on the front-end and back-end separation of the middle and back-end solutions, follow the pseudo three-tier architecture design, support for python3.10 and above versions
Its purpose is to allow you to use it directly as the infrastructure of your new project, this repository as a template library open to any person or enterprise can be used for free!
Continuously updated and maintained
The mvc architecture is a common design pattern in python web, but the three-tier architecture is even more fascinating.
In python web development, there is no common standard for the concept of three-tier architecture, so we'll call it a pseudo three-tier architecture here
workflow | java | fastapi_best_architecture |
---|---|---|
view | controller | api |
data transmit | dto | schema |
business logic | service + impl | service |
data access | dao / mapper | crud |
model | model / entity | model |
Unfortunately, we don't have the funds to provide an online preview, you can deploy by checking out local-development, or directly using Docker to deploy, or at fastapi_best_architecture_ui See a preview of some of the screenshots
- Design with FastAPI PEP 593 Annotated Parameters
- Global asynchronous design with async/await + asgiref
- Follows Restful API specification
- Global SQLAlchemy 2.0 syntax
- Casbin RBAC access control model
- Celery asynchronous tasks
- JWT middleware whitelist authentication
- Global customizable time zone time
- Docker / Docker-compose deployment
- Pytest Unit Testing
TODO:
- Pydantic 2.0
- User management: system user role management, permission assignment
- Department Management: Configure the system organization (company, department, group...)
- Menu Management: Configuration of system menus, user menus, button privilege identification
- Role Management: Assign role menu privileges, assign role routing privileges
- Dictionary Management: Maintain common fixed data or parameters within the system.
- Operation Logs: logging and querying of normal and abnormal system operations.
- Login Authentication: graphical authentication code background authentication login
- Login Logs: Logging and querying of normal and abnormal user logins
- Service Monitoring: server hardware device information and status
- Timed Tasks: online task control (modify, delete, pause...)
- Interface Documentation: Automatically generate online interactive API interface documentation.
TODO:
- Dynamic Configuration: Dynamic configuration of the system environment (site title, logo, filing, footer...)
- code generation: according to the table structure, visualize the generation of additions, deletions, modifications and checks of the business code.
- File Upload: Docking cloud OSS and local backup.
- System Notification: proactively send timed task notifications, resource warnings, service anomaly warnings...
- Python: 3.10+
- Mysql: 8.0+
- Redis: The latest stable version is recommended
- Nodejs: 14.0+
-
Install dependencies
pip install -r requirements.txt
-
Create a database
fba
, choose utf8mb4 encoding -
Install and start Redis
-
Create a
.env
file in thebackend/app/
directorycd backend/app/ touch .env
-
Copy
.env.example
to.env
cp .env.example .env
-
Database migration alembic
cd backend/app/ # Generate migration file alembic revision --autogenerate # Execute the migration alembic upgrade head
-
Start celery worker and beat
celery -A tasks worker --loglevel=INFO # Optional, if you don't need to use the scheduled task celery -A tasks beat --loglevel=INFO
-
Modify the configuration file as needed
-
Execute the
backend/app/main.py
file to start the service -
Browser access: http://127.0.0.1:8000/api/v1/docs
Click fastapi_best_architecture_ui for details
Warning
Default port conflict:8000,3306,6379,5672
As a best practice, shut down on-premises services before deployment:mysql,redis,rabbitmq...
-
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
-
Modify the configuration file as needed
-
Execute the one-click boot command
docker-compose up -d --build
-
Wait for the command to complete automatically
-
Visit the browser: http://127.0.0.1:8000/api/v1/docs
Initialize the test data using the backend/sql/init_test_data.sql
file
For reference only
- Define the database model (model) and remember to perform database migration for each change
- Define the data validation model (schema)
- Define routes (router) and views (api)
- Define the business logic (service)
- Write database operations (crud)
Click fastapi_best_architecture_ui for details
Execute unittests via pytest
-
Create the test database
fba_test
, select utf8mb4 encoding -
Using
backend/sql/create_tables.sql
file to create database tables -
Initialize the test data using the
backend/sql/init_pytest_data.sql
file -
Enter the app directory
cd backend/app/
-
Execute the test command
pytest -vs --disable-warnings
If this program has helped you, you can sponsor us with some coffee beans ☕
WeChat Pay | Ali Pay | ERC20 |
This project is licensed under the terms of the MIT license