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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .claude/docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> **Purpose**: High-level system architecture for AI agents and developers. Read this before touching anything under `src/`.
> **Stability**: Stable — update only when the architecture itself changes (new module, changed data flow), not for feature-level changes.
> Facts here were verified against the code on 2026-07-08. Items marked *[inferred]* are conclusions from structure/naming, not verified line-by-line.
> Facts here were verified against the code on 2026-07-08; the module map and every path were re-verified on 2026-11-25 (story #43) after the monorepo move and the feature-first `src/` layout (#55). Items marked *[inferred]* are conclusions from structure/naming, not verified line-by-line.

## The one-paragraph summary

Expand Down Expand Up @@ -47,8 +47,8 @@ Three analysis modes share this pipeline: **XR** (A-Frame scene in browser/heads
|---|---|---|
| `features/analysis/` | The ANALYSES section: the per-mode analysis commands (file, directory, DOM, clean), the tree and its subsections (active analyses, files/project by language, analysis settings), the workspace scan and the server watcher integration | `commands/analysisCommandRegistrations.ts`, `commands/analysisCommands.ts`, `commands/{file,directory,dom}/`, `views/AnalysisSectionProvider.ts`, `sections/active-analyses/activeAnalysesCommands.ts` (Active Analyses actions and export), `sections/settings/` (one folder per setting; `chartTypeCommandFactory.ts` and the two `shared*SettingCore.ts` at its root), `workspace/workspaceSnapshotService.ts`, `workspace/workspaceFileScanner.ts`, `services/serverWatcherIntegration.ts` |
| `core/analysis/` | **The analysis engine.** Pipeline: launchers, parsers, the requirement processor, sessions, session servers, watchers, refresh, the Python bridge, the scene-asset injection, the language tables | `analysisOrchestrator.ts`, `launchers/launchPipeline.ts`, `launchers/launcherXRAnalysis.ts`, `session/analysisSession.ts`, `session/sessionRegistry.ts`, `session-servers/sessionServerManager.ts`, `watchers/sessionWatcherManager.ts`, `python/executePython.ts`, `python/xrFieldSchemaService.ts`, `configuration/analysisConfigurationStorage.ts`, `languages/languageMetadata.ts`, `languages/supportedLanguages.ts` |
| `code_analysis/python/` | Python analysis backend (see `PYTHON_ANALYSIS.md`) | `main.py`, `tools/lizard_analyzer.py`, `utils/xr_field_schema.py` |
| `core/dependencies/` | Dependency-graph analysis service (see `docs/features/DEPENDENCY_GRAPH_XR.md`) | `DependencyGraphService` *[inferred name from docs]* |
| `backend/src/` (repository root, outside `src/`) | Python analysis backend (see `PYTHON_ANALYSIS.md`); copied into `dist/code_analysis/python` by webpack | `main.py`, `tools/lizard_analyzer.py`, `utils/xr_field_schema.py` |
| `core/dependencies/` | Dependency-graph analysis service (see `docs/features/DEPENDENCY_GRAPH_XR.md`) | `dependencyGraphService.ts`, `dependencyGraphModels.ts` |
| `core/export/` | Analysis export: the manifest, the package transaction and the Git-revision exporter with its Python worker pool | `exportManifest.ts`, `exportPackageTransaction.ts`, `gitRevisionExporter.ts`, `gitRevisionExportCore.ts`, `gitTimelineBlobAnalyzer.ts` |
| `core/history/` | Git history: comparator + Project Evolution. Both services compose a `GitAnalysisSessionContext` (catalogue, per-commit payload cache, analyze/exclude) and a `SingleJobGate` (one job at a time, last successful request); `gitAnalysisShared.ts` holds the pure helpers the export core shares | `gitRepositoryService.ts`, `historicalComparisonService.ts`, `projectEvolutionService.ts`, `gitAnalysisSessionContext.ts`, `gitAnalysisShared.ts` |
| `core/charts/` | Chart template system: registry, models, dimension validation, HTML placeholder processing, the visualization configuration read by every launch | `chartRegistry.ts`, `chartModels.ts`, `xrFieldModels.ts`, `templateCharts.ts`, `chartPresentation.ts`, `getVisualizationConfiguration.ts` (lazy `require` of `settings/settingsAccessors.ts`), `processing/dimensionValidator.ts`, `processing/templateHTMLProcessor.ts`, `processing/templateProcessor.ts`, `processing/placeholders/` |
Expand Down Expand Up @@ -78,7 +78,7 @@ Three analysis modes share this pipeline: **XR** (A-Frame scene in browser/heads

**Layout** (story #55, `docs/cleanup/src-layout.md` §3; pinned by `test/tooling/srcLayout.test.cjs`): `src/` holds `extension.ts` and five layers, `app/` (composition root) → `features/` (one folder per sidebar section) → `core/` (the engine, one folder per domain) → `platform/` (VS Code host plumbing, no feature knowledge) → `shared/` (no VS Code, no domain). Folder names are kebab-case; `core/` and `features/` hold folders only; there are no re-export barrels.

**Per-feature layout convention**: `features/<section>/` has `commands/` (`<x>Commands.ts`, the handlers, and `<x>CommandRegistrations.ts`, the registration array `app/commands/registerAllCommands.ts` collects), `views/` (the `*SectionProvider.ts`, item factories and click handlers, flat), and where needed `services/`, `model/`, `runtime/`. A section with subsections nests them under `sections/<subsection>/` (see `features/analysis/`). Engine code that more than one feature, the servers or the analysis pipeline uses goes in `core/<domain>/`, not in a feature. When adding a feature, mirror this pattern.
**Per-feature layout convention**: `features/<section>/` has `commands/` (`<x>Commands.ts`, the handlers, and `<x>CommandRegistrations.ts`, the registration array `app/commands/registerAllCommands.ts` collects), `views/` (the `*SectionProvider.ts`, item factories and click handlers, flat), and where needed `services/` and `model/`. A section with subsections nests them under `sections/<subsection>/` (see `features/analysis/`). Engine code that more than one feature, the servers or the analysis pipeline uses goes in `core/<domain>/`, not in a feature. When adding a feature, mirror this pattern.

**Folder dependencies** (stories #42, #55): which folder may import which is data in `test/tooling/folderDependencies.json`, checked by `test/tooling/dependencyDirection.test.cjs` (type imports count). A folder is the first directory under `src/`, or the first two under `core/` and `features/` (`twoLevelAreas`); the same file holds the layer order `app → features → core → platform → shared` (`layers`), which the test enforces (no upward edge, no feature importing another feature) except for the reasoned entries in `layerExceptions`. A new cross-folder direction fails the gate until it is added there; a new two-way pair also needs a written reason. The remaining pairs are each documented in that file (all inside the server/analysis subsystems: `core/server`, `core/remote-access`, `core/analysis` with `core/history`, plus `core/server`/`features/active-servers`, which is the one allow-listed upward edge). `platform/` imports no feature folder, and `core/` none besides that edge.

Expand All @@ -90,7 +90,7 @@ Note: before #55 a feature was split between a feature folder and `views/<featur

## Cross-module contracts (the seams that matter)

1. **XR field schema**: Python defines analyzable fields in `code_analysis/python/utils/xr_field_schema.py`; TypeScript consumes it via `core/analysis/python/xrFieldSchemaService.ts` (backed by `main.py --mode schema`). Dimension-mapping validation in `core/charts/processing/dimensionValidator.ts` checks user mappings against this schema. **Changing metrics on the Python side requires keeping this schema in sync.**
1. **XR field schema**: Python defines analyzable fields in `backend/src/utils/xr_field_schema.py`; TypeScript consumes it via `core/analysis/python/xrFieldSchemaService.ts` (backed by `main.py --mode schema`). Dimension-mapping validation in `core/charts/processing/dimensionValidator.ts` checks user mappings against this schema. **Changing metrics on the Python side requires keeping this schema in sync.**
2. **Chart registry**: `core/charts/chartRegistry.ts` (`BabiaChartRegistry` singleton) is the source of truth for available chart types and their dimension requirements.
3. **File ↔ server mapping**: `src/core/server/fileToServerMap.ts` links analyzed files to the server instance serving their visualization; SSE clients are keyed by file URI in `SSEManager`.
4. **Component-asset injection**: TS files in `core/analysis/scene-assets/*ComponentAsset.ts` read runtime JS from `templates/components/` and inline it into generated HTML. A runtime shipped as one file is a row of the `SINGLE_FILE_RUNTIME_ASSETS` descriptor table in `scene-assets/singleFileRuntimeAssets.ts` (output name, folder, refusal label), and its `*ComponentAsset.ts` is a thin wrapper keeping the named exports; multi-part runtimes go through `runtimeAssembly.ts`. The browser runtimes never import TS code; the contract is the injected globals and entity schemas (see `templates/components/COMPONENTS.md`).
Expand All @@ -110,13 +110,13 @@ Every diagnostic of the extension host goes through `src/platform/logging`. A mo
| Path | What it is |
|---|---|
| `templates/` | Raw HTML templates + **browser-side JS runtimes**. `xr/` (scene templates + SSE client scripts), `analysis_livePanel/` (webview panels), `components/` (A-Frame component runtimes — see `templates/components/COMPONENTS.md`; `components/livepanel/` holds shared 2D LivePanel components such as `dataTable.{js,css}` that `LivePanelParser` bundles ahead of each panel's own `main.js`/`style.css`), `utils/color-picker.html`. Read in place at `<extensionPath>/templates` and shipped by the `files` allowlist; not copied into `dist/` since 1.2.1. Source code builds every template path with `resolveTemplatePath(extensionPath, …)` (`src/platform/templatePaths.ts`), never from `__dirname` (wrong from the bundle); tests use `test/helpers/templatesRoot.cjs`. |
| `test/` | All tests. `.test.cjs` unit suites (Node native runner), Python suites, language fixtures, manual HTML harnesses. See `DEVELOPMENT.md`. |
| `test/` | The extension's tests: `.test.cjs` unit suites (Node native runner), the feature baseline, the tooling ratchet, manual HTML harnesses. The Python suites, fixtures and per-language corpus live in `backend/tests/` and `backend/manual_test/`. See `DEVELOPMENT.md`. |
| `resources/` | Icons and media (per-language icons, collaboration/comparison/screen assets). |
| `examples/` | Bundled sample charts + data for the Babia Examples tree section. |
| `scripts/` | Build utilities: `package-vsix.mjs`, `prepare-dev-extension.mjs` (the manual-metrics report tool is `backend/scripts/report-manual-metrics.py`). |
| `docs/` | Human-facing feature docs, linked from the README (vsce rewrites those links to GitHub). Not shipped in the VSIX since 1.2.1. |
| `backend/manual_test/` | Per-language fixtures for `npm run test:analysis` (see its README); outside this package since 1.2.1. |
| `pages/` | GitHub Pages redirect page (deployed by the only CI workflow). |
| `pages/` | GitHub Pages redirect page (deployed by `.github/workflows/deploy-pages-redirect.yml`; the gates run in `ci.yml`). |

## How future agents should use this document

Expand Down
Loading
Loading