Frontend shared consolidation plan
Status: proposal — not yet executed. Produced alongside the CI/testing work in June 2026, after auditing what
fe-coreandfe-publicactually import fromchainr-frontend-shared.
Context
modules/fe is an npm-workspaces monorepo with three packages: core (logged-in app), public (marketing site), and shared (chainr-frontend-shared, meant to hold reusable components/logic).
An import audit revealed two problems:
sharedwas ~95% dead code. Of the ~184 source files it exported, only a small live surface was ever imported by the apps (theme context, a few buttons, theCard/TitleCard/anim components used by the public home page, the route constants, andcapitalise). The dead files were pruned as part of the testing work —shared/srcis now ~40 files.The apps duplicate logic instead of sharing it.
coreandpubliceach re-implement utilities and UI primitives locally. Concretely:26 files are byte-identical across
coreandpublic(drift waiting to happen).26 more share a filename but have already diverged (drift that already happened).
core/src/utilhas 16 utility modules;sharedpreviously held byte-identical copies of every one, yetcoreimported its own copies.
This document proposes how to make shared the single source of truth.
Goal
Each piece of cross-app logic lives in exactly one place — shared — and both apps import it. No more copy-paste drift.
What becomes canonical in shared
Tier 1 — identical today, move verbatim (low risk)
These 26 files are byte-identical in core and public. Move the canonical copy into shared, delete both app copies, and import from chainr-frontend-shared.
UI primitives (
components/ui/):button.tsx,input.tsx,checkbox.tsx,dropdown-menu.tsx,form.tsx,popover.tsx,progress.tsx,select.tsx,slider.tsx,table.tsx,textarea.tsxHelpers:
lib/utils.ts(thecnhelper),util/array.tsxButtons / links:
MyButton.tsx,MyLink.tsx,buttons/SectionLink,img/Logo.tsxAssets / context / page scaffolding:
Icons.tsx,PageContext.tsx,App.tsx,Pages.tsx,MyAppSections.tsx,NavTitle.tsx,ViewerPage.tsx,PolicyDocs.tsx,PrivacyPolicy.tsx,TermsOfService.tsx
Because core already imports chainr-frontend-shared, the migration per file is: move file → fix its internal relative imports → re-export from the appropriate shared barrel → replace app-local imports with the package import → delete the app copy.
Tier 2 — core/src/util shared logic (low risk, high value)
core owns the full utility set (agent, category, chunk, embedding, file, format, hosting_region, id, language, price, string, time, tree, email, project). These are pure, framework-agnostic, and already exhaustively unit-tested. Promote them to shared/src/util (the now-pruned util folder), move the tests with them, and have core import from the package. If public later needs any (e.g. capitalise, already used), it gets them for free.
Tier 3 — diverged files, reconcile before sharing (needs review)
The 26 same-named-but-different files have drifted and cannot be moved blindly. Examples: App.tsx, AppRouter.tsx, Footer.tsx, Navbar.tsx, NavItem.tsx, NavHeader.tsx, SectionLink.tsx, DocTree.tsx, useAuth.ts, AuthContext.tsx, Auth0ProviderWithNavigate.tsx, ProtectedRoute.tsx, label.tsx, main.tsx.
For each: diff the two versions, decide whether the difference is intentional (app-specific) or accidental drift.
Accidental drift → reconcile to one implementation, then treat as Tier 1.
Intentional → either keep app-local (rename to remove the false implication of sameness) or lift a shared core into
sharedwith app-specific props/slots.
Auth (useAuth, AuthContext, Auth0ProviderWithNavigate, ProtectedRoute) is the highest-value Tier 3 candidate but also the most sensitive — tackle it last and with care.
Suggested shared layout after consolidation
shared/src/
components/
ui/ # radix-based primitives (button, input, select, …)
buttons/ # MyButton, MyLink, SectionLink, ThemeButtons (existing)
img/ # Logo, Icons
text/ # Card, TitleCard (existing) + wrappers
anim/ # existing animation components
nav/ # reconciled nav once Tier 3 is resolved
context/ # ThemeContext (existing) + PageContext
lib/ # utils (cn)
util/ # the full pure-utility set (Tier 2)
routes/ # const, App (existing)
Execution order (each step independently shippable + reviewable)
Tier 2 utils — move
core/src/util/*(+ tests) intoshared/src/util, updatecoreimports. Smallest blast radius, immediate de-dup win.Tier 1
lib/utils.ts+components/ui— these are imported widely, so do them as one focused PR; update both apps.Tier 1 remaining (buttons, Logo, Icons, page scaffolding).
Tier 3 — one PR per concern (nav, then auth), diffing and reconciling.
Guardrails to prevent regression
After each step, run the per-package vitest suites and the
vitestCI job.Add an ESLint
no-restricted-importsrule (or a small CI grep) forbidding new app-local re-implementations of modules that now live inshared.Keep
shared's barrels exporting only what is consumed — re-run the import audit periodically soshareddoes not silently re-accumulate dead code.
Verification
cd modules/fe && npm run build --workspace=sharedsucceeds.npm run test --workspace=core/public/sharedall green.npx tsc --noEmit -p core/tsconfig.jsonandpublic/tsconfig.jsonreport nochainr-frontend-sharedresolution errors.npm run build --workspace=coreand--workspace=public(vite) succeed.