Skip to content

Template Conventions

The heart of the scaffold is the templates/ directory: the files inside it are exactly what users end up with. Modifying a template is the same as modifying a generated project.

The directory organization of different stacks is deliberately not unified, and instead follows each language’s community conventions:

Template Organization
backend-python/ Domain-modular: app/core/ (infrastructure) + one package per business domain (auth/, user/, role/, permission/, menu/, …), each containing models.py / schemas.py / service.py / router.py; schema changes go through migrations/ (Alembic)
backend-java/ Layered: controller/, service/, repository/, entity/, dto/, with infrastructure split by responsibility across common/, config/, catalog/, bootstrap/, web/, data/, security/; schema changes go through db/migration/ (Flyway)
frontend-react/ and frontend-vue/ Feature-based: pages under pages/settings/<Domain>/, APIs split by domain under api/, types split by domain under types/
frontend-svelte/ SvelteKit file routing + src/lib/: pages under src/routes/(app)/settings/<domain>/, APIs/types under src/lib/api and src/lib/types

docs/contract/api.md is the API contract both backends follow, pinned by two executable test suites:

  • Python: templates/backend-python/tests/test_contract.py
  • Java: templates/backend-java/src/test/java/com/hmilyld/fullstack/ContractTest.java

Change the contract first, then both implementations and both test suites. A drift on either side fails its tests.

The structures are deliberately un-unified, but the quality bar is the same:

Convention Python Java
Failure Raise domain exceptions (AppException subclasses) Raise domain exceptions (AppException subclasses)
Transactions get_db commits on return, rolls back on error @Transactional rolls back on error
Response types Pydantic schemas + model_dump() dto/*Response records
Pagination out of range Clamped Clamped
Schema changes Alembic migrations Flyway migrations
Role-name checks Only admin (all permissions) and admin-account protection, one place each Same
  • Frontend and backend UI copy uniformly uses Chinese.
  • API responses are fixed as { code: 0, message: "success", data }, with code: -1 for errors.
  • TS/JS variables use camelCase, and components use PascalCase.
  • Python Pydantic schema fields use camelCase (such as roleId), and ORM fields use snake_case (such as role_id).
  • Python’s ApiResponse / PaginatedData live in app/core/schemas.py.
  • The permission code catalog is the single source of truth: Python app/catalogs/permissions.py, Java catalog/PermissionCatalog.java. The two must stay identical; npm run sync:permissions:check fails on drift, and the tables in reference/permissions.md are generated by the same script — do not edit them by hand. Migrations no longer contain permission seed rows.
  • Menu presentation is separate from authorization: permissions handles authorization, while menu_groups / menu_items own groups, routes, icons, order, and visibility (hidden).
  • Menu permissions must be created through Menu & Permissions; built-in items cannot be deleted, and deleting a custom item cascades to its operation permissions and role grants.
  • Export archives use manifest.json + schema.sql + checksums.sha256 + data/*.jsonl, support only same-backend/same-version restore, and exclude app_state.
  • The frontend HTTP layer is a lightweight fetch wrapper (api/client.ts over api/http.ts); do not introduce axios.
  • The fetch wrapper must support binary downloads, FormData uploads, and custom status headers instead of assuming every response is JSON.
  • API docs URLs are identical in both stacks: /docs (Swagger UI) and /openapi.json (OpenAPI description). Python serves them via FastAPI, Java via SpringDoc.