% SF Dashboard Architecture
Last updated: 2025-11-08
System Overview
The SF Dashboard is a React + Vite single-page application that provides operational visibility and controls for the Salesforce Middleware platform. The UI communicates exclusively with the middleware REST APIs (and optional WebSocket endpoints) to surface system metrics, manage users, and trigger exports. No server-side rendering is used; hosting can be fully static.
User Browser
│
▼
SF Dashboard (React SPA)
│ REST / WebSocket
▼
Salesforce Middleware API Gateway
│
▼
Downstream Services (Salesforce, queues, logging, jobs)
Key Application Layers
Routing & Shell (
src/App.tsx,src/main.tsx)
Sets up React Router routes and mounts the authenticated shell (MainLayout) around protected pages.Auth Guarding (
src/components/auth/)AuthGuardandRequireRolewrap routes to enforce login and RBAC checks usingauth-store. Guards control redirects and fallbacks (spinner, unauthorized page).Pages (
src/pages/)
Feature-oriented containers that load data through service modules, apply view-specific state, and compose reusable UI components.Services (
src/services/)
Typed API clients built on a sharedfetchwrapper. They encapsulate endpoints, map payloads to TypeScript models, and implement error translation.Stores (
src/stores/)
Zustand stores (auth-store,dashboard-store) maintain client-side session data and cross-page state (metrics cache, environment).Hooks (
src/hooks/)usePageTitle,usePermissions, and future hooks centralize cross-cutting logic. Hooks consume stores/services and isolate reusable behaviors.UI Components (
src/components/)
Based on shadcn/ui primitives, organized by domain (dashboard,tables,layout). These components take typed props and avoid direct API calls to maintain separation.
Data Flow
- User navigates to a protected route.
AuthGuardverifies auth state viaauth-store; if absent, redirect to/login.- Page component loads using React Query / service call, passing the active environment from
dashboard-store. - Responses are normalized into view models and rendered via UI components.
- User actions (filters, exports) call service functions; optimistic updates go through Zustand stores, while background mutations use React Query where appropriate.
Environment Awareness
src/config/environments.ts defines available environments with API/WS URLs. The EnvironmentSelector component and dashboard-store coordinate the active selection, influencing outbound service calls.
Extensibility Guidelines
- Keep API interaction inside service modules; never call
fetchdirectly from pages. - Add new feature routes under
src/pagesand register via router configuration inApp.tsx. - Introduce cross-feature state in dedicated Zustand stores to avoid prop drilling.
- For complex feature sets, create domain-specific subfolders (e.g.,
src/features/exports/) housing pages, hooks, and components.
External Integrations
- Authentication: JWT Bearer tokens managed via backend endpoints (
auth-api). Tokens are stored securely, refreshed proactively, and injected via request interceptors. - Real-time Updates: WebSocket endpoints (configurable) support real-time logs/metrics. Socket scaffolding is present; enable by wiring to handlers within feature pages.
- Export Engine:
export-apicoordinates CSV/JSON/XLSX generation; responses trigger browser downloads handled by utility helpers.
Future Enhancements
- Introduce a shared
api-clientlayer to consolidate retries, telemetry, and error reporting. - Add type-safe React Query hooks per feature to standardize caching.
- Configure feature flags (e.g., LaunchDarkly) for incremental roll-outs.