Skip to content

Commit e492cec

Browse files
authored
Optimize codes and comments with cursor (#550)
1 parent 92fe1e7 commit e492cec

File tree

152 files changed

+3420
-2065
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+3420
-2065
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.idea/
22
.vscode/
3+
.cursor/
4+
.DS_Store
35
venv/
46
.venv/
57
.python-version

README.md

+35-35
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
English | [简体中文](./README.zh-CN.md)
88

9-
A backend and frontend separation solution based on the FastAPI framework, following
10-
the [pseudo 3-tier architecture](#pseudo-3-tier-architecture) design, supporting **Python 3.10** and above
11-
versions
9+
Enterprise-level backend architecture solution
1210

1311
**🔥Continuously updated and maintained🔥**
1412

@@ -49,37 +47,39 @@ pattern, use templates to transform it to your heart's content!
4947

5048
## Features
5149

52-
- [x] Design with FastAPI PEP 593 Annotated Parameters
53-
- [x] Global asynchronous design with async/await + asgiref
54-
- [x] Follows Restful API specification
55-
- [x] Global SQLAlchemy 2.0 syntax
56-
- [x] Pydantic v1 and v2 (different branches)
57-
- [x] Casbin RBAC access control model
58-
- [x] Role menu RBAC access control model
59-
- [x] Celery asynchronous tasks
60-
- [x] JWT middleware whitelist authentication
61-
- [x] Global customizable time zone time
62-
- [x] Docker / Docker-compose deployment
63-
- [x] Pytest Unit Testing
64-
65-
## Built-in features
66-
67-
- [x] User management: System User Role Management, Permission Allocation
68-
- [x] Department management: Configure system organization (company, department, team...)
69-
- [x] Menu management: Configure system menu, user menu, button permission tags
70-
- [x] Role management: role menu permission allocation, role route permission allocation
71-
- [x] Dictionary management: Maintain commonly used fixed data or parameters within the system
72-
- [x] Token management: System user online status detection, supports kicking users offline
73-
- [x] Login authentication: backend-based graphical captcha background authentication login
74-
- [x] Multipoint login: One-click modification of multipoint login through user information
75-
- [x] OAuth 2.0: Built-in self-developed OAuth 2.0 login integration
76-
- [x] Code generation: automatic backend code generation, supports preview, writing, and download
77-
- [x] Scheduled task: Automated task, asynchronous task, supports function calls
78-
- [x] Plugin system: Say goodbye to high coupling integration through hot-pluggable plugin mode
79-
- [x] Operation log: Record and query of system normal and abnormal operations
80-
- [x] Login log: Record and query of normal and abnormal user login
81-
- [x] Service monitoring: Server hardware device information and status
82-
- [x] API documentation: Automatically generate online interactive API documentation
50+
- [x] Global FastAPI PEP 593 Annotated parameter style
51+
- [x] Comprehensive async/await + asgiref asynchronous design
52+
- [x] Adheres to RESTful API specifications
53+
- [x] Uses SQLAlchemy 2.0 with new syntax
54+
- [x] Uses Pydantic v2 version
55+
- [x] Implements role-menu RBAC access control
56+
- [x] Integrates Casbin RBAC access control
57+
- [x] Supports Celery asynchronous tasks
58+
- [x] Custom-developed JWT authentication middleware
59+
- [x] Supports global custom time zones
60+
- [x] Supports Docker / Docker-compose deployment
61+
- [x] Integrates Pytest unit testing
62+
63+
## Built-in Functions
64+
65+
- [x] User Management: Assign roles and permissions
66+
- [x] Department Management: Configure organizational structure (company, department, team, etc.)
67+
- [x] Menu Management: Set up menus and button-level permissions
68+
- [x] Role Management: Configure roles, assign menus and permissions
69+
- [x] Dictionary Management: Maintain common parameters and configurations
70+
- [x] Parameter Management: Dynamically configure commonly used system parameters
71+
- [x] Notification Announcements: Publish and maintain system notification and announcement information
72+
- [x] Token Management: Detect online status, support forced logout
73+
- [x] Multi-device Login: Support one-click switching between multi-device login modes
74+
- [x] OAuth 2.0: Built-in custom-developed OAuth 2.0 authorization login
75+
- [x] Plugin System: Hot-swappable plugin design to reduce coupling
76+
- [x] Scheduled Tasks: Support scheduled, asynchronous tasks, and function calls
77+
- [x] Code Generation: Automatically generate code with preview, write, and download support
78+
- [x] Operation Logs: Record and query normal and abnormal operations
79+
- [x] Login Logs: Record and query normal and abnormal logins
80+
- [x] Cache Monitoring: Query system cache information and command statistics
81+
- [x] Service Monitoring: View server hardware information and status
82+
- [x] API Documentation: Automatically generate online interactive API documentation
8383

8484
## Development and deployment
8585

@@ -103,7 +103,7 @@ the [official documentation](https://fastapi-practices.github.io/fastapi_best_ar
103103

104104
## Interactivity
105105

106-
[TG / Discord](https://wu-clan.github.io/homepage/)
106+
[Discord](https://wu-clan.github.io/homepage/)
107107

108108
## Sponsor us
109109

README.zh-CN.md

+31-29
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
简体中文 | [English](./README.md)
88

9-
基于 FastAPI 框架的前后端分离中后台解决方案,遵循[伪三层架构](#伪三层架构)设计, 支持 **python3.10** 及以上版本
9+
企业级后端架构解决方案
1010

1111
**🔥持续更新维护中🔥**
1212

@@ -43,38 +43,40 @@ mvc 架构作为常规设计模式,在 python web 中也很常见,但是三
4343
| 数据访问 | dao / mapper | crud |
4444
| 模型 | model / entity | model |
4545

46-
## 特征
46+
## 特性
4747

4848
- [x] 全局 FastAPI PEP 593 Annotated 参数风格
49-
- [x] async/await + asgiref 的全局异步设计
50-
- [x] 遵循 Restful API 规范
51-
- [x] 全局 SQLAlchemy 2.0 语法
52-
- [x] Pydantic v1 和 v2 (不同分支)
53-
- [x] Casbin RBAC 访问控制模型
54-
- [x] 角色菜单 RBAC 访问控制模型
55-
- [x] Celery 异步任务
56-
- [x] JWT 中间件白名单认证
57-
- [x] 全局自定义时区时间
58-
- [x] Docker / Docker-compose 部署
59-
- [x] Pytest 单元测试
49+
- [x] 全面 async/await + asgiref 异步设计
50+
- [x] 遵循 RESTful API 规范
51+
- [x] 使用 SQLAlchemy 2.0 全新语法
52+
- [x] 使用 Pydantic v2 版本
53+
- [x] 实现角色菜单 RBAC 访问控制
54+
- [x] 集成 Casbin RBAC 访问控制
55+
- [x] 支持 Celery 异步任务
56+
- [x] 自研 JWT 认证中间件
57+
- [x] 支持全局自定义时间时区
58+
- [x] 支持 Docker / Docker-compose 部署
59+
- [x] 集成 Pytest 单元测试
6060

6161
## 内置功能
6262

63-
- [x] 用户管理:系统用户角色管理,权限分配
64-
- [x] 部门管理:配置系统组织机构(公司、部门、小组...)
65-
- [x] 菜单管理:配置系统菜单,用户菜单,按钮权限标识
66-
- [x] 角色管理:角色菜单权限分配,角色路由权限分配
67-
- [x] 字典管理:维护系统内部常用固定数据或参数
68-
- [x] 令牌管理:系统用户在线状态检测,支持踢人下线
69-
- [x] 登录认证:基于后端的图形验证码后台认证登录
70-
- [x] 多点登录:通过用户信息一键修改多点登录支持
71-
- [x] OAuth20:内置自研 OAuth 2.0 登录集成
72-
- [x] 代码生成:后端代码自动生成,支持预览,写入及下载
73-
- [x] 定时任务:自动化任务,异步任务,支持函数调用
74-
- [x] 插件系统:通过热插拔插件模式告别高耦合集成
75-
- [x] 操作日志:系统正常和异常操作的日志记录与查询
76-
- [x] 登录日志:用户正常和异常登录的日志记录与查询
77-
- [x] 服务监控:服务器硬件设备信息与状态
63+
- [x] 用户管理:分配角色和权限
64+
- [x] 部门管理:配置组织架构(公司、部门、小组等)
65+
- [x] 菜单管理:设置菜单及按钮级权限
66+
- [x] 角色管理:配置角色、分配菜单和权限
67+
- [x] 字典管理:维护常用参数和配置
68+
- [x] 参数管理:系统常用参数动态配置
69+
- [x] 通知公告:发布和维护系统通知公告信息
70+
- [x] 令牌管理:检测在线状态,支持强制下线
71+
- [x] 多端登录:支持一键切换多端登录模式
72+
- [x] OAuth 2.0:内置自研 OAuth 2.0 授权登录
73+
- [x] 插件系统:热插拔插件设计,降低耦合
74+
- [x] 定时任务:支持定时,异步任务及函数调用
75+
- [x] 代码生成:自动生成代码,支持预览、写入和下载
76+
- [x] 操作日志:记录和查询正常和异常操作
77+
- [x] 登录日志:记录和查询正常和异常登录
78+
- [x] 缓存监控:查询系统缓存信息和命令统计
79+
- [x] 服务监控:查看服务器硬件信息和状态
7880
- [x] 接口文档:自动生成在线交互式 API 文档
7981

8082
## 开发部署
@@ -98,7 +100,7 @@ mvc 架构作为常规设计模式,在 python web 中也很常见,但是三
98100

99101
## 互动
100102

101-
[TG / Discord](https://wu-clan.github.io/homepage/)
103+
[Discord](https://wu-clan.github.io/homepage/)
102104

103105
## 赞助我们
104106

backend/app/admin/api/v1/auth/auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def user_login(
3636

3737

3838
@router.post('/token/new', summary='创建新 token')
39-
async def create_new_token(request: Request, response: Response) -> ResponseSchemaModel[GetNewToken]:
39+
async def create_new_token(request: Request) -> ResponseSchemaModel[GetNewToken]:
4040
data = await auth_service.new_token(request=request)
4141
return response_base.success(data=data)
4242

backend/app/admin/api/v1/log/login_log.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818

1919
@router.get(
2020
'',
21-
summary='(模糊条件)分页获取登录日志',
21+
summary='分页获取登录日志',
2222
dependencies=[
2323
DependsJwtAuth,
2424
DependsPagination,
2525
],
2626
)
2727
async def get_pagination_login_logs(
2828
db: CurrentSession,
29-
username: Annotated[str | None, Query()] = None,
30-
status: Annotated[int | None, Query()] = None,
31-
ip: Annotated[str | None, Query()] = None,
29+
username: Annotated[str | None, Query(description='用户名')] = None,
30+
status: Annotated[int | None, Query(description='状态')] = None,
31+
ip: Annotated[str | None, Query(description='IP 地址')] = None,
3232
) -> ResponseSchemaModel[PageData[GetLoginLogDetail]]:
3333
log_select = await login_log_service.get_select(username=username, status=status, ip=ip)
3434
page_data = await paging_data(db, log_select)
@@ -37,13 +37,13 @@ async def get_pagination_login_logs(
3737

3838
@router.delete(
3939
'',
40-
summary='(批量)删除登录日志',
40+
summary='批量删除登录日志',
4141
dependencies=[
4242
Depends(RequestPermission('log:login:del')),
4343
DependsRBAC,
4444
],
4545
)
46-
async def delete_login_log(pk: Annotated[list[int], Query(...)]) -> ResponseModel:
46+
async def delete_login_log(pk: Annotated[list[int], Query(description='登录日志 ID 列表')]) -> ResponseModel:
4747
count = await login_log_service.delete(pk=pk)
4848
if count > 0:
4949
return response_base.success()

backend/app/admin/api/v1/log/opera_log.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818

1919
@router.get(
2020
'',
21-
summary='(模糊条件)分页获取操作日志',
21+
summary='分页获取操作日志',
2222
dependencies=[
2323
DependsJwtAuth,
2424
DependsPagination,
2525
],
2626
)
2727
async def get_pagination_opera_logs(
2828
db: CurrentSession,
29-
username: Annotated[str | None, Query()] = None,
30-
status: Annotated[int | None, Query()] = None,
31-
ip: Annotated[str | None, Query()] = None,
29+
username: Annotated[str | None, Query(description='用户名')] = None,
30+
status: Annotated[int | None, Query(description='状态')] = None,
31+
ip: Annotated[str | None, Query(description='IP 地址')] = None,
3232
) -> ResponseSchemaModel[PageData[GetOperaLogDetail]]:
3333
log_select = await opera_log_service.get_select(username=username, status=status, ip=ip)
3434
page_data = await paging_data(db, log_select)
@@ -37,13 +37,13 @@ async def get_pagination_opera_logs(
3737

3838
@router.delete(
3939
'',
40-
summary='(批量)删除操作日志',
40+
summary='批量删除操作日志',
4141
dependencies=[
4242
Depends(RequestPermission('log:opera:del')),
4343
DependsRBAC,
4444
],
4545
)
46-
async def delete_opera_log(pk: Annotated[list[int], Query(...)]) -> ResponseModel:
46+
async def delete_opera_log(pk: Annotated[list[int], Query(description='操作日志 ID 列表')]) -> ResponseModel:
4747
count = await opera_log_service.delete(pk=pk)
4848
if count > 0:
4949
return response_base.success()

backend/app/admin/api/v1/monitor/redis.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
],
2020
)
2121
async def get_redis_info() -> ResponseModel:
22-
data = {'info': await redis_info.get_info(), 'stats': await redis_info.get_stats()}
22+
data = {
23+
'info': await redis_info.get_info(),
24+
'stats': await redis_info.get_stats(),
25+
}
2326
return response_base.success(data=data)

backend/app/admin/api/v1/oauth2/linux_do.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
_linux_do_oauth2 = FastAPIOAuth20(_linux_do_client, admin_settings.OAUTH2_LINUX_DO_REDIRECT_URI)
2020

2121

22-
@router.get('', summary='获取 Linux Do 授权链接')
22+
@router.get('', summary='获取 LinuxDo 授权链接')
2323
async def linux_do_auth2() -> ResponseSchemaModel[str]:
2424
auth_url = await _linux_do_client.get_authorization_url(redirect_uri=admin_settings.OAUTH2_LINUX_DO_REDIRECT_URI)
2525
return response_base.success(data=auth_url)
2626

2727

2828
@router.get(
2929
'/callback',
30-
summary='Linux Do 授权自动重定向',
31-
description='Linux Do 授权后,自动重定向到当前地址并获取用户信息,通过用户信息自动创建系统用户',
30+
summary='LinuxDo 授权自动重定向',
31+
description='LinuxDo 授权后,自动重定向到当前地址并获取用户信息,通过用户信息自动创建系统用户',
3232
dependencies=[Depends(RateLimiter(times=5, minutes=1))],
3333
)
3434
async def linux_do_login(
@@ -45,6 +45,6 @@ async def linux_do_login(
4545
response=response,
4646
background_tasks=background_tasks,
4747
user=user,
48-
social=UserSocialType.linuxdo,
48+
social=UserSocialType.linux_do,
4949
)
5050
return RedirectResponse(url=f'{admin_settings.OAUTH2_FRONTEND_REDIRECT_URI}?access_token={data.access_token}')

backend/app/admin/api/v1/sys/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
router = APIRouter(prefix='/sys')
1818

19-
router.include_router(config_router, prefix='/configs', tags=['系统配置'])
19+
router.include_router(config_router, prefix='/configs', tags=['系统参数配置'])
2020
router.include_router(dept_router, prefix='/depts', tags=['系统部门'])
2121
router.include_router(dict_data_router, prefix='/dict-datas', tags=['系统字典数据'])
2222
router.include_router(dict_type_router, prefix='/dict-types', tags=['系统字典类型'])

0 commit comments

Comments
 (0)