diff --git a/AGENTS.md b/AGENTS.md index 990ce89a70..e5abaf98eb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,6 +31,8 @@ cd frontend && npm run lint && npm run format:check - .NET 10 SDK required (no global.json pins it) - Frontend uses Vite + React + TypeScript, not Angular CLI +- The frontend is a modular monolith: each `frontend/src/features//` folder is removable on its + own, with import boundaries enforced by lint. See `frontend/AGENTS.md` before adding code there - The C# build treats warnings as errors, and runs the Sonar rules (SonarAnalyzer.CSharp) next to the Roslyn ones, with the severities of `.editorconfig`. A violation fails `dotnet build`, so fix it, or, for a rule that is not meant for that code, say so in `.editorconfig` with the reason. The SonarCloud workflow builds with `-p:SonarGate=false` diff --git a/frontend/AGENTS.md b/frontend/AGENTS.md index bda9fc0a5e..d42adcf65d 100644 --- a/frontend/AGENTS.md +++ b/frontend/AGENTS.md @@ -19,6 +19,9 @@ npm run preview # Run tests (single run, no watch) npm run test +# Prove every feature can be removed (slow; add -- for one) +npm run check:removable + # Lint (zero warnings) / auto-fix npm run lint npm run lint:fix @@ -40,12 +43,56 @@ npm run format:check `eslint.config.js` with the reason, not with inline disables. - `npm install` installs the husky git hooks (commit-msg: commitlint; pre-commit: lint-staged; pre-push: format check, lint, typecheck, tests). -- Page components live in `src/pages/` and stay thin; their child components, - hooks and helpers live in `src/components//`. -- Tests live in a `test/` folder inside their feature folder (e.g. - `src/components/sql/test/`, `src/lib/test/`) and run in Node by default. Component and - hook tests opt into a DOM with `// @vitest-environment jsdom` on their first - line, and use Testing Library (`src/test/setup.ts` adds the jest-dom matchers). +- Tests live in a `test/` folder next to what they test (e.g. `src/features/sql/test/`, + `src/shared/api/test/`) and run in Node by default. Component and hook tests opt into a DOM with + `// @vitest-environment jsdom` on their first line, and use Testing Library + (`src/test/setup.ts` adds the jest-dom matchers and registers every feature). + +## Architecture: a modular monolith + +`src/` has three layers, each with a path alias: + +| Folder | Alias | Holds | +| --- | --- | --- | +| `app/` | `@app/` | The shell: entry point, route table, layout, command palette, auth screens | +| `shared/` | `@shared/` | Everything reusable, grouped by area (below) | +| `features//` | `@features/` | One folder per dashboard section, plus Chat Ops (`chat`) | + +`app/` is laid out like a feature: `main.tsx` (the entry `index.html` loads), `routes/AppRoutes.tsx` +(the login gates and the route table built from the feature registry), `pages/` (not-found and +the auth screens), `components/` (layout, palette, dialogs), `lib/` (feature discovery, OIDC), +`styles/app.css` and `test/`. + +`shared/` holds `api/` (transport and calls several features make, the socket), `auth/` (auth +context, stored backends), `shell/` (the feature registry, shell actions, shortcuts, Chat Ops +events), `lib/` (errors, toasts, nav guard, theme, font, and plain helpers), `hooks/`, `ui/` +(generic components) and `resources/` (editor language support). + +Every feature can be deleted with its folder and the app still typechecks, builds and passes its +tests. What keeps that true: + +- A feature folder holds `index.ts` (its manifest) and the subfolders `pages/` (the page its + route renders), `components/`, `hooks/`, `lib/` (including `lib/api.ts`, its backend calls), + `styles/` and `test/`. Nothing else sits at its root. +- The manifest (`FeatureManifest` in `shared/shell/features.ts`) declares the feature's route and + lazy page, nav entry, palette links and data sources, shortcuts, and an optional `shell` + component the layout keeps mounted. `app/lib/registry.ts` finds manifests with + `import.meta.glob`, so adding or removing a feature needs no other edit. +- Features never import each other, and `app/` and `shared/` never import a feature. + `eslint-plugin-boundaries` enforces this in `npm run lint`. To link to another feature use + `featureHref(id, suffix)` or ``, which render nothing when that feature is + missing; use `hasFeature(id)` to hide anything else that depends on one. +- Anything a feature contributes to the shell at runtime (footer buttons, palette actions) goes + through `shared/shell/shellActions.ts`, and is withdrawn when the feature unmounts. +- A backend call only one feature makes belongs in that feature's `lib/api.ts`, on the `http` + helper from `@shared/api`. Tests that mock `@shared/api` also mock `../lib/api`. +- Styles only one feature uses live in `styles/.css`, imported by the manifest so it loads + after `app/styles/app.css`. Keep a rule global when moving it could change the cascade. +- Tests of app and shared code register stand-in features (`registerFeatures`) rather than + relying on real ones; a feature's test that links into another uses `withStandInFeatures`. +- `npm run check:removable` proves the whole thing: for each feature it typechecks, builds and + tests a copy of the frontend without that feature (`-- ` for one feature, + `-- --no-tests` for a quicker pass). ## Risk controls diff --git a/frontend/eslint.config.js b/frontend/eslint.config.js index e72bfd694a..b5f91c5fa6 100644 --- a/frontend/eslint.config.js +++ b/frontend/eslint.config.js @@ -11,6 +11,7 @@ import reactHooks from 'eslint-plugin-react-hooks'; import reactRefresh from 'eslint-plugin-react-refresh'; import jsxA11y from 'eslint-plugin-jsx-a11y'; import prettier from 'eslint-config-prettier'; +import boundaries from 'eslint-plugin-boundaries'; import simpleImportSort from 'eslint-plugin-simple-import-sort'; import sonarjs from 'eslint-plugin-sonarjs'; import unicorn from 'eslint-plugin-unicorn'; @@ -93,7 +94,7 @@ export default defineConfig( ], // Dialogs move focus to their first field on open, as the WAI-ARIA dialog pattern asks for. 'jsx-a11y/no-autofocus': 'off', - // Select (components/Select.tsx) renders a button, which a wrapping