> ## Documentation Index
> Fetch the complete documentation index at: https://loadwise.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture

> How a Loadwise scan flows from the CLI through the checkers to reports and fixes.

A high-level map of how Loadwise is built.

## Overview

```
bin/loadwise.ts ──► lib/shared/cli-dispatch.ts
   │ explain, lsp, editor,      │ perf | rel | maint | sec | a11y ──► lib/<checker>/cli.ts
   │ agent, report-fp,          │ fix ──► lib/shared/fix.ts ──► lib/shared/fix/*
   │ completion                 │ check (default) ──► lib/shared/check.ts
   ▼                            ▼
own modules           lib/shared/reporting/pillars.ts
                         │  scan cache lookup (lib/shared/analysis/scan-cache.ts)
                         │  one child `node loadwise <checker>` per checker,
                         │  or one shared child for several source checkers
                         ▼
              lib/<checker>: TypeScript program (lib/performance/projects.ts,
              native engine in lib/performance/engine) ► per-file analyzers ►
              function summaries / taint ► findings
                         ▼
              lib/shared/reporting + lib/shared/formats ► text, JSON, SARIF, ...
```

## CLI entry

`bin/loadwise.ts` handles `--version`, `--help`, crash-reporting opt-in and the heap limit, then lazily imports the module for the command. Commands such as `explain`, `lsp`, `editor`, `agent` and `report-fp` are routed there. Everything else goes to `lib/shared/cli-dispatch.ts`. It sends `perf`, `rel`, `maint`, `sec` and `a11y` to the `cli.ts` of each checker folder, `fix` to `lib/shared/fix.ts`, and `check` (also the default) to `lib/shared/check.ts`.

## `check` orchestration

`lib/shared/check.ts` validates options such as `--staged`, `--uncommitted` and `--changed-since`, and builds the shared arguments for each checker. `lib/shared/reporting/pillars.ts` runs the selected checkers. Each runs as a child Node process of the same Loadwise entry point (`spawn(process.execPath, [cliEntryPath, ...])`), so a checker in its own child that fails or runs out of memory does not take down the others. When two or more source checkers are selected, `runSharedSourceCheck` runs them in one shared child so they share one source pass and type-check. That shared child is one failure domain: if it fails, crashes, runs out of memory or returns a malformed result, every checker in it is reported as failed. The parent collects each child's JSON over stdout and IPC, merges the results and prints one report.

## TypeScript programs

`lib/performance/projects.ts` finds the project's `tsconfig.json` or `jsconfig.json`, or the workspace packages without one, and creates the TypeScript program with `ts.createProgram`. The bundled TypeScript is 6.0.3. The optional `@typescript/typescript-*` package for the platform provides the TypeScript 7 native engine, used through the vendored API in `lib/performance/vendor/typescript` and loaded by `lib/performance/engine/`. `--engine js` or `--engine native` selects one. In the default `auto` mode, a one-shot scan tries the native engine and falls back to the JS engine when native cannot load the project; a direct `sec` scan and the shared source child of `check` use the JS engine.

## Analysis

