2.2 KiB
2.2 KiB
Design Overview
React‑Auth
- Purpose: Centralize authentication flows (login, logout, token refresh) for the UI.
- Key Concepts
- AuthProvider – React context that stores
user,accessToken, andisAuthenticated. - useAuth hook – Exposes
login,logout,refreshToken, and state values. - Route Guard – HOC/Component (
ProtectedRoute) that redirects unauthenticated users to the login page.
- AuthProvider – React context that stores
- UI: Simple MUI forms, error handling with snackbars, and a loading spinner while the auth request is pending.
- Extensibility: Plug‑in point for additional providers (OAuth, SSO) via a
providersmap.
React‑OpenAPI
- Purpose: Generate UI components directly from an OpenAPI spec (tables, filters, forms).
- Core Modules
ResourceConfig&ResourceField– Typed definitions that describe each endpoint and its fields, includingdisplayFormatfor rendering.EnhancedTable– Data‑grid component that renders rows according to the config, supports relation rendering, sorting, pagination, and custom cell renderers.FilterBar– Dynamically builds filter controls (autocomplete, number‑range, date‑range) based on the same config.
- Data Flow
- Load OpenAPI spec → transform to
ResourceConfigobjects. useQuery(TanStack) fetches data.- UI components consume the config to render tables and filter UI without hand‑written column definitions.
- Load OpenAPI spec → transform to
- Design Goals
- Zero boilerplate – Adding a new resource only requires a JSON config.
- Consistency – All tables share pagination, actions, and styling.
- Extensibility – Override components via
componentsprop.
src (Root Application)
- Entry Point –
main.tsxmounts the React app withBrowserRouterand wraps it withAuthProvider. - Routing – Routes are defined per‑resource (
/admin/:resource,/admin/:resource/edit/:id).ProtectedRouteensures auth. - State Management – TanStack Query handles server state; React Context handles auth state.
- Theming – MUI theming with light/dark mode toggle (future enhancement).
These design notes serve as a concise reference for developers preparing a richer UI/UX implementation on the lovable platform.