Skip to content

Architecture

Code Bearings is a monorepo with three packages sharing a strict layering contract:

@code-bearings/core ← Shared product logic
@code-bearings/cli ← Thin CLI consuming core
@code-bearings/vscode ← Thin editor surface consuming core

Core owns truth. CLI and extension are thin consumers. No forked product.

Source files (TypeScript/JavaScript)
Indexer (ts-morph AST parsing)
BearingsStore (SQLite graph database)
├── files, symbols, edges, modules
├── module boundaries, metrics
Review Engine (diff → ChangeBrief)
├── risk scoring
├── symbol explanations
├── reviewer tips
├── contract shift detection
Rendering (HTML, Markdown, JSON)
├── CLI output
├── VS Code webview
└── CI artifacts

The graph database is a SQLite file (.code-bearings/bearings.db) with these tables:

TableContents
filesSource files with paths and line counts
symbolsFunctions, classes, interfaces, types, variables, enums
edgesRelationships between symbols (imports, calls, called_by, references, implements, extends, reads, writes, exposes, verified_by)
testsTest records with name, file, and line
test_targetsLinks tests to the symbols they exercise
entrypointsExported symbols, CLI entry points, API routes, jobs, event handlers
modulesDetected module boundaries
module_filesWhich files belong to which modules
module_depsModule-level dependency edges with weight
bearings_metaKey-value metadata (file count, index timestamp)

Code Bearings detects module boundaries using a priority chain. Higher-priority strategies win when boundaries overlap:

PriorityKindHow detected
1OverrideUser-defined boundaries via .code-bearings/modules.json or code-bearings.modules.json
2PackageDirectory containing a package.json (monorepo packages)
3BarrelDirectory with index.ts re-exporting symbols (more re-exports than own logic)
4DirectoryDirectory containing multiple related source files (fallback)
4FileSingle file with exported symbols (weakest boundary)
HeuristicFallback for ambiguous groupings

Each boundary has a confidence level (low/medium/high) and a reason explaining why it was chosen.

You can define custom module boundaries by creating a config file at .code-bearings/modules.json or code-bearings.modules.json in your project root. Overrides take highest priority in the boundary chain.

[
{
"name": "billing",
"include": ["src/billing/**"],
"exclude": ["src/billing/test/**"],
"responsibility": "Payment processing and invoice generation"
}
]

Each override accepts:

  • name — module name
  • include — glob patterns for files in this module
  • exclude — (optional) glob patterns to exclude
  • responsibility — (optional) human description of what this module owns

A ChangeBrief is generated from a git diff and contains:

  • Summary — one-line description of the change
  • Confidence — how much of the change Code Bearings understands
  • Changed modules — each with risk score, change kinds, symbol explanations, reviewer tips
  • Contract shifts — API changes detected from signature modifications
  • Unknowns — things Code Bearings couldn’t fully resolve

Risk scores range from 0-100 and are computed from:

  • Number and kind of changed symbols
  • Whether changed symbols are exported (public API)
  • Number of callers (fan-in)
  • Whether tests exist for changed symbols
  • Error handling changes
  • Control flow modifications

General Review provides the canonical truth. Other modes are lenses:

ModeAdditional content
Bug HunterFailure hypotheses, blind spots, inspection prompts
LearningSyntax translations, before/after explanations
ArchitectureModule roles, boundary health, system position
ExplorationGuided questions for unfamiliar codebases

The extension is a thin surface over core:

  • Activity bar — dedicated “Code Bearings” view container with Modules and Review Brief tree views
  • Tree views — read from BearingsStore, no separate data model
  • Review panel — renders core’s HTML report in a webview, injects a postMessage bridge for interactivity
  • Cursor providers — hover tooltips, CodeLens annotations, gutter decorations, and status bar context, all calling resolveCursorContext() which is pure computation over existing data
  • Freshness tracker — monitors file saves and git state, shows stale indicators without disrupting reading; optionally auto-re-analyzes on save
CommandWhat it does
Analyze ProjectIndex the workspace and build the code graph
Review ChangesGenerate a change brief from staged + unstaged changes
Review BranchCompare the current branch against a chosen base branch
Show Module CardPick a module and view its card as JSON
Show Function CardEnter a function name and view its card as JSON
System OverviewView the full system map as JSON
Show Symbol DetailView the function or module card for the symbol at cursor
Refresh AllRe-index and/or re-review based on freshness state
SettingDefaultDescription
codeBearings.dbPath.code-bearings/bearings.dbPath to the bearings database
codeBearings.autoAnalyzefalseRe-analyze automatically on file save
codeBearings.reviewModegeneralDefault review mode lens
codeBearings.cursorContext.enabledtrueShow contextual intelligence at cursor
codeBearings.cursorContext.codeLensEnabledtrueShow CodeLens on changed symbols
codeBearings.cursorContext.gutterEnabledtrueShow gutter decorations on changed lines

No new truth is created in the extension layer. Every surface traces back to BearingsStore.