This document describes the runtime structure, intended data flow seams, and theming mechanics for the Credence frontend.
The application's provider tree in src/App.tsx establishes the foundation for global state and routing. The order of these providers is load-bearing.
graph TD
A["<BrowserRouter>"] --> B["<SettingsProvider>"]
B --> C["<WalletProvider>"]
C --> D["<ToastProvider>"]
D --> E["<Suspense>"]
E --> F["<Routes>"]
F --> G["<Route path='/' element={<Layout />}>"]
G --> H(Home)
G --> I(Dashboard)
G --> J(Bond)
G --> K(CreateBondPage)
G --> L(TrustScore)
G --> M(Settings)
SettingsProvider: Manages global user preferences (theme mode, network, address display) and application settings (toast toggles and auto-dismiss timing). It must sit high in the tree because it reads fromlocalStorageand applies the data-theme immediately.WalletProvider: Manages Stellar wallet connection state, exposed address, and connect/disconnect functionality. Depends onSettingsProviderfor network preferences.ToastProvider: ExposesaddToastandremoveToastfunctions for global notifications. Must be placed insideSettingsProvider, because the toast component readstoastsEnabledandautoDismisspreferences viauseSettings()to calculate timeout bounds and global mute states.
The route table is defined inside <Routes> in App.tsx wrapped in <Suspense>. It leverages React Router's nested routes.
The top-level route uses src/components/Layout.tsx as an application shell. The Layout component provides:
- Skip-link: A hidden accessibility link for keyboard navigation bypassing the header.
- Header/Nav: Contains
MobileNav(hamburger menu),ThemeToggle, and desktop navigation links. - Main Content: Renders child routes inside
<main id="main-content">via<Outlet />. - Footer: Displays standard legal and document links.
The application implements a pure CSS-variable theming system triggered via DOM attributes.
ThemeMode('light', 'dark', or 'system') is maintained inSettingsContext.- A
useEffectinsideSettingsProviderlistens to this state. - If 'system' is selected, it uses
window.matchMedia('(prefers-color-scheme: dark)')to determine the OS preference. - It sets the
data-themeattribute directly on the root<html>element. src/index.cssscopes token overrides (e.g., color variables) based on[data-theme="dark"], seamlessly transitioning the entire app UI.
Currently, the application operates on mock data to illustrate UI flows.
- Bond Page (
src/pages/Bond.tsx): Contains a hardcodedinitialBondsarray mapped to UI models. State transitions (e.g., slash calculations, withdrawal warnings) execute purely in-memory. - Trust Score Page (
src/pages/TrustScore.tsx): Retrieves its score and tier information via a mock-enableduseTrustScorehook.
src/api/ is the designated boundary for typed API clients and real data fetching.
API types are generated from the OpenAPI 3.1 specification at openapi.yaml:
npm run generate:api # writes src/api/generated.tssrc/api/types.ts re-exports named aliases (TrustScore, Bond, Transaction, etc.) derived from the generated file, keeping the public type surface backwards-compatible while ensuring all types trace back to a single contract. See docs/API_TYPES.md for the full workflow.
When replacing mock data with real integration:
- Create data fetching functions inside
src/api/using the standardapiFetch<T>()helper (orapiFetch<ApiResponse<operations['myOp']>>()for spec-verified types). This ensures all HTTP calls get consistent proxy prefixing, error typing (ApiError), and abort signal handling. - Consume these functions via custom data hooks (e.g.,
useQueryor dedicated React hooks). - Connect
BondandTrustScorecomponents to the new hooks instead of internal state, delegating all Stellar contract reads/writes and backend endpoints to theapilayer.