Skip to content

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/.

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-Disposition filename parsing, JSON requests, and raw requests. Used only by client.ts.
  • src/api/client.ts — the public apiClient: get / post / put / delete / download / upload / getWithHeaders.

Behavior:

  • The base URL is fixed at /api; during development Vite proxies it to localhost:8088.
  • Automatically attaches Authorization: Bearer <token>.
  • On a 401 response, clears the login state and redirects to the login page.
  • get / post / put / delete all return { code, message, data } and do not throw on network or HTTP errors; callers check code.
  • download / upload / getWithHeaders use 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/user.ts
// src/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.

  1. Call definitions only: files under api/ export call functions only — no formatting, DOM work, toasts, or business orchestration.
  2. Types belong in types/: request bodies, responses, and query-parameter types go in src/types/<domain>.ts (src/lib/types/<domain>.ts in Svelte); api/ imports them with import type.
  3. No cross-domain imports: business-domain files do not import each other; shared capabilities go in lib/.
  4. Upgrade rule: only when a domain file grows past ~150 lines, or the domain needs a second file, promote api/<domain>.ts to api/<domain>/index.ts plus siblings. Keep the rest flat; do not nest ahead of need.
  • Routing uses react-router (React), vue-router (Vue), or SvelteKit file routing (Svelte).
  • ProtectedRoute (a route guard in Vue, (app)/+layout.ts in 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_items instead of hard-coded data in AppSidebar.
  • 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.

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.

  • Three responsive modes: cards and a drawer below 768px, an icon rail from 768px to 1279px, and the full sidebar at 1280px and 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 (oklch hue 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/ or src/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.

Taking React as an example:

  1. Create a new page component under src/pages/.
  2. Register the route in router.tsx.
  3. Define a permission code, then create or synchronize the menu item with its route and icon in Menu & Permissions, and grant it to roles.
  4. Add the domain’s calls and types under src/api/ and src/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.