Aller au contenu

๐ŸŽจ Frontend Development

This section covers the SvelteKit frontend architecture, components, and development patterns.

๐Ÿ“– Overview

LibreFolio's frontend is built with:

  • SvelteKit 2.x - Full-stack web framework
  • Svelte 5 - Reactive UI framework using Runes ($state, $derived, $effect)
  • Tailwind CSS 4.x - Utility-first CSS (configured via @theme in CSS)
  • TypeScript - Type safety
  • lucide-svelte - Icon library

๐Ÿ“‚ Directory Structure

frontend/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ routes/           # SvelteKit pages and routing
โ”‚   โ”‚   โ”œโ”€โ”€ (app)/        # Authenticated app routes (Dashboard, Brokers, etc.)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ dashboard/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ brokers/
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [id]/    # Broker detail page
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ assets/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ transactions/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ fx/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ files/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ settings/
โ”‚   โ”‚   โ””โ”€โ”€ +page.svelte  # Login page (Public)
โ”‚   โ””โ”€โ”€ lib/
โ”‚       โ”œโ”€โ”€ api/          # API client (Zodios, generated from OpenAPI)
โ”‚       โ”œโ”€โ”€ components/   # Reusable components
โ”‚       โ”‚   โ”œโ”€โ”€ auth/     # LoginCard, RegisterCard, ForgotPasswordCard
โ”‚       โ”‚   โ”œโ”€โ”€ brokers/  # Broker cards, forms, icon, import
โ”‚       โ”‚   โ”œโ”€โ”€ files/    # FilesTable with DataTable
โ”‚       โ”‚   โ”œโ”€โ”€ layout/   # Sidebar, Header, LanguageSelector
โ”‚       โ”‚   โ”œโ”€โ”€ settings/ # Settings tabs (Profile, Preferences, Global, About)
โ”‚       โ”‚   โ”œโ”€โ”€ table/    # DataTable suite (DataTable, toolbar, pagination, column filter, SelectionBar)
โ”‚       โ”‚   โ””โ”€โ”€ ui/       # Generic UI atoms
โ”‚       โ”‚       โ”œโ”€โ”€ input/    # PasswordInput, PasswordStrength
โ”‚       โ”‚       โ”œโ”€โ”€ media/    # ImageCropper, ImageEditModal, AssetPickerModal, FileEditModal
โ”‚       โ”‚       โ”œโ”€โ”€ modals/   # ModalBase, ConfirmModal
โ”‚       โ”‚       โ”œโ”€โ”€ select/   # SimpleSelect, SearchSelect + specialized selects
โ”‚       โ”‚       โ”œโ”€โ”€ tabs/     # TabBar (used standalone and by PageToolbar)
โ”‚       โ”‚       โ””โ”€โ”€ toolbar/  # PageToolbar โ€” shared responsive shell (see Toolbar & Responsive Layout)
โ”‚       โ”œโ”€โ”€ i18n/         # Internationalization (EN, IT, FR, ES)
โ”‚       โ”œโ”€โ”€ stores/       # Store Client System (State Management)
โ”‚       โ”‚   โ”œโ”€โ”€ app/          # auth, clientSession, settings, globalSettings, themeStore, language, privacyStore, toastStore, โ€ฆ
โ”‚       โ”‚   โ”œโ”€โ”€ core/         # EntityStore, EditBuffer, TimeSeriesStore
โ”‚       โ”‚   โ”œโ”€โ”€ reference/    # brokerStore, assetStore, currencyStore, countryStore, sectorStore, fxRoutesStore
โ”‚       โ”‚   โ”œโ”€โ”€ portfolio/    # portfolioStore (report cache), portfolioMutation, lotsAnalysisStore, dashboardViewStore
โ”‚       โ”‚   โ”œโ”€โ”€ risk/         # riskStore, riskBenchmarkStore, riskPanelController
โ”‚       โ”‚   โ”œโ”€โ”€ transactions/ # txStore, transactionTypeStore
โ”‚       โ”‚   โ”œโ”€โ”€ fx/           # fxCardInversionStore
โ”‚       โ”‚   โ”œโ”€โ”€ files/        # imagePreviewCache
โ”‚       โ”‚   โ”œโ”€โ”€ assetPriceStoreRegistry.ts     # Registry: price series per asset and currency
โ”‚       โ”‚   โ”œโ”€โ”€ fxStoreRegistry.ts             # Registry: rate series per FX pair
โ”‚       โ”‚   โ”œโ”€โ”€ dateRangeStore.svelte.ts       # Date range shared by the pages
โ”‚       โ”‚   โ”œโ”€โ”€ dateRangeController.svelte.ts  # Per-page wiring of that date range
โ”‚       โ”‚   โ”œโ”€โ”€ chartSettingsStore.svelte.ts   # Chart aesthetics and signal configs (localStorage)
โ”‚       โ”‚   โ”œโ”€โ”€ currencyGraphStore.ts          # FX currency graph (session cache)
โ”‚       โ”‚   โ””โ”€โ”€ signalCatalogStore.svelte.ts   # Signal catalog per domain (asset, FX)
โ”‚       โ”œโ”€โ”€ types/        # TypeScript type definitions
โ”‚       โ””โ”€โ”€ utils/        # Utilities (urlFilters, chartUtils, โ€ฆ)
โ”‚           โ”œโ”€โ”€ files/        # imageCrop.ts, upload.ts
โ”‚           โ””โ”€โ”€ layout/       # responsiveLayout.svelte.ts, labelShrink.ts, dropdownPosition.ts
โ”œโ”€โ”€ e2e/                  # Playwright E2E tests
โ””โ”€โ”€ static/               # Static assets

