Shared configuration and utilities
Shared configuration and utilities provide the common facts and small services that keep the application shell and dashboard views consistent. They define the product identity, navigation model, demo user context, display helpers, browser persistence boundary, font choices, and server-side cookie actions used by higher-level experiences. This page is a child of Shared application services. Dashboard composition is described in Dashboard experiences, while preference behavior is described in Personalization system and Preferences and theme runtime.
Application identity and navigation
Application configuration
The application configuration is the single source for the product name, public links, package version, copyright text, and page metadata. The root layout uses its title and description for the browser and document metadata, while dashboard branding uses its name. This keeps visible identity and document identity aligned.
References: src/…/app-config.ts• L1-16 src/…/layout.tsx• L8-19 src/…/app-sidebar.tsx• L17-47
Application icons
The application icon helper creates a square image with a black background and the shared product logo centered inside it. The icon routes use it for the standard browser icon sizes and the Apple touch icon, so those entry points show the same product mark with consistent framing.
References: src/…/app-icon.tsx• L1-25 src/…/icon.tsx• L1-17 src/…/apple-icon.tsx• L1-9
Sidebar navigation model
The sidebar item definitions describe the destinations that the main dashboard exposes. A navigation group contains ordered items, and an item can be a direct link or a parent with sub-items. Each item can also carry an icon, a badge, a disabled state, or a new-tab hint, so the dashboard sidebar can present active, upcoming, legacy, and versioned destinations from one model.
The current groups separate the main dashboard views from page-oriented views, legacy dashboard versions, and items that are not yet available. Authentication links sit under a parent item and open their versioned entrypoints in a new tab. The sidebar renderer consumes these definitions rather than rebuilding the menu for each route.
References: src/…/sidebar-items.ts• L34-70 src/…/sidebar-items.ts• L72-189 src/…/sidebar-items.ts• L191-268 src/…/sidebar-items.ts• L270-300 src/…/app-sidebar.tsx• L18-24 src/…/app-sidebar.tsx• L52-58
Shared user data
Demo user records
The shared user data supplies the small set of user records used by the dashboard demo. The first record is also the root user shown in the sidebar account area, while the full list feeds the dashboard account switcher. These records give presentation components a common identity shape without requiring a live user service.
The same data supports the users view as representative organization-member content. It is therefore sample application context, not an authentication or account system.
References: src/…/users.ts• L1-20 src/…/layout.tsx• L8-10 src/…/layout.tsx• L62-67 src/…/app-sidebar.tsx• L17-19 src/…/app-sidebar.tsx• L55-58
Generic display utilities
Class and value formatting
The generic utility set handles recurring display tasks across unrelated views. It creates uppercase initials for identity fallbacks and formats numbers as localized currency with optional currency, locale, and decimal controls.
These helpers keep common display rules in one place. For example, the sidebar account control uses the initials helper when a user has no avatar, while views that show monetary values can use the currency helper to apply one locale-aware format.
References: src/…/utils.ts• L1-35 src/…/nav-user.tsx• L15-16 src/…/nav-user.tsx• L38-45 src/…/layout.tsx• L8-10
Client persistence and cookie boundary
Browser storage helpers
The client storage helpers provide a small safe boundary around browser localStorage. They save string values for client-only state and return null when a read is not available. A write failure is contained and is logged only outside production, so storage limits or browser restrictions do not stop the application from rendering.
Browser cookie helpers
The browser cookie helpers manage simple, path-wide cookies for client-side state. They support setting a value with a day-based lifetime, reading a named value, and removing a value. They run only in the browser; server-side cookie access belongs to the server action boundary.
Preference persistence choices
The preference persistence layer selects where each registered preference is saved. A client cookie can carry settings that should be available to the browser, localStorage is available for client-only state, a server cookie can be written through a server action, and none means that the value returns to its default after reload. Layout-critical settings avoid localStorage so the server and browser can start from the same value.
The following flow shows how a preference change reaches its persistence target.
flowchart LR
A[Preference change] --> B{Persistence mode}
B -->|client-cookie| C[Browser cookie]
B -->|localStorage| D[Browser local storage]
B -->|server-cookie| E[Server action]
E --> F[Server cookie]
B -->|none| G[Default after reload]
References: src/…/local-storage.client.ts• L1-19 src/…/cookie.client.ts• L1-24 src/…/preferences-storage.ts• L1-35 src/…/preferences-config.ts• L1-12 src/…/preferences-config.ts• L55-120
Font registration
Font registry
The font registry gives the application one named catalog of available typefaces. Each entry pairs a stable key and display label with a loaded font definition, which lets preference controls offer font choices without knowing how each font is loaded.
The registry also exposes the list of valid keys, the combined font variable names used by the document, and label-ready options for selection controls. It includes sans, serif, and monospace choices as well as display-focused options. The root layout applies the combined variables to the document so the registered choices are available across the application.
References: src/…/registry.ts• L1-22 src/…/registry.ts• L24-109 src/…/registry.ts• L111-188 src/…/registry.ts• L190-201 src/…/layout.tsx• L8-10 src/…/layout.tsx• L32-45
Server action boundary
Cookie and preference actions
The server action module is the server-side boundary for cookie access. It reads a named cookie, writes a cookie with a path and lifetime, and reads registered preferences from server cookies while falling back to an allowed default when a value is missing or invalid.
The preference action uses the shared preference registry as its contract. This links server-rendered layout choices to the same allowed values and defaults used by the client preference store, which prevents an unsupported cookie value from becoming application state.
References: src/…/server-actions.ts• L1-40 src/…/preferences-config.ts• L55-133 src/…/preferences-storage.ts• L14-34 src/…/layout.tsx• L18-35
Change checklist
When these files or sections are changed, remember to consider these:
- Keep application metadata and visible product branding aligned when changing
APP_CONFIG. - Keep the standard and Apple icon routes aligned with the shared logo framing when changing icon sizes or product branding.
- Keep sidebar item IDs, URLs, nesting, and disabled or new-tab states aligned with the route destinations that render them.
- Keep the shared user record shape compatible with both the dashboard account switcher and the sidebar account control.
- When adding a preference value, update its allowed-value source and persistence definition together so client and server parsing accept the same contract.
- Keep font registry keys aligned with preference values and keep the document’s font variable list available to the global layout.
- Preserve the client-versus-server cookie boundary when changing persistence behavior; browser helpers must not replace server action access for server-rendered state.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A sidebar definition points to a missing or renamed route | The menu presents a destination that cannot complete its intended dashboard flow | Update the navigation definition with the route change and review its nesting or availability state |
| An icon route uses an unsupported size or bypasses the shared icon helper | Browser and Apple surfaces can show inconsistent product identity or image output | Keep icon routes on the shared square image contract and review size metadata with logo changes |
| A preference cookie contains a value outside its registry | The setting could produce an unsupported document state | parsePreference checks the registered values and returns the registered default |
A layout-critical preference is saved only in localStorage | Server-rendered and browser-rendered layout state can disagree during startup | Keep sidebar layout preferences on a cookie-backed mode |
| Browser storage is blocked or full | A client-only value is not saved, but the view can continue with its current or default state | Storage helpers contain browser access errors and return null on failed reads |
| The shared root user lacks the fields expected by account controls | Sidebar identity and account switching can show incomplete data | Preserve the common user fields used by NavUser and the dashboard account switcher |
Key files
| File | Why to read it |
|---|---|
| src/…/app-config.ts | Defines the product identity, public links, and document metadata used across the shell. |
| src/…/app-icon.tsx | Creates the shared square product image used by browser and Apple icon routes. |
| src/…/icon.tsx and src/…/apple-icon.tsx | Connect the shared icon image to the browser and Apple metadata surfaces. |
| src/…/sidebar-items.ts | Defines the dashboard navigation groups, routes, badges, and sub-item behavior. |
| src/…/users.ts | Provides the shared demo user records and root user used by dashboard account views. |
| src/…/utils.ts | Shows the common identity and currency display helpers. |
| src/…/preferences-config.ts | Defines the allowed preference values, defaults, and persistence contract shared by client and server code. |
| src/…/preferences-storage.ts | Connects preference changes to browser storage or server cookie actions. |
| src/…/local-storage.client.ts | Provides the safe client-only local storage boundary. |
| src/…/cookie.client.ts | Provides browser-only cookie read, write, and delete helpers. |
| src/…/registry.ts | Defines the available font choices, their labels, and the document-level font variables. |
| src/…/server-actions.ts | Exposes server-side cookie and preference reads and cookie writes. |
| src/…/layout.tsx | Shows how configuration, preference defaults, and font variables enter the global document. |
| src/…/app-sidebar.tsx | Shows how configuration, navigation definitions, and shared user data reach the dashboard sidebar. |