# gmax-13/guard-gate architecture

> Architecture diagram of the GitHub repository gmax-13/guard-gate, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gmax-13/guard-gate
- Repository: https://github.com/gmax-13/guard-gate

## Overview

#### Purpose and Top-Level Entry Points
GuardGate is a pnpm monorepo for CI/CD security scanning plus a report dashboard. The CLI runs code, API, browser/E2E, dependency, and secrets scans; it emits console, JSON, and SARIF artifacts. The dashboard ingests JSON reports through authenticated APIs and presents runs/trends/settings.
- `packages/cli/src/index.ts`
- `apps/dashboard/src/app/page.tsx`
- `packages/github-action/action.yml`

#### CLI Orchestration and Configuration
The CLI is the main execution boundary: it resolves commands, loads/validates GuardGate configuration, selects scan modules, aggregates findings, applies baseline filtering, determines exit behavior, and delegates output serialization.
- `packages/cli/src/index.ts`
- `packages/cli/src/config/loader.ts`
- `packages/cli/src/config/schema.ts`

Repository/project configuration controls scanner targets, rules, API fuzzing, and browser workflows. Example inputs establish the expected user-authored extension model.
- `guardgate.config.yml`
- `examples/guardgate.config.yml`
- `examples/flows/login-flow.yml`

#### Scanner Pipeline
Each scanner produces a common report/finding representation consumed by formatters and the dashboard. The principal scanning stages are:
1. Semantic source analysis using TypeScript AST and JavaScript rule plugins.
2. API DAST: parse endpoint definitions, generate/run fuzz cases, and evaluate response matching.
3. Playwright-driven E2E flows with pluggable auth/session/IDOR checks.
4. SBOM generation from ecosystem manifests followed by OSV vulnerability matching.
5. Repository and Git-history secrets detection.
- `packages/cli/src/types/report.ts`
- `packages/cli/src/types/scanner.ts`
- `packages/cli/src/scanners/code/index.ts`

#### Code and Secrets Analysis Boundaries
The code scanner separates AST traversal from executable/custom rule definitions, allowing semantic rules beyond regex matching. Secrets scanning separates working-tree files, history, entropy/rule heuristics, and explicit allowlists; Git access is isolated in utilities.
- `packages/cli/src/scanners/code/ast-parser.ts`
- `packages/cli/src/scanners/code/rules.ts`
- `packages/cli/src/scanners/secrets/index.ts`
- `packages/cli/src/utils/git.ts`

#### Dynamic and Browser Security Testing
API scanning treats parser, runner, and endpoint payload logic as distinct layers. Browser security testing parses YAML flows into typed execution context, then invokes registered plugins for common authentication/session vulnerabilities. These stages interact with user-supplied target services and require runtime network/browser access.
- `packages/cli/src/scanners/api/parser.ts`
- `packages/cli/src/scanners/api/runner.ts`
- `packages/cli/src/scanners/e2e/flow-runner.ts`
- `packages/cli/src/scanners/e2e/plugin-registry.ts`

#### Reports, CI, and External Services
Scan results are formatted for humans or persisted under `.guardgate`; JSON is the dashboard ingestion contract, while SARIF integrates with GitHub/GitLab security UIs. Baseline logic compares findings against a Git revision to suppress existing debt. Dependency scanning calls the OSV vulnerability service. GitHub Actions can execute scans, upload SARIF, and POST reports to a hosted dashboard using an API key.
- `packages/cli/src/report/json-writer.ts`
- `packages/cli/src/report/sarif-writer.ts`
- `packages/cli/src/utils/baseline.ts`
- `.github/workflows/guardgate.yml`

#### Dashboard Application and Persistence
The dashboard is a Next.js application with auth routes/middleware, report ingestion/detail APIs, and trends/settings views. Its database adapter/schema and Drizzle migration define the persistence boundary for users, API keys, reports, and dashboard-derived views. It is intended for Vercel-hosted deployment, with CI clients posting reports over HTTP bearer authentication.
- `apps/dashboard/src/middleware.ts`
- `apps/dashboard/src/app/api/reports/route.ts`
- `apps/dashboard/src/lib/schema.ts`
- `apps/dashboard/drizzle/0000_lame_xorn.sql`