* **Per-file analyzers.** Each checker folder (`lib/performance`, `lib/reliability`, `lib/maintainability`, `lib/security`, `lib/accessibility`) holds topic folders of rules that walk each source file's AST. Performance, reliability, security and accessibility analyzers get the type checker from the TypeScript program. Maintainability's common analyzer (`lib/maintainability/analysis/analyze-source.ts`) parses each file on its own with `ts.createSourceFile` and has no type checker; only a few maintainability rules, such as `quality/type-safety-hygiene.ts`, are type-aware. Accessibility also reads static markup (HTML, Vue, Angular, Astro and Jinja templates). Security also reads lockfiles, environment templates, Dockerfiles, Compose files, Kubernetes manifests, GitHub Actions workflows and composite actions, GitLab CI, Azure Pipelines, CircleCI and Bitbucket Pipelines files, Jenkinsfiles, Terraform `.tf` files, Nginx and Apache configuration, static hosting configuration (`vercel.json`, `netlify.toml`, `_headers`, `_redirects`) and `package.json` scripts (see [infrastructure coverage](https://loadwise.mintlify.site/infrastructure-coverage.md)).
* **Interprocedural summaries.** `lib/shared/analysis/function-summaries.ts` summarizes project functions (for example, which parameters a function validates) so rules can look through calls. The security checker's demand-driven backward taint analysis in `lib/security/taint/` starts at a sink and asks whether its argument traces to request data, using those summaries.
* **Call graph.** `lib/shared/analysis/hot-path-graph.ts` ranks performance findings on hot paths.

## Scan cache

`lib/shared/analysis/scan-cache.ts` caches each checker run's result, keyed by a SHA-256 hash of the Loadwise version, the arguments, the Git-tracked inputs, configs and installs. Entries live under the user cache directory, or `LOADWISE_SCAN_CACHE_ROOT` when it is an absolute path, and `scan-cache-storage.ts` reads and writes them. Before using a directory or an entry, `trustedCacheDirectory` and `trustedCacheEntry` check symlinks and hard-link count, and on POSIX systems also ownership and permissions. Windows has no owner or mode bits in `fs.Stats`, so there the resolved cache directory must instead lie inside the user's profile or `LOCALAPPDATA`; otherwise the run is uncached.

## Changed-line mode

`lib/shared/changed-lines.ts` reads `git diff` for `--staged`, `--uncommitted` or `--changed-since <ref>` and returns the changed line ranges per file. The reports keep only findings that overlap those ranges, except dependency vulnerability findings, which are always kept, and maintainability's file-level `file-placement` findings, which are kept for every changed file.

## Fix pipeline

`lib/shared/fix.ts` and `lib/shared/fix/` select fixes by checker, id or scope, and preview them by default. Each checker's `site-fixes/` folder builds the edits. On apply, `fix-safety.ts` refuses a JavaScript or TypeScript file whose new text parses worse than the original; other files get no syntax check. `fix-typecheck.ts` refuses edits that add selected type errors to modified TypeScript files covered by a usable `tsconfig.json`, and `--no-verify-types` turns it off. Neither replaces your own build and tests. `project-file-access.ts` keeps every write inside the project root and writes atomically. `fix-history.ts` and `fix-reverse.ts` record and undo applied fixes. Applied edits are formatted with the project's own Prettier, or Biome when `LOADWISE_ALLOW_BIOME=1`, unless `--no-format` is passed.

## Reporting formats

`lib/shared/reporting/` renders the text report, baselines and impact levels. `lib/shared/formats/` renders `--format` outputs: SARIF (with CWE tags from `security-cwe.ts`), GitHub annotations, JUnit, HTML and others.

## Editors and agents

`lib/editor/` implements the language server behind `loadwise lsp` (`language-server.ts`) and `loadwise editor setup`. `editor/` is the VS Code-compatible extension packaged as VSIX, and `integrations/` holds the Zed, Sublime Text and Eclipse clients. `lib/shared/agent/` implements `loadwise agent`: instructions, the MCP server, pending reports, history and `verify`.

## Other languages

`polyglot/` holds ast-grep rules for Python, Go, Java, C#, Rust, Kotlin, PHP and Ruby. `lib/performance/polyglot.ts` and `lib/maintainability/polyglot.ts` run the `@ast-grep/cli` binary (an optional dependency) with Loadwise's own `sgconfig.yml` and parse its JSON output.

## GitHub Action

`action.yml` runs `bin/github-action.ts`, which runs `loadwise check` on the workspace, writes a job summary and sets the `exit-code` output. When `upload-sarif` is true (the default) and the scan is complete, it also writes a SARIF file and sets the `sarif-file` output; otherwise that output is empty.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.