1
1
# FastAPI Best Architecture
2
2
3
+ [ ![ GitHub] ( https://img.shields.io/github/license/fastapi-practices/fastapi_best_architecture )] ( https://github.com/fastapi-practices/fastapi_best_architecture/blob/master/LICENSE )
4
+ [ ![ Static Badge] ( https://img.shields.io/badge/python-3.10%2B-blue )] ( https://www.python.org/downloads/ )
5
+
3
6
English | [ 简体中文] ( ./README.zh-CN.md )
4
7
5
- This is a base project for the FastAPI framework, using a pseudo three-tier architecture, ** still in production** .
8
+ FastAPI framework based on the front-end and back-end separation of the middle and back-end solutions, follow
9
+ the [ pseudo three-tier architecture] ( #pseudo-three-tier-architecture ) design, support for ** python3.10** and above
10
+ versions
6
11
7
- It is intended to allow you to use it directly as your infrastructure to develop your project, this repository as a
8
- template library public, can be used directly
12
+ Its purpose is to allow you to use it directly as the infrastructure of your new project, this repository as a template
13
+ library open to any person or enterprise can be used for free!
9
14
10
- Support ** python3.10 ** and above
15
+ ** Continuously updated and maintained **
11
16
12
17
## Pseudo three-tier architecture
13
18
14
- In python web frameworks, the mvc architecture is the most common, but for restful users, the three-tier architecture is
15
- the way to go
19
+ The mvc architecture is a common design pattern in python web, but the three-tier architecture is even more fascinating.
16
20
17
- But in python development, there is no universal standard for the concept of a three-tier architecture, so here I call
18
- it a pseudo three-tier architecture
21
+ In python web development, there is no common standard for the concept of three-tier architecture, so we'll call it a
22
+ pseudo three-tier architecture here
19
23
20
24
| workflow | java | fastapi_best_architecture |
21
25
| ----------------| ----------------| ---------------------------|
@@ -25,23 +29,60 @@ it a pseudo three-tier architecture
25
29
| data access | dao / mapper | crud |
26
30
| model | model / entity | model |
27
31
32
+ ## Online preview
33
+
34
+ Unfortunately, we don't have the funds to provide an online preview, you can deploy by checking
35
+ out [ local-development] ( #local-development ) , or directly using [ Docker] ( #docker-deploy )
36
+ to deploy, or at [ fastapi_best_architecture_ui] ( https://github.com/fastapi-practices/fastapi_best_architecture_ui )
37
+ See a preview of some of the screenshots
38
+
28
39
## Features
29
40
30
- - [x] FastAPI new features
31
- - [x] Asynchronous design
32
- - [x] Restful API specification
33
- - [x] SQLAlchemy 2.0 syntax
34
- - [x] Pydantic data validation
35
- - [x] Casbin RBAC permission control
36
- - [x] APScheduler timed tasks
37
- - [x] JWT authentication
38
- - [x] Redis caching
39
- - [x] Docker deployment
40
- - [x] Pytest testing
41
+ - [x] Design with FastAPI PEP 593 Annotated Parameters
42
+ - [x] Global asynchronous design with async/await + asgiref
43
+ - [x] Follows Restful API specification
44
+ - [x] Global SQLAlchemy 2.0 syntax
45
+ - [x] Casbin RBAC access control model
46
+ - [x] APScheduler online timed tasks
47
+ - [x] JWT middleware whitelist authentication
48
+ - [x] Global customizable time zone time
49
+ - [x] Docker / Docker-compose deployment
50
+ - [x] Pytest Unit Testing
51
+
52
+ TODO:
53
+
54
+ 1 . [ ] Pydantic 2.0
55
+
56
+ ## Built-in features
57
+
58
+ 1 . [x] User management: system user role management, permission assignment
59
+ 2 . [x] Department Management: Configure the system organization (company, department, group...)
60
+ 3 . [x] Menu Management: Configuration of system menus, user menus, button privilege identification
61
+ 4 . [x] Role Management: Assign role menu privileges, assign role routing privileges
62
+ 5 . [x] Dictionary Management: Maintain common fixed data or parameters within the system.
63
+ 6 . [x] Operation Logs: logging and querying of normal and abnormal system operations.
64
+ 7 . [x] Login Authentication: graphical authentication code background authentication login
65
+ 8 . [x] Login Logs: Logging and querying of normal and abnormal user logins
66
+ 9 . [x] Service Monitoring: server hardware device information and status
67
+ 10 . [x] Timed Tasks: online task control (modify, delete, pause...)
68
+ 11 . [x] Interface Documentation: Automatically generate online interactive API interface documentation.
69
+
70
+ TODO:
41
71
42
- ## Getting started:
72
+ 1 . [ ] Dynamic Configuration: Dynamic configuration of the system environment (site title, logo, filing, footer...)
73
+ 2 . [ ] code generation: according to the table structure, visualize the generation of additions, deletions,
74
+ modifications and checks of the business code.
75
+ 3 . [ ] File Upload: Docking cloud OSS and local backup.
76
+ 4 . [ ] System Notification: proactively send timed task notifications, resource warnings, service anomaly warnings...
43
77
44
- ### 1: Legacy mode
78
+ ## Local development
79
+
80
+ * Python: 3.10+
81
+ * Mysql: 8.0+
82
+ * Redis: The latest stable version is recommended
83
+ * Nodejs: 14.0+
84
+
85
+ ### BackEnd
45
86
46
87
1 . Install dependencies
47
88
``` shell
@@ -74,13 +115,17 @@ it a pseudo three-tier architecture
74
115
# Execute the migration
75
116
alembic upgrade head
76
117
` ` `
77
-
78
- 7 . Execute the ` backend/app/main.py` file to start the service
79
- 8 . Browser access: http://127.0.0.1:8000/api/v1/docs
118
+ 7. Modify the configuration file as needed
119
+ 8 . Execute the ` backend/app/main.py` file to start the service
120
+ 9 . Browser access: http://127.0.0.1:8000/api/v1/docs
80
121
81
122
---
82
123
83
- # ## 2: Docker
124
+ # ## Front
125
+
126
+ Click [fastapi_best_architecture_ui](https://github.com/fastapi-practices/fastapi_best_architecture_ui) for details
127
+
128
+ # ## Docker deploy
84
129
85
130
1. Go to the directory where the ` ` docker-compose.yml` ` file is located and create the environment variable
86
131
file ` ` .env` `
@@ -94,32 +139,39 @@ it a pseudo three-tier architecture
94
139
cp .env.docker .env
95
140
` ` `
96
141
97
- 2. Execute the one-click boot command
142
+ 2. Modify the configuration file as needed
143
+ 3. Execute the one-click boot command
98
144
99
145
` ` ` shell
100
146
docker-compose up -d -build
101
147
` ` `
102
148
103
- 3 . Wait for the command to complete automatically
104
- 4 . Visit the browser: http://127.0.0.1:8000/api/v1/docs
149
+ 4 . Wait for the command to complete automatically
150
+ 5 . Visit the browser: http://127.0.0.1:8000/api/v1/docs
105
151
106
152
# # Test data
107
153
108
154
Initialize the test data using the ` backend/sql/init_test_data.sql` file
109
155
110
- # # Development
156
+ # # Development process
157
+
158
+ For reference only
111
159
112
- Development process, for reference only
160
+ # ## BackEnd
113
161
114
162
1. Define the database model (model) and remember to perform database migration for each change
115
163
2. Define the data validation model (schema)
116
164
3. Define routes (router) and views (api)
117
165
4. Define the business logic (service)
118
166
5. Write database operations (crud)
119
167
168
+ # ## Front
169
+
170
+ Click [fastapi_best_architecture_ui](https://github.com/fastapi-practices/fastapi_best_architecture_ui) for details
171
+
120
172
# # Test
121
173
122
- Execute tests via pytest
174
+ Execute unittests via pytest
123
175
124
176
1. Create the test database ` fba_test` , select utf8mb4 encoding
125
177
2. Enter the app directory
@@ -141,30 +193,35 @@ Execute tests via pytest
141
193
< span style=" margin: 0 5px;" ><a href=" https://github.com/wu-clan" ><img src=" https://images.weserv.nl/?url=avatars.githubusercontent.com/u/52145145?v=4&h=60&w=60&fit=cover&mask=circle&maxage=7d" /></a></span>
142
194
< span style=" margin: 0 5px;" ><a href=" https://github.com/downdawn" ><img src=" https://images.weserv.nl/?url=avatars.githubusercontent.com/u/41266749?v=4&h=60&w=60&fit=cover&mask=circle&maxage=7d" /></a></span>
143
195
144
- # # Thanks
196
+ # # Special thanks
145
197
146
198
- [FastAPI](https://fastapi.tiangolo.com/)
147
199
- [Pydantic](https://docs.pydantic.dev/latest/)
148
200
- [SQLAlchemy](https://docs.sqlalchemy.org/en/20/)
149
201
- [Casbin](https://casbin.org/zh/)
150
202
- [Ruff](https://beta.ruff.rs/docs/)
151
- - ......
203
+ - [Black](https://black.readthedocs.io/en/stable/index.html)
204
+ - [RuoYi](http://ruoyi.vip/)
205
+ - ...
152
206
153
- # # Sponsor
207
+ # # Sponsor us
154
208
155
- > If this program has helped you, you can sponsor the author with some coffee beans :coffee:
209
+ > If this program has helped you, you can sponsor us with some coffee beans :coffee:
156
210
157
211
< table>
158
212
< tr>
159
- < td><img src=" https://github.com/wu-clan/image/blob/master/pay/weixin.jpg?raw=true" width=" 180px" />
160
- < td><img src=" https://github.com/wu-clan/image/blob/master/pay/zfb.jpg?raw=true" width=" 180px" />
213
+ < td><img src=" https://github.com/wu-clan/image/blob/master/pay/weixin.jpg?raw=true" width=" 180px" alt=" WeChat" />
214
+ < td><img src=" https://github.com/wu-clan/image/blob/master/pay/zfb.jpg?raw=true" width=" 180px" alt=" Alipay" />
215
+ < td><img src=" https://github.com/wu-clan/image/blob/master/pay/ERC20.jpg?raw=true" width=" 180px" alt=" 0x40D5e2304b452256afD9CE2d3d5531dc8d293138" />
161
216
< /tr>
162
217
< tr>
163
- < td align=" center" > Wechat Pay< /td>
218
+ < td align=" center" > WeChat Pay< /td>
164
219
< td align=" center" > Ali Pay< /td>
220
+ < td align=" center" > ERC20< /td>
165
221
< /tr>
166
222
< /table>
167
223
168
224
# # License
169
225
170
- This project is licensed under the terms of the MIT license
226
+ This project is licensed under the terms of
227
+ the [MIT](https://github.com/fastapi-practices/fastapi_best_architecture/blob/master/LICENSE) license
0 commit comments