โšก Svelte 5 Runes

New components use Svelte 5's Runes for reactivity, but a minority of older components use no rune at all, so Svelte compiles them in legacy mode (export let props, $: statements). The one consequence to know: in a legacy component, a function call inside a template expression compiles into $.untrack(โ€ฆ), so runes state read inside that function is not tracked โ€” that is why the Brokers page stopped following the privacy toggle (R20). Render such a value through a runes child (e.g. lib/components/ui/display/CurrencyAmount.svelte) or migrate the component; see Legacy components freeze masked output.

๐Ÿ”‘ Key Runes Used

  • $state: Declares reactive state.
    let count = $state(0);
    
  • $derived: Declares derived state (automatically updates when dependencies change).
    let double = $derived(count * 2);
    
  • $effect: Side effects (runs when dependencies change).
    $effect(() => {
        console.log(count);
    });
    
  • $props: Declares component props.
    let { title, active = false } = $props();
    

๐Ÿ“š Documentation Sections


๐Ÿ—๏ธ Build & Development

Frontend tasks are managed via dev.py front:

# Start Vite dev server with Hot Module Replacement
./dev.py front dev

# Build for production (output in frontend/build/)
./dev.py front build

# Build with source maps for debugging
./dev.py front build --debug

# Type-check with svelte-check
./dev.py front check

# Preview production build locally
./dev.py front preview
Command Description
front dev Starts Vite at localhost:5173, proxies API calls to backend
front build Production build with minification and tree-shaking
front build --debug Build with source maps (useful for debugging deployed code)
front check Runs svelte-check for TypeScript and Svelte diagnostics
front preview Serves the production build locally for testing

Development workflow

Run ./dev.py server in one terminal and ./dev.py front dev in another. The Vite dev server proxies /api calls to the backend automatically.

Topic Description
DataTable Advanced table with sorting, filtering, pagination
Toolbar & Responsive Layout PageToolbar shell, threshold-driven tiers, per-page tuning
FX Chain Algorithm DFS + graphology for multi-step FX routes
Authentication LoginCard, RegisterCard, ForgotPasswordCard
Settings User preferences, profile, and global settings
File Upload File uploader, image crop, asset picker