Skip to content

Naming Conventions

Files / directories

SideConventionExample
Frontend file / dirkebab-caseuser-list.vue, hooks/use-table.ts
Backend file / dirsnake_caseinit_helper.py, hr/api/manage.py
Business module namesnake_case, single wordhr / inventory / notify

Python identifiers

KindConventionExample
ClassPascalCaseUserController / EmployeeCreate
Function / methodsnake_caseget_user() / create_employee()
Module-level constantUPPER_SNAKE_CASESECRET_KEY / SUPER_ADMIN_ROLE
Module-level private_snake_case_safe_update_or_create()
Field (DB / Schema internal)snake_caseuser_name / created_at
Field (HTTP boundary)camelCase (auto-converted)userName / createdAt
Pydantic schemaPascalCase + Create / Update / Search / Out suffixEmployeeCreate / EmployeeSearch
Tortoise modelPascalCase singularEmployee / Department
Tortoise Meta.table<scope>_<module>_<entity>biz_hr_employee / sys_dictionary

TypeScript identifiers

KindConventionExample
ComponentPascalCaseUserCard
Composable / hookuseXxxuseTable / useAuth
FunctioncamelCasegetUser()
ConstantUPPER_SNAKE_CASEMAX_COUNT
API request functionfetchXxxfetchUserList() / fetchLogin()
Type / interfaceApi.<Module>.<Type>Api.User.UserOut

URL / path

KindConventionExample
Resource segmentplural + kebab-case/users / /departments / /system-manage/users
Sub-resourceplural + parent ID/roles/{id}/menus
Collection actionresource + /<verb-noun>/roles/batch-offline / /apis/refresh
Instance action/{id}/<verb-noun>/employees/{id}/transition
Derived query/<noun>/menus/tree / /menus/pages
Avoidtrailing slash, camelCase, mixing plural & singular/users/ / ❌ /userList / ❌ /user

Business codes

B_<MODULE>_<RESOURCE>_<ACTION>      # Button code
R_<UPPER>                           # Role code
ExampleMeaning
B_HR_EMP_CREATEHR / employee / create
B_HR_EMP_TRANSITIONHR / employee / state transition
R_HR_ADMINHR admin
R_DEPT_MGRgeneric department manager
R_SUPERsuper admin (reserved)

Route name (menu route_name)

<module>            # top-level catalog
<module>_<page>     # second-level page
<module>_<page>_<sub>  # third level
ExamplePath
home/home
hr/hr
hr_department/hr/department
hr_employee_detail/hr/employee/detail
function_multi-tab/function/multi-tab (kebab inside a segment)

route_name is the Vue Router name and the unique key on Menu.route_namekeep it stable. Renaming means every role seed referencing it must be updated too.

i18n key

route.<route_name>             # route / menu title
page.<module>.<key>            # in-page text
common.<key>                   # global

Cache key

ScopeTemplateExample
System-level permissionrole:{code}:* / user:{uid}:*role:R_HR_ADMIN:apis
Business module<module>_<resource>:<scope>dict_options:tag_category
Startup coordinationapp:<purpose>app:init_lock / app:init_done

Event name

<aggregate>.<verb>           # lowercase + dot
ExampleMeaning
employee.createdemployee created
employee.status_changedemployee state transition
order.refundedorder refunded

Database

KindConvention
Table name<scope>_<module>_<entity> (lowercase + underscore, singular)
PKid (int)
FK field<entity>_id (e.g. department_id)
Time fieldscreated_at / updated_at / deleted_at
Status fieldstatus or status_type (matching frontend expectation)

Other

  • Module-level __all__ exposes only the truly public symbols; keep private with _ prefix
  • Test files are named after the module under test with test_ prefix (tests/test_employee_service.py)
  • Avoid single-letter variable names (l, O, I collide in some fonts); loop counters i, j are OK

基于 MIT 协议发布