Introduction
GuardLink is an open specification and CLI toolset for Continuous Threat Modeling with AI. It solves the "stale threat model" problem by embedding security decisions directly into source code comments using GAL (GuardLink Annotation Language).
WHY GUARDLINK?
- Security knowledge lives where the code is.
- AI Agents maintain the model automatically.
- CI/CD enforces security intent on every PR.
- Language-agnostic and zero runtime cost.
Installation
Install GuardLink globally via npm to use the CLI from any directory. Requires Node.js 18+.
Clone the repo, then npm install && npm run build. Use node dist/cli/index.js or link via npm link.
Add GuardLink to your MCP client config (e.g. Cursor) so AI agents can call guardlink_parse, guardlink_validate, and guardlink_dashboard.
Quick Start
How to Use Guide
1Initialize & Agent Setup
Run guardlink init in your project root. Choose your preferred AI coding agent (Cursor, Claude, etc.). GuardLink will automatically create the necessary agentic configuration files:
2AI-Powered Annotation
Simply instruct your AI agent to "read guardlink gal" to understand the annotation language. Then, sit back and sip your coffee while the agent autonomously scans and annotates your codebase with security intent.

3The GuardLink Toolchain
Once the AI has finished annotating, run the core toolchain to process your threat model:
guardlink parseExtracts GAL annotations from your source code.
guardlink validateChecks for syntax errors and unmitigated threats.
guardlink reportGenerates a detailed Markdown threat model.
guardlink dashboardLaunches an interactive visualization in your browser.
4Continuous Insights & AI Analysis
Explore your system's security architecture through interactive Data Flow Diagrams and Mermaid diagrams. For a deep dive, use the AI analysis command:
guardlink /analyzeThis triggers a comprehensive AI-powered audit of your threat model, providing a final report on edge cases, architectural weaknesses, and recommended mitigations.
Architecture
GuardLink is a single-binary CLI. User input (CLI args, TUI commands, or MCP tool calls) flows into the parser; the resulting ThreatModel is consumed by report, dashboard, SARIF, and diff. Definitions live in .guardlink/definitions.ts; the rest of the codebase uses relationship verbs only.
Loading diagram…
Entry points. CLI and TUI read project dir; MCP exposes tools (parse, validate, dashboard, etc.) over stdio.
Scans source files, strips comments, extracts GAL lines, resolves #id refs against definitions, outputs ThreatModel JSON.
Consume ThreatModel to produce markdown, HTML dashboard, SARIF 2.1.0, or git-diff of threat changes.
Codebase Overview
The GuardLink CLI codebase is organized by capability. Definitions for assets, threats, and controls live in .guardlink/definitions.ts; all other modules reference them by #id. Key directories:
The project is annotated with GuardLink itself: .guardlink/definitions.ts declares assets (e.g. #parser, #dashboard, #mcp), threats (#xss, #path-traversal), and controls (#output-encoding, #path-validation). Source files use @exposes, @mitigates, @flows, and @comment to document the threat model. Run guardlink dashboard . in the repo to see the generated threat-model dashboard.
GAL Specification
GAL is a structured grammar designed to be both human-readable and machine-parsable. All annotations follow a standard pattern:
Definition Verbs
Used to declare the building blocks of your threat model.
@asset<path> (#id)Declares a component, service, or resource.
@threat<name> (#id) [severity]Names a threat or vulnerability class.
@control<name> (#id)Names a security defense mechanism.
Relationship Verbs
Connects assets, threats, and controls into a graph.
@mitigates<asset> against <threat> [using <control>]Declares a defense against a threat.
@exposes<asset> to <threat> [severity] [external-refs]Declares a known vulnerability or weakness.
@accepts<threat> on <asset>Acknowledges and accepts a known risk.
@transfers<threat> from <source> to <target>Delegates risk responsibility to another component or external service.
@flows<source> -> <target> [via <mechanism>]Describes data flow between components.
@boundarybetween <asset-a> and <asset-b> [(#id)]Declares a trust boundary between two components. Also supports pipe syntax: asset-a | asset-b.
Lifecycle Verbs
Track validation, ownership, audits, and security assumptions over time.
@validates<control> for <asset>Declares that a test verifies a security control is working.
@audit<asset>Flags a component for security review.
@owns<owner> for <asset>Assigns security ownership of a component to a team, role, or individual.
@handles<classification> on <asset>Classifies the type of sensitive data a component processes. Classifications: pii, phi, financial, secrets, internal, public.
@assumes<asset>Documents a security assumption that the code relies on.
Comment & Special Verbs
Developer notes and AI exclusion markers.
@comment[-- "<description>"]Adds a security-relevant developer note to the threat model.
@shield[-- "<reason>"]Excludes code from AI agent context. Use @shield for a single function, or @shield:begin / @shield:end for a block range.
Parsing & Output
The guardlink parse command recursively scans every source file in your project, extracts all GAL annotations from comments, and assembles them into a structured Threat Model. It supports 30+ comment syntaxes across all major languages.
How Parsing Works
From source code annotations to a structured threat model in seconds.
Recursively walks every source file, detecting comment syntax per language.
Parses each annotation line — resolves IDs, normalizes names, validates severity and external refs.
Combines all annotations into a single threat model graph with full cross-referencing.
Output Structure
The parsed threat model is a JSON object containing every relationship in your codebase.
Supported Comment Syntaxes
GAL annotations work in any language — the parser detects the comment prefix automatically.
//JS, TS, Go, Rust, Java, C#Python, Ruby, Shell, YAML--SQL, Lua, Haskell/* */CSS, C, Java(* *)OCaml, Pascal""" """Python docstrings%LaTeX, Erlang;Lisp, Clojure, INI<!-- -->HTML, XML, Markdown{- -}HaskellREMBatch'VB, VBAReports & Diagrams
GuardLink generates three output formats — a Markdown report with embedded Mermaid diagrams, a machine-readable JSON file, and an interactive HTML dashboard. Together, they produce 4 distinct diagram types that visualize your threat model from different angles.
Output Formats
Three formats for different audiences — developers, tools, and stakeholders.
guardlink reportGenerates threat-model.md — a complete threat model with executive summary, risk tables, data flow tables, and an embedded Mermaid diagram.
guardlink report --jsonGenerates threat-model.json — machine-readable structured data for CI/CD pipelines, custom tooling, or SIEM integration.
guardlink dashboardGenerates threat-dashboard.html — a self-contained interactive dashboard with dark/light themes, filterable tables, and live Mermaid diagrams.
Markdown Report Sections
What's inside the generated threat-model.md file.
High-level metrics — asset count, threat count, controls, mitigations, coverage percentage.
Embedded Mermaid diagram showing assets, threats, data flows, and trust boundaries.
Table of open vulnerabilities sorted by severity — your immediate action items.
Risks acknowledged via @accepts with rationale for each acceptance.
Table showing which controls defend which assets against which threats.
All @flows annotations — source, target, and transport mechanism.
Per-asset breakdown of PII, PHI, financial, secrets, internal, and public data.
Security assumptions for review and components flagged for audit.
Dashboard Pages
The interactive HTML dashboard includes 7 navigable pages.
Key metrics, risk grade (A–F), coverage bar chart, severity breakdown, top exposed assets.
Displays saved AI analysis results from guardlink analyze — STRIDE, DREAD, or PASTA frameworks.
Open exposures (red), mitigated (green), accepted (blue) — with interactive drill-down drawers.
All 3 interactive Mermaid diagrams rendered live — threat graph, data flow, and attack surface.
File browser with collapsible source listings — view annotations grouped by file with line numbers.
Data handling classifications per asset and trust boundary definitions.
Risk level per asset — exposure counts, mitigation counts, data flow participation, and classifications.
Sample Dashboard HTML
The generated threat-dashboard.html is self-contained: one file with embedded CSS, data, and Mermaid. Layout: top nav (project name, stats, theme toggle), sidebar (7 pages), main content, and a slide-out drawer for exposure/asset details.
Run guardlink dashboard [dir] to generate this file. Open it in a browser; all data is embedded, so it works offline. Diagrams use Mermaid.js from CDN.
Diagram Types
GuardLink auto-generates 4 distinct Mermaid diagram types from your annotations. Each diagram visualizes a different dimension of your threat model.
1. Data Flow Diagram
Generated from @flows and @boundary annotations. Shows how data moves between components.
Loading diagram…
NODE SHAPES
[("name")] Data stores (db, cache, file)(("name")) External actors (browser, user)["name"] Processes (api, service)2. Threat Model Graph
Generated from @exposes, @mitigates, and @control annotations. Maps the relationship between assets, threats, and defenses.
Loading diagram…
EDGE TYPES
3. Attack Surface Map
Generated from @exposes annotations. Groups all vulnerabilities by asset, colored by severity, with mitigation status.
Loading diagram…
STATUS ICONS
4. Report Architecture Diagram
Generated in the Markdown report. A top-down architecture view emphasizing data security, with smart node shapes and threat markers.
Loading diagram…
SMART NODE DETECTION
Node shapes are auto-detected from asset names using pattern matching:
[("...")] Cylinder — names containing: db, database, store, cache, file, credential, config, secret, storage(("...")) Circle — names containing: user, browser, client, external, attacker["..."] Rectangle — everything else (services, APIs, modules)Diagram Coverage Matrix
| Diagram | Annotations Used | Available In | Layout |
|---|---|---|---|
| Data Flow | @flows, @boundary, @handles | Dashboard + Report | LR |
| Threat Graph | @exposes, @mitigates, @control | Dashboard | LR |
| Attack Surface | @exposes, @mitigates, @accepts | Dashboard | LR + TB |
| Architecture | @asset, @flows, @boundary, @exposes, @handles | Report | TD |
AI & MCP Integration
GuardLink is "AI-native". It exposes an MCP (Model Context Protocol) server that allows AI coding agents to read your threat model and suggest annotations in real-time.
Automated Maintenance
When your AI agent writes a new route, it automatically adds @exposes and @mitigates annotations based on the project's security policy.
@shield Enforcement
Use the @shield annotation to exclude sensitive cryptographic or proprietary logic from AI processing entirely.
CI/CD Pipelines
Threat modeling is only effective if enforced. GuardLink integrates into your CI pipeline to block regressions.
GUARDLINK DIFF
Compares threat models between Git refs
Open Source & Contributing
GuardLink is open source and community-driven. We believe that security standards should be transparent and accessible to everyone.