chain-rdeveloper portal
build

Frontend shared consolidation plan

Status: proposal — not yet executed. Produced alongside the CI/testing work in June 2026, after auditing what fe-core and fe-public actually import from chainr-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:

  1. shared was ~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, the Card/TitleCard/anim components used by the public home page, the route constants, and capitalise). The dead files were pruned as part of the testing work — shared/src is now ~40 files.

  2. The apps duplicate logic instead of sharing it. core and public each re-implement utilities and UI primitives locally. Concretely:

    • 26 files are byte-identical across core and public (drift waiting to happen).

    • 26 more share a filename but have already diverged (drift that already happened).

    • core/src/util has 16 utility modules; shared previously held byte-identical copies of every one, yet core imported 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.tsx

  • Helpers: lib/utils.ts (the cn helper), util/array.tsx

  • Buttons / links: MyButton.tsx, MyLink.tsx, buttons/SectionLink, img/Logo.tsx

  • Assets / 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 shared with 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)

  1. Tier 2 utils — move core/src/util/* (+ tests) into shared/src/util, update core imports. Smallest blast radius, immediate de-dup win.

  2. Tier 1 lib/utils.ts + components/ui — these are imported widely, so do them as one focused PR; update both apps.

  3. Tier 1 remaining (buttons, Logo, Icons, page scaffolding).

  4. 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 vitest CI job.

  • Add an ESLint no-restricted-imports rule (or a small CI grep) forbidding new app-local re-implementations of modules that now live in shared.

  • Keep shared's barrels exporting only what is consumed — re-run the import audit periodically so shared does not silently re-accumulate dead code.

Verification

  • cd modules/fe && npm run build --workspace=shared succeeds.

  • npm run test --workspace=core / public / shared all green.

  • npx tsc --noEmit -p core/tsconfig.json and public/tsconfig.json report no chainr-frontend-shared resolution errors.

  • npm run build --workspace=core and --workspace=public (vite) succeed.