Architectural drift detection engine with VS Code integration.
- Overview
- Architecture
- Prerequisites
- Development Setup
- Configuration
- Building the Project
- Running / Debugging the Core Engine
- Running / Debugging the VS Code Extension
- Testing
- Publishing the VS Code Extension
- Packages
- Troubleshooting
DriftGuard is a modular system for detecting architectural drift in codebases, with initial support for TypeScript and planned support for Python. It uses a graph database as the core source of truth for code architecture relationships.
- Core Engine: Scanning engine that orchestrates analysis and manages graph storage
- Language Modules: Pluggable analyzers for different languages (TypeScript, Python)
- VS Code Extension: IDE integration for real-time drift detection
- TypeScript-only analysis
- Import graph extraction
- Circular dependency detection
- Layer boundary violation detection
- Basic drift metrics
- Memgraph graph database backend
Before setting up DriftGuard, ensure the following are available on your system:
- Node.js >= 18.0.0 – Check with
node --version - pnpm (recommended) or npm – The monorepo uses pnpm workspaces. Install pnpm with
npm install -g pnpm. - Memgraph (optional) – Graph database backend. If not running, the engine falls back to a mock graph. See Memgraph installation docs.
- VS Code with the Extension Development tools – Required to run the extension in development mode (press F5).
# Clone the repository
git clone https://github.com/adrianmikula/DriftGuard.git
cd DriftGuard
# Install root-level dev dependencies
npm install
# Install dependencies in each package
# (pnpm workspace symlinks may not work on all platforms)
cd packages/core-engine && npm install
cd ../language-typescript && npm install
cd ../language-python && npm install
cd ../vscode-extension && npm install
cd ../..Note: Due to platform symlink limitations (e.g. Windows), dependencies must be installed in each package individually rather than relying on workspace hoisting.
DriftGuard uses two configuration files:
Copy .env.example to .env and fill in your values:
cp .env.example .env| Variable | Required | Default | Description |
|---|---|---|---|
MEMGRAPH_USERNAME |
Yes | — | Memgraph database username |
MEMGRAPH_PASSWORD |
Yes | — | Memgraph database password |
MEMGRAPH_URI |
No | bolt://localhost:7687 |
Memgraph connection URI |
ENGINE_URL |
No | http://localhost:3000 |
Core engine HTTP server URL |
Controls layer definitions, analyzer settings, file discovery, rule enablement, and severity. The shipped defaults work for a typical TypeScript project.
| Key | Description |
|---|---|
layers |
Named layer definitions with path patterns |
analyzer.fileExtensions |
File types to include in analysis |
fileDiscovery |
Glob patterns for file discovery |
rules |
Rule enablement and severity per rule ID |
database.uri |
Non-sensitive database URI (overridden by .env) |
engine.url |
Engine server URL |
Config precedence: environment variables > --config flag > workspace .driftguard/config.json.
The extension also supports VS Code workspace settings under the driftguard. namespace:
// .vscode/settings.json
{
"driftguard.engineUrl": "http://localhost:3000",
"driftguard.timeoutMs": 30000
}VS Code settings override config file values.
Each package must be built individually. Build core-engine and language-typescript before vscode-extension, as the extension depends on a packed tarball of the core engine.
cd packages/core-engine && npm run build
cd ../language-typescript && npm run build
cd ../language-python && npm run build
cd ../vscode-extension && npm run buildTo watch for changes during development:
# In separate terminals:
cd packages/core-engine && npm run watch
cd packages/vscode-extension && npm run watchcd packages/core-engine
npm run cli <workspace-path>
# With a custom config path:
npm run cli <workspace-path> -- --config <custom-config-path>cd packages/core-engine
npm run cli <workspace-path> -- --server --port 3000The engine will listen on http://localhost:3000 and expose a REST API consumed by the VS Code extension.
cd packages/core-engine
npm run build
node --inspect-brk dist/cli/index.js <workspace-path>Then attach VS Code's debugger (or Chrome DevTools at chrome://inspect) to the process.
The root .vscode/launch.json includes a Run Extension configuration that builds and launches the extension host. To debug the core engine separately, add a configuration like this to .vscode/launch.json:
{
"name": "Debug Core Engine CLI",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/packages/core-engine/dist/cli/index.js",
"args": ["${workspaceFolder}"],
"preLaunchTask": "build-extension",
"outFiles": ["${workspaceFolder}/packages/core-engine/dist/**/*.js"]
}-
Build the core engine first (the extension bundles a packed tarball):
cd packages/core-engine && npm run build
-
Open the workspace root (
DriftGuard/) in VS Code. -
Press F5 (or run Run Extension from the Run & Debug panel). This launches an Extension Development Host window with DriftGuard loaded.
-
Start the engine server in a separate terminal so the extension can communicate with it:
cd packages/core-engine && npm run cli <your-workspace-path> -- --server --port 3000
-
In the Extension Development Host, open the Command Palette (
Ctrl+Shift+P) and run:DriftGuard: Scan WorkspaceDriftGuard: Scan Current FileDriftGuard: Check Engine StatusDriftGuard: Open Configuration
Tip: The extension uses
driftguard.engineUrl(defaulthttp://localhost:3000) to reach the engine. If the engine is not running, commands will report a connection error.
DriftGuard uses Vitest for unit testing across all packages. Test files live in src/__tests__ directories within each package.
npm testcd packages/core-engine && npm testRuns unit tests only — no external dependencies, completes in under 10 seconds:
npm run test:fastIncludes:
- Core engine unit tests (rules, config) with mocked dependencies
- Language package unit tests (TypeScript rules, analyzer stubs)
Excludes: integration tests, graph client tests, scanner tests, VS Code extension tests.
npm test -- --coverageHTML reports are generated in each package's coverage/ directory.
- Core Engine: GraphClient (mocked neo4j-driver), RuleEngine, ScannerOrchestrator, utility functions
- VS Code Extension: EngineClient, command registration, ArchitectureTreeProvider (mocked VS Code API)
- Language-TypeScript: ImportGraphAnalyzer, CircularDependencyRule, BoundaryViolationRule
- Language-Python: Stub tests for Phase 1 (expanded in Phase 2)
- Neo4j Driver: Manual mock at
packages/core-engine/src/__mocks__/neo4j-driver.tsviavi.mock() - VS Code API: Manual mock at
packages/vscode-extension/src/__mocks__/vscode.ts - Test Utilities: Shared helpers at
packages/core-engine/src/__tests__/utils.ts
The extension is published to the VS Code Marketplace under the CodeMedic publisher.
-
Install the
vscepackaging tool:npm install -g @vscode/vsce
-
Create a publisher account at Azure DevOps if you don't have one.
-
Generate a Personal Access Token (PAT) in Azure DevOps:
- Organization:
All accessible organizations - Scopes:
Marketplace → Manage
- Organization:
-
Log in with
vsce:vsce login CodeMedic # Paste your PAT when prompted
cd packages/vscode-extension
vsce package
# Produces: driftguard-<version>.vsixcd packages/vscode-extension
vsce publish
# To bump the version and publish in one step:
vsce publish patch # or minor / majorcode --install-extension packages/vscode-extension/driftguard-0.1.0.vsix| Package | Description |
|---|---|
core-engine |
Core scanning engine, graph management, CLI, HTTP server |
language-typescript |
TypeScript import graph analyzer and rules |
language-python |
Python analyzer (stub for Phase 1, expanded in Phase 2) |
vscode-extension |
VS Code IDE integration |
- Confirm the engine is running:
curl http://localhost:3000/health - Check
driftguard.engineUrlin VS Code settings or.driftguard/config.json - Ensure the engine built successfully before starting:
cd packages/core-engine && npm run build
- If Memgraph is not installed or not running, the engine falls back to a mock in-memory graph — no action needed for local development.
- To connect a real Memgraph instance, set
MEMGRAPH_URI,MEMGRAPH_USERNAME, andMEMGRAPH_PASSWORDin.env.
- Ensure
packages/vscode-extensionhas been built (npm run build) before pressing F5. - The VS Code launch config uses
--extensionDevelopmentPathpointing topackages/vscode-extension. - Check the Extension Host output panel for errors.
- Try deleting
node_modulesandpackage-lock.jsonin the affected package, then re-runnpm install. - Ensure your Node.js version meets the
>=18.0.0requirement:node --version.
- Run
npm run test:fastfirst to isolate unit test failures from integration issues. - Ensure all packages are built before running tests that depend on compiled output.