Frontend Structure
All three templates use the same feature split: APIs and types are split by business domain, pages live under each stack’s page directory, and shared technical code lives under components/ and lib/. React/Vue use src/; Svelte uses src/lib/ and src/routes/.
Request Layer
Section titled “Request Layer”The frontend HTTP layer is a lightweight native fetch wrapper and does not use axios. It has two layers:
src/api/http.ts— infrastructure:BASE_URL, query-string building, auth headers,Content-Dispositionfilename parsing, JSON requests, and raw requests. Used only byclient.ts.src/api/client.ts— the publicapiClient:get/post/put/delete/download/upload/getWithHeaders.
Behavior:
- The base URL is fixed at
/api; during development Vite proxies it tolocalhost:8088. - Automatically attaches
Authorization: Bearer <token>. - On a 401 response, clears the login state and redirects to the login page.
get/post/put/deleteall return{ code, message, data }and do not throw on network or HTTP errors; callers checkcode.download/upload/getWithHeadersuse raw requests, throw on failure, and keep the response headers (export password, job token, …).
In Svelte these two layers live at src/lib/api/http.ts and src/lib/api/client.ts, with the same behaviour.
The calls for each business domain are split under src/api/ (src/lib/api/ in Svelte): auth.ts, user.ts, role.ts, permission.ts, menu.ts, system.ts, dashboard.ts, ai-model.ts, audit-log.ts, data-management.ts. Request and response types live in src/types/<domain>.ts (src/lib/types/<domain>.ts in Svelte); api/ keeps only the call functions.
// src/api/client.ts (illustrative)export const apiClient = new ApiClient();
export async function getUsers(params?: PageParams) { return apiClient.get<PaginatedData<User>>('/users', params);}// src/api/client.ts (illustrative)export const apiClient = new ApiClient();
export async function getUsers(params?: PageParams) { return apiClient.get<PaginatedData<User>>('/users', params);}// src/lib/api/client.ts (illustrative)export const apiClient = new ApiClient();
export async function getUsers(params?: PageParams) { return apiClient.get<PaginatedData<User>>('/users', params);}React and Vue keep byte-identical src/api/ and src/types/; change both together. Svelte keeps the same domain files and export signatures under src/lib/api and src/lib/types.
API layer rules
Section titled “API layer rules”- Call definitions only: files under
api/export call functions only — no formatting, DOM work, toasts, or business orchestration. - Types belong in
types/: request bodies, responses, and query-parameter types go insrc/types/<domain>.ts(src/lib/types/<domain>.tsin Svelte);api/imports them withimport type. - No cross-domain imports: business-domain files do not import each other; shared capabilities go in
lib/. - Upgrade rule: only when a domain file grows past ~150 lines, or the domain needs a second file, promote
api/<domain>.tstoapi/<domain>/index.tsplus siblings. Keep the rest flat; do not nest ahead of need.
Routing and Authorization
Section titled “Routing and Authorization”- Routing uses
react-router(React),vue-router(Vue), or SvelteKit file routing (Svelte). ProtectedRoute(a route guard in Vue,(app)/+layout.tsin Svelte) checks only whether the user is logged in; if not, it redirects to the login page.- The sidebar is loaded dynamically from
GET /api/menus/navigation; the backend filters by current-user permissions and omits groups with no visible items. - Menu order, groups, routes, and icons come from
menu_groups/menu_itemsinstead of hard-coded data inAppSidebar. - The real access control is in the backend: hiding menus on the frontend is only a UX improvement, and the backend still rejects unauthorized requests by permission point.
Security tip: do not rely solely on frontend routing for permission decisions; the server is authoritative. See Permission System.
State Management
Section titled “State Management”| React | Vue | Svelte | |
|---|---|---|---|
| Auth state | lib/auth-context.tsx |
stores/auth.ts (Pinia) |
lib/stores/auth.svelte.ts |
| Site config | lib/site-config.tsx |
stores/site-config.ts |
lib/stores/site-config.svelte.ts |
| Theme | components/theme-provider.tsx |
stores/theme.ts |
lib/stores/theme.svelte.ts |
Site config comes from the public endpoint GET /api/public/config and is used on the login page to display the site name and maintenance message, and to determine whether registration is open.
UI Conventions and Theming
Section titled “UI Conventions and Theming”- Three responsive modes: cards and a drawer below
768px, an icon rail from768pxto1279px, and the full sidebar at1280pxand above. Below 1280 it starts collapsed (also when the viewport shrinks at runtime, without overwriting the saved desktop preference); content is capped at 1536px. - The design spec lives in
templates/frontend-react/DESIGN.md(the Vue and Svelte templates are identical): blue-grey neutrals (oklchhue 256–265) with a deep navy primary, Inter body text and Manrope headings, a 6/8/10/14/18 radius scale, 36px controls (44px on touch). - Light/dark theme switching is provided (
ThemeToggle), and the preference is persisted. - All three templates use Tailwind CSS v4 + shadcn: shadcn/ui (Radix UI) for React, shadcn-vue (Reka UI) for Vue, and shadcn-svelte (Bits UI) for Svelte. Shared components such as forms, tables, pagination, and delete confirmation live under
components/shared/orsrc/lib/components/shared/.
The React version ships PWA support through vite-plugin-pwa, so the build output can be installed as a desktop/mobile app. Icons use lucide-react.
The Vue version ships PWA support through vite-plugin-pwa, uses @lucide/vue icons, and manages notifications with the use-toast composable. All requests go through the api/client.ts fetch wrapper; the template does not depend on axios.
The Svelte version ships PWA support through @vite-pwa/sveltekit, uses @lucide/svelte icons, and manages notifications with svelte-sonner. All requests go through the src/lib/api/client.ts fetch wrapper; the template does not depend on axios.
Adding a Page
Section titled “Adding a Page”Taking React as an example:
- Create a new page component under
src/pages/. - Register the route in
router.tsx. - Define a permission code, then create or synchronize the menu item with its route and icon in Menu & Permissions, and grant it to roles.
- Add the domain’s calls and types under
src/api/andsrc/types/.
For Vue, modify the corresponding pages/, router/index.ts, api/, and types/; menu configuration is still performed in the admin panel.
For Svelte, create +page.svelte under src/routes/(app)/ (with subcomponents in the same folder), add calls and types under src/lib/api and src/lib/types, and configure the menu in the admin panel as well.