Skip to content

Refactor/frontend modular monolith - #454

Merged
polterguy merged 10 commits into
masterfrom
refactor/frontend-modular-monolith
Nov 23, 2026
Merged

polterguy merged 10 commits into
masterfrom
refactor/frontend-modular-monolith

Conversation

@EbubeEvan

Copy link
Copy Markdown
Collaborator

What this does

Turns the frontend into a modular monolith: every folder under frontend/src/features/ can be deleted and the app still typechecks, builds and passes its tests. Nothing else needs editing when a feature is added or removed.

src/ now has three layers, each with a path alias:

Folder Alias Holds
app/ @app/ The shell: main.tsx, routes/AppRoutes.tsx (login gates + route table), pages/ (not-found, auth screens), components/ (layout, palette, dialogs), lib/, styles/
shared/ @shared/ Everything reusable, by area: api/, auth/, shell/ (feature registry, shell actions, shortcuts), lib/, hooks/, ui/, resources/
features/<id>/ @features/ One folder per dashboard section, plus Chat Ops (chat)

No behaviour change is intended. Every page, link and shortcut works as before when all features are present.

How a feature plugs in

  • Each feature exports a manifest from index.ts: route and lazy page, nav entry, palette links and data sources, shortcuts, and an optional shell component the layout keeps mounted (Chat Ops uses this). app/lib/registry.ts finds manifests with import.meta.glob.
  • Routes, navigation, the command palette, the shortcuts overview and the dashboard guide are built from the registry instead of hardcoded lists (sections.tsx is gone).
  • Links between features go through featureHref(id, suffix) / <FeatureLink>, which render nothing when the target feature is missing.
  • Runtime additions to the shell (footer buttons, palette actions such as the dashboard tour) go through shared/shell/shellActions.ts.
  • Inside a feature: only index.ts at the root, the rest in pages/ (the routed page), components/, hooks/, lib/, styles/ and test/.
  • A backend call only one feature makes lives in its lib/api.ts. The shared API module (shared/api/index.ts) went from 2,331 to ~1,150 lines.
  • Styles only one feature uses live in styles/<id>.css (~2,000 lines moved out of the global sheet, now app/styles/app.css).

How it's enforced

  • eslint-plugin-boundaries in npm run lint: a feature imports only itself, shared and the test helpers, and app and shared never import a feature.
  • npm run check:removable typechecks, builds and tests a copy of the frontend without each feature in turn. All 16 features pass. It takes ~15 minutes, so it isn't in CI or the hooks; -- <id> checks one feature.

Review notes

  • Commits are in sections and are best reviewed one at a time. The move commits (reorganise src…, components, lib and hooks layout, fold core into shared…) are mechanical moves with import rewrites, and git shows them as renames.
  • 162 feature-specific CSS rules stay in the global sheet on purpose. Feature sheets load after app/styles/app.css, so a rule only moved when no later global rule of equal specificity could style the same element. The rule set is unchanged: all 927 rules are still present with identical declarations, checked rule by rule.
  • The initial bundle is +7 kB (+2.4 kB gzipped). That's the manifests, which load eagerly. Pages, palette sources and Chat Ops stay lazy.
  • Tests: app and shared tests run against stand-in features. Tests that link into another feature register a stand-in for it (src/test/features.ts). API tests for moved calls moved with them onto a shared fetch stand-in (src/test/fetchMock.ts). 2,821 tests, up from 2,808.
  • Editors: after pulling, restart the VS Code TypeScript and ESLint servers once so they pick up the new path aliases. Otherwise the editor shows false no-unsafe-* errors.
  • Docs: frontend/AGENTS.md describes the layout and rules, and the root AGENTS.md points to it.

Verified

  • npm run lint, npm run format:check, tsc, vite build
  • npm run test: 2,821 passed
  • npm run check:removable: all 16 features removable

🤖 Generated with Claude Code

Checked

  • dotnet build magic.sln passes, which includes the analyzer rules, and dotnet test magic.sln passes
  • cd frontend && npm run build && npm run test passes, if the frontend changed
  • The README of the plugin is updated, if a slot, or the way one is used, changed
  • backend/files/config/appsettings.json is not part of the change

