Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<id>/` 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`
Expand Down
59 changes: 53 additions & 6 deletions frontend/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ npm run preview
# Run tests (single run, no watch)
npm run test

# Prove every feature can be removed (slow; add -- <id> for one)
npm run check:removable

# Lint (zero warnings) / auto-fix
npm run lint
npm run lint:fix
Expand All @@ -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/<page>/`.
- 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/<id>/` | `@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 `<FeatureLink>`, 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/<id>.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 (`-- <id>` for one feature,
`-- --no-tests` for a quicker pass).

## Risk controls

Expand Down
58 changes: 57 additions & 1 deletion frontend/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 <label> does label;
// Select (shared/ui/Select.tsx) renders a button, which a wrapping <label> does label;
// the rule just cannot see inside custom components without being told.
'jsx-a11y/label-has-associated-control': [
'error',
Expand Down Expand Up @@ -127,6 +128,61 @@ export default defineConfig(
extends: [tseslint.configs.disableTypeChecked],
languageOptions: { globals: globals.node },
},
{
/*
* The modular monolith's import rules. Every feature must be removable by deleting its
* folder, so a feature imports only itself and shared code; nothing outside a feature
* imports into one — the app finds features through app/lib/registry.ts's glob.
*/
files: ['src/**/*.{ts,tsx}'],
plugins: { boundaries },
settings: {
'import/resolver': { typescript: { project: './tsconfig.json' } },
'boundaries/elements': [
{ type: 'app', pattern: 'src/app/**' },
{ type: 'shared', pattern: 'src/shared/**' },
{ type: 'feature', pattern: 'src/features/*/**', capture: ['feature'] },
{ type: 'testing', pattern: 'src/test/**' },
],
},
rules: {
'boundaries/dependencies': [
'error',
{
default: 'disallow',
policies: [
{
from: { element: { type: 'shared' } },
allow: { to: { element: { types: ['shared', 'testing'] } } },
},
{
from: { element: { type: 'feature' } },
allow: { to: { element: { types: ['shared', 'testing'] } } },
},
{
from: { element: { type: 'feature' } },
allow: {
to: {
element: {
type: 'feature',
captured: { feature: '{{ from.element.captured.feature }}' },
},
},
},
},
{
from: { element: { type: 'app' } },
allow: { to: { element: { types: ['app', 'shared', 'testing'] } } },
},
{
from: { element: { type: 'testing' } },
allow: { to: { element: { types: ['app', 'shared', 'testing'] } } },
},
],
},
],
},
},
prettier,
{
// eslint-config-prettier turns this off as a formatting rule, but Sonar reports it (S6772):
Expand Down
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
.then(regs => regs.forEach(reg => reg.unregister()));
}
</script>
<script type="module" src="/src/main.tsx"></script>
<script type="module" src="/src/app/main.tsx"></script>
</body>
</html>
Loading
Loading