Main entry points: [`packages/cli/src/index.ts`](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/index.ts) (CLI entry), [`packages/cli/src/types/report.ts`](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/types/report.ts) (Common report model), [`apps/dashboard/src/app/api/reports/route.ts`](https://github.com/gmax-13/guard-gate/blob/main/apps/dashboard/src/app/api/reports/route.ts) (Report ingestion API), [`packages/github-action/action.yml`](https://github.com/gmax-13/guard-gate/blob/main/packages/github-action/action.yml) (GitHub Action)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["GuardGate CLI"]
  node_cli_entry["CLI entry<br/>command<br/>[index.ts]"]
  node_config["Config loader &amp; schema<br/>configuration<br/>[loader.ts]"]
  node_report_model["Common report model<br/>contract<br/>[report.ts]"]
  node_baseline["Baseline filter<br/>[baseline.ts]"]
  node_json_writer["JSON reports<br/>serializer<br/>[json-writer.ts]"]
  node_sarif_writer["SARIF reports<br/>serializer<br/>[sarif-writer.ts]"]
end

subgraph group_scanners["Scan engines"]
  node_code_scanner["Code scanner<br/>[index.ts]"]
  node_ast_parser["AST traversal<br/>analysis layer<br/>[ast-parser.ts]"]
  node_api_scanner["API DAST runner<br/>scanner<br/>[runner.ts]"]
  node_e2e_runner["E2E flow runner<br/>scanner<br/>[flow-runner.ts]"]
  node_e2e_plugins["E2E security plugins<br/>plugin registry<br/>[plugin-registry.ts]"]
  node_dependency_scanner["Dependency &amp; OSV scan<br/>scanner"]
  node_secrets_scanner["Secrets scanner<br/>[index.ts]"]
end

subgraph group_dashboard["Dashboard"]
  node_dashboard_api["Report ingestion API<br/>authenticated API<br/>[route.ts]"]
  node_dashboard_ui["Dashboard UI<br/>Next.js application<br/>[page.tsx]"]
  node_dashboard_auth["Auth middleware<br/>authentication<br/>[middleware.ts]"]
  node_dashboard_db[("Dashboard database<br/>Drizzle persistence<br/>[schema.ts]")]
end

node_project_config["User scan config<br/>user input"]
node_osv{{"OSV service<br/>external vulnerability API"}}
node_github_action["GitHub Action<br/>CI integration<br/>[action.yml]"]

node_project_config -->|"loaded and validated"| node_config
node_config -->|"scan settings"| node_cli_entry
node_cli_entry -->|"selects"| node_code_scanner
node_cli_entry -->|"selects"| node_api_scanner
node_cli_entry -->|"selects"| node_e2e_runner
node_cli_entry -->|"selects"| node_dependency_scanner
node_cli_entry -->|"selects"| node_secrets_scanner
node_ast_parser -->|"semantic input"| node_code_scanner
node_e2e_plugins -->|"security checks"| node_e2e_runner
node_osv -->|"vulnerability matches"| node_dependency_scanner
node_code_scanner -->|"findings"| node_report_model
node_api_scanner -->|"findings"| node_report_model
node_e2e_runner -->|"findings"| node_report_model
node_dependency_scanner -->|"findings"| node_report_model
node_secrets_scanner -->|"findings"| node_report_model
node_report_model -->|"aggregated findings"| node_baseline
node_baseline -->|"filtered report"| node_json_writer
node_baseline -->|"filtered report"| node_sarif_writer
node_github_action -->|"executes"| node_cli_entry
node_github_action -->|"uploads artifact"| node_sarif_writer
node_json_writer -->|"JSON report"| node_dashboard_api
node_github_action -->|"posts with API key"| node_dashboard_api
node_dashboard_auth -->|"protects"| node_dashboard_api
node_dashboard_api -->|"persists reports"| node_dashboard_db
node_dashboard_ui -->|"reads runs and trends"| node_dashboard_db

click node_cli_entry "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/index.ts"
click node_config "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/config/loader.ts"
click node_project_config "https://github.com/gmax-13/guard-gate/blob/main/guardgate.config.yml"
click node_report_model "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/types/report.ts"
click node_baseline "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/utils/baseline.ts"
click node_json_writer "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/report/json-writer.ts"
click node_sarif_writer "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/report/sarif-writer.ts"
click node_code_scanner "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/code/index.ts"
click node_ast_parser "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/code/ast-parser.ts"
click node_api_scanner "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/api/runner.ts"
click node_e2e_runner "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/e2e/flow-runner.ts"
click node_e2e_plugins "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/e2e/plugin-registry.ts"
click node_secrets_scanner "https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/secrets/index.ts"
click node_github_action "https://github.com/gmax-13/guard-gate/blob/main/packages/github-action/action.yml"
click node_dashboard_api "https://github.com/gmax-13/guard-gate/blob/main/apps/dashboard/src/app/api/reports/route.ts"
click node_dashboard_ui "https://github.com/gmax-13/guard-gate/blob/main/apps/dashboard/src/app/page.tsx"
click node_dashboard_auth "https://github.com/gmax-13/guard-gate/blob/main/apps/dashboard/src/middleware.ts"
click node_dashboard_db "https://github.com/gmax-13/guard-gate/blob/main/apps/dashboard/src/lib/schema.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli_entry,node_config,node_report_model,node_baseline,node_json_writer,node_sarif_writer toneBlue
class node_code_scanner,node_ast_parser,node_api_scanner,node_e2e_runner,node_e2e_plugins,node_dependency_scanner,node_secrets_scanner toneAmber
class node_dashboard_api,node_dashboard_ui,node_dashboard_auth,node_dashboard_db toneMint
class node_project_config,node_osv,node_github_action toneNeutral
```

## Components

### GuardGate CLI

Scan orchestration and local artifacts.

- [CLI entry](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/index.ts): command · Resolves commands and coordinates scans. · `packages/cli/src/index.ts`
- [Config loader & schema](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/config/loader.ts): configuration · Loads and validates scan targets, rules, and workflows. · `packages/cli/src/config/loader.ts`
- [Common report model](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/types/report.ts): contract · Shared finding and scanner result representation. · `packages/cli/src/types/report.ts`
- [Baseline filter](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/utils/baseline.ts): filter · Suppresses findings already present at a Git revision. · `packages/cli/src/utils/baseline.ts`
- [JSON reports](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/report/json-writer.ts): serializer · Dashboard ingestion contract persisted under .guardgate. · `packages/cli/src/report/json-writer.ts`
- [SARIF reports](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/report/sarif-writer.ts): serializer · Security UI artifact output. · `packages/cli/src/report/sarif-writer.ts`

### Scan engines

Security analysis stages sharing a report model.

- [Code scanner](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/code/index.ts): scanner · Semantic source analysis using AST rules. · `packages/cli/src/scanners/code/index.ts`
- [AST traversal](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/code/ast-parser.ts): analysis layer · Parses TypeScript and JavaScript source. · `packages/cli/src/scanners/code/ast-parser.ts`
- [API DAST runner](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/api/runner.ts): scanner · Runs generated fuzz cases and evaluates responses. · `packages/cli/src/scanners/api/runner.ts`
- [E2E flow runner](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/e2e/flow-runner.ts): scanner · Executes browser flows against target services. · `packages/cli/src/scanners/e2e/flow-runner.ts`
- [E2E security plugins](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/e2e/plugin-registry.ts): plugin registry · Registers auth, session, and IDOR checks. · `packages/cli/src/scanners/e2e/plugin-registry.ts`
- **Dependency & OSV scan**: scanner · Builds an SBOM and matches vulnerabilities.
- [Secrets scanner](https://github.com/gmax-13/guard-gate/blob/main/packages/cli/src/scanners/secrets/index.ts): scanner · Scans working tree and Git history with heuristics and allowlists. · `packages/cli/src/scanners/secrets/index.ts`

### Dashboard

Authenticated report ingestion and reporting UI.

- [Report ingestion API](https://github.com/gmax-13/guard-gate/blob/main/apps/dashboard/src/app/api/reports/route.ts): authenticated API · Accepts posted JSON reports with bearer authentication. · `apps/dashboard/src/app/api/reports/route.ts`
- [Dashboard UI](https://github.com/gmax-13/guard-gate/blob/main/apps/dashboard/src/app/page.tsx): Next.js application · Presents runs, trends, and settings. · `apps/dashboard/src/app/page.tsx`
- [Auth middleware](https://github.com/gmax-13/guard-gate/blob/main/apps/dashboard/src/middleware.ts): authentication · Protects dashboard routes. · `apps/dashboard/src/middleware.ts`
- [Dashboard database](https://github.com/gmax-13/guard-gate/blob/main/apps/dashboard/src/lib/schema.ts): Drizzle persistence · Stores users, API keys, reports, and derived views. · `apps/dashboard/src/lib/schema.ts`

### Other components

- [User scan config](https://github.com/gmax-13/guard-gate/blob/main/guardgate.config.yml): user input · Repository-authored scan configuration and flow inputs. · `guardgate.config.yml`
- **OSV service**: external vulnerability API
- [GitHub Action](https://github.com/gmax-13/guard-gate/blob/main/packages/github-action/action.yml): CI integration · Runs scans, uploads SARIF, and posts JSON reports. · `packages/github-action/action.yml`

## Connections

- User scan config → Config loader & schema: loaded and validated
- Config loader & schema → CLI entry: scan settings
- CLI entry → Code scanner: selects
- CLI entry → API DAST runner: selects
- CLI entry → E2E flow runner: selects
- CLI entry → Dependency & OSV scan: selects
- CLI entry → Secrets scanner: selects
- AST traversal → Code scanner: semantic input
- E2E security plugins → E2E flow runner: security checks
- OSV service → Dependency & OSV scan: vulnerability matches
- Code scanner → Common report model: findings
- API DAST runner → Common report model: findings
- E2E flow runner → Common report model: findings
- Dependency & OSV scan → Common report model: findings
- Secrets scanner → Common report model: findings
- Common report model → Baseline filter: aggregated findings
- Baseline filter → JSON reports: filtered report
- Baseline filter → SARIF reports: filtered report
- GitHub Action → CLI entry: executes
- GitHub Action → SARIF reports: uploads artifact
- JSON reports → Report ingestion API: JSON report
- GitHub Action → Report ingestion API: posts with API key
- Auth middleware → Report ingestion API: protects
- Report ingestion API → Dashboard database: persists reports
- Dashboard UI → Dashboard database: reads runs and trends
