Skip to content

Naming Conventions

Files / directories

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

Python identifiers

KindConventionExample
ClassPascalCaseUserController / ProductCreate
Function / methodsnake_caseget_user() / create_product()
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 suffixProductCreate / ProductSearch
Tortoise modelPascalCase singularProduct / Warehouse
Tortoise Meta.table<scope>_<module>_<entity>biz_inventory_product / 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 / /warehouses / /system-manage/users
Sub-resourceplural + parent ID/roles/{id}/menus
Collection actionresource + /<verb-noun>/roles/batch-offline / /apis/refresh
Instance action/{id}/<verb-noun>/products/{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_INVENTORY_PRODUCT_CREATEInventory / product / create
B_INVENTORY_PRODUCT_TRANSITIONInventory / product / state transition
R_INVENTORY_ADMINinventory admin
R_DEPT_MGRgeneric warehouse 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
inventory/inventory
inventory_warehouse/inventory/warehouse
inventory_product_detail/inventory/product/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_INVENTORY_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
product.createdproduct created
product.status_changedproduct state transition
order.refundedorder refunded

Database

KindConvention
Table name<scope>_<module>_<entity> (lowercase + underscore, singular)
PKid (int)
FK field<entity>_id (e.g. team_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_product_service.py)
  • Avoid single-letter variable names (l, O, I collide in some fonts); loop counters i, j are OK

基于 MIT 协议发布