EbubeEvan and others added 9 commits November 23, 2026 14:18
Adds @app, @core, @shared and @features aliases to tsconfig and Vite, and
eslint-plugin-boundaries with the TypeScript resolver, ahead of splitting
the frontend into independent feature folders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… folders

Moves every file into the modular-monolith layout, with history kept:

- app/: entry point, routing, layout shell, command palette, auth screens
- core/: API transport, auth, backend, errors, toasts, socket, theme
- shared/: generic UI components, hooks, helpers and editor resources
- features/<id>/: one folder per dashboard section, holding its page,
  components, hooks and tests, plus Chat Ops as features/chat

Components and helpers used by a single feature move into it. Imports
within one unit stay relative, and imports across units use the layer
aliases. No behaviour changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…anifests

Each feature folder now exports a manifest from its index.ts: route and
lazy page, nav entry, roomy layout flag, palette links and data sources,
shortcuts, and an optional shell component. app/registry.ts discovers
them with import.meta.glob, so deleting a feature folder removes it from
the build with no other edits.

- core/features.ts holds the registry, featureHref() and hasFeature().
  Links between features go through it and disappear when the target
  feature is missing; shared/ui/FeatureLink wraps that for JSX.
- App routes, Layout navigation, the command palette, the shortcuts
  overview and the dashboard guide read the registry instead of the
  hardcoded sections list, which is removed.
- Chat Ops moves out of Layout into features/chat/ChatShell, adding its
  footer button, palette action and Ctrl+. through core/shellActions.
  The dashboard tour registers its palette action the same way.
- The Chat Ops turn event moves to core, ProgressDialog back to shared,
  and the designer sandbox test next to the designer.
- App, Layout, palette and shortcuts tests run against stand-in features;
  each feature tests its own palette source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…yout

A feature folder now keeps only its manifest (index.ts) at the root.
React components move into components/, plain TypeScript into lib/,
hooks stay in hooks/ and tests in test/. The generator's rule wizards
move under components/wizards/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
core/api.ts keeps the transport and the calls the shell, shared code or
several features make (about half). Every call, type and helper only one
feature uses moves to features/<id>/lib/api.ts, built on the http helper
core exports, so the call leaves with its feature.

The core API tests' cases for moved calls move with them into each
feature's test/api.test.ts, on a shared fetch stand-in in
src/test/fetchMock.ts. Feature tests that mock core/api also mock their
own api module. The suite keeps all 2814 tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rules whose classes only one feature uses move from app/styles.css to
features/<id>/styles/<id>.css, imported by the feature's manifest, so
they load after the global sheet and leave with the feature. About 2,000
lines move; the global sheet goes from 7,123 to 5,052 lines.

Loading later can only change the cascade where a later global rule of
the same specificity styles the same element, so any moved rule with
such a candidate stays global (162 rules). The rule set is unchanged:
all 927 rules are still present with identical declarations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s removable

- eslint-plugin-boundaries: a feature may import only itself, core,
  shared and the test helpers; app, core and shared may not import a
  feature. Violations fail npm run lint.
- npm run check:removable typechecks, builds and tests a copy of the
  frontend without each feature in turn (or the ones named). All 16
  features pass.
- Tests that link into another feature register a stand-in for it
  (src/test/features.ts), so they hold in a build without it.
- Unit tests for the registry and FeatureLink, and a race fixed in the
  Chat Ops shell test that showed under load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e layout

- core/ merges into shared/, grouped by area: api/ (transport, shared
  calls, socket), auth/ (context, stored backends), shell/ (feature
  registry, shell actions, shortcuts, Chat Ops events) and lib/ (errors,
  toasts, nav guard, theme, font, support). The @core alias is gone, and
  the boundary rules have three layers: app, shared, features.
- app/ gets the same layout as a feature: routes/AppRoutes.tsx (the
  login gates and route table, was App.tsx), pages/ (not-found and the
  auth screens), components/, lib/ (feature discovery, OIDC), styles/.
- Each feature's routed page moves from components/ to pages/.

Moves only, no behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… failure regex

SonarCloud: the shared API module exported its mutable baseUrl (S6861),
which nothing outside the module reads; apiBaseUrl() is the accessor.
The removability check's failure filter now groups its alternatives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@polterguy
polterguy merged commit d9f337a into master Nov 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants