# dembrandt/dembrandt architecture

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

- Interactive diagram: https://gitdiagram.com/dembrandt/dembrandt
- Repository: https://github.com/dembrandt/dembrandt

## Overview

#### Purpose and Entry Points
Dembrandt is a Node.js 18+ CLI/library that drives Chromium via Playwright to extract a website’s observed design system into normalized tokens, reports, and CI drift results. Main executable orchestration is `index.ts`; MCP stdio integration is `mcp-server.ts`; GitHub Action packaging is `action.yml`. Browser installation is handled by `lib/install-browser.ts`.

#### Browser Acquisition and Site Discovery
Extraction begins by validating URL/options, locating or connecting to a Chromium instance, respecting robots policy, and optionally discovering/crawling additional pages or sitemap paths. Browser-facing logic and crawl/discovery boundaries are in `lib/browser.ts`, `lib/discovery.ts`, and `lib/robots.ts`. This is the external-network and untrusted-page boundary; authenticated headers, user agent, CDP/browser selection, viewport, dark mode, and sandbox settings enter here.

#### DOM Extraction Pipeline
Playwright-rendered pages are inspected for computed styles, CSS rules, DOM structure, assets, and interaction-related evidence. Specialized extractors produce raw observations for colors, typography, spacing, breakpoints, components, logos, consent UI, menus, motion-related styling, and page context. The extraction stage is organized under `lib/extractors/index.ts`, `lib/extractors/colors.ts`, and `lib/extractors/typography.ts`, with the broader extractor family in `lib/extractors/`.

#### Normalization, Inference, and Aggregation
Raw page observations are transformed into stable token-oriented output: color parsing/semantic heuristics, grouping, confidence assessment, cross-page merging, and type normalization. Core aggregation boundaries are `lib/normalize.ts`, `lib/merger.ts`, and `lib/types.ts`. ML-assisted classification is shipped locally as ONNX/runtime assets in `lib/ml/model.onnx`, `lib/ml/runtime.js`, and `lib/ml/meta.json`; it does not require a remote ML service.

#### Quality Findings and Drift Enforcement
The system evaluates extracted output for consistency and accessibility findings, then compares it with a committed or supplied baseline to produce token-level changes and process exit status. This supports generic CI as well as PR annotations. Key modules are `lib/findings.ts`, `lib/compare.ts`, `lib/drift.ts`, and `lib/ci-annotations.ts`; exit-contract behavior is centralized in `lib/exit-codes.ts`. GitHub Action execution uses `action.yml`.

#### Output and Interchange Formats
A normalized extraction can be rendered for terminal use, JSON persistence, W3C DTCG consumers, Markdown/DESIGN.md, HTML/PDF brand guides, Tailwind v4 themes, and theme artifacts. Format adapters are isolated in `lib/formatters/dtcg.ts`, `lib/formatters/tailwind.ts`, and `lib/formatters/terminal.ts`; DTCG validation is in `lib/dtcg/validate.ts`. This keeps extraction independent from downstream presentation and design-tool targets.

#### MCP Job-Oriented API
The MCP server exposes extraction and pure post-processing tools to compatible AI clients. Extraction returns a job identifier; later status, findings, drift, DTCG export, and report calls operate against retained job state rather than retransmitted extraction payloads. The protocol entry point is `mcp-server.ts`, with job lifecycle/state in `lib/mcp/jobs.ts` and option translation in `lib/mcp/options.ts`.

#### Runtime and External Integrations
The deployed runtime is Node.js/TypeScript with `playwright-core` and a separately installed shared Chromium cache. It accesses target websites, their CSS/font/assets, optional sitemaps, and GitHub Actions annotation facilities. Optional cloud snapshot upload/API-key behavior is CLI-facing; the repository’s core local extraction and comparison path remains file/terminal/MCP based.

Main entry points: [`lib/merger.ts`](https://github.com/dembrandt/dembrandt/blob/main/lib/merger.ts) (Cross-page merger), [`lib/browser.ts`](https://github.com/dembrandt/dembrandt/blob/main/lib/browser.ts) (Browser access), [`lib/mcp/jobs.ts`](https://github.com/dembrandt/dembrandt/blob/main/lib/mcp/jobs.ts) (Retained jobs), [`lib/normalize.ts`](https://github.com/dembrandt/dembrandt/blob/main/lib/normalize.ts) (Normalization & inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entrypoints"]
  node_cli["CLI orchestration<br/>Node.js CLI<br/>[index.ts]"]
  node_action["GitHub Action<br/>Action package<br/>[action.yml]"]
end

subgraph group_browser["Browser &amp; Discovery"]
  node_browser_install["Chromium installer<br/>browser setup<br/>[install-browser.ts]"]
  node_browser_access["Browser access<br/>Playwright boundary<br/>[browser.ts]"]
  node_robots["Robots policy<br/>crawl policy<br/>[robots.ts]"]
  node_discovery["Page discovery<br/>crawler<br/>[discovery.ts]"]
  node_website{{"Target websites<br/>external web"}}
end

subgraph group_pipeline["Extraction Pipeline"]
  node_extractors["DOM extractors<br/>raw observation pipeline<br/>[index.ts]"]
  node_colors["Color extraction<br/>extractor<br/>[colors.ts]"]
  node_typography["Typography extraction<br/>extractor<br/>[typography.ts]"]
  node_normalization["Normalization &amp; inference<br/>token normalization<br/>[normalize.ts]"]
  node_ml_model["Local ML classifier<br/>ONNX runtime<br/>[model.onnx]"]
  node_merger["Cross-page merger<br/>aggregation<br/>[merger.ts]"]
  node_token_types["Token types<br/>shared schema<br/>[types.ts]"]
end

subgraph group_quality["Quality &amp; Outputs"]
  node_findings["Quality findings<br/>consistency &amp; accessibility<br/>[findings.ts]"]
  node_drift["Baseline drift<br/>comparison &amp; enforcement<br/>[drift.ts]"]
  node_formatters["Format adapters<br/>renderers<br/>[dtcg.ts]"]
end

subgraph group_mcp["MCP API"]
  node_mcp_server["MCP stdio server<br/>MCP protocol<br/>[mcp-server.ts]"]
  node_jobs[("Retained jobs<br/>job state<br/>[jobs.ts]")]
  node_mcp_options["MCP options<br/>option translation<br/>[options.ts]"]
end

node_action -->|"runs"| node_cli
node_cli -->|"ensures browser"| node_browser_install
node_cli -->|"starts extraction"| node_browser_access
node_mcp_server -->|"translates options"| node_mcp_options
node_mcp_options -->|"invokes extraction"| node_browser_access
node_mcp_server -->|"creates and queries"| node_jobs
node_browser_access -->|"loads"| node_website
node_browser_access -->|"checks policy"| node_robots
node_robots -->|"permits crawl"| node_discovery
node_website -->|"pages and sitemaps"| node_discovery
node_discovery -->|"rendered pages"| node_extractors
node_browser_access -->|"single-page render"| node_extractors
node_extractors -->|"specializes"| node_colors
node_extractors -->|"specializes"| node_typography
node_colors -->|"raw observations"| node_normalization
node_typography -->|"raw observations"| node_normalization
node_ml_model -->|"assists classification"| node_normalization
node_normalization -->|"normalized pages"| node_merger
node_token_types -->|"defines output"| node_normalization
node_merger -->|"design system"| node_findings
node_merger -->|"tokens"| node_drift
node_merger -->|"normalized extraction"| node_formatters
node_drift -->|"CI result"| node_action
node_merger -->|"stores result"| node_jobs
node_jobs -->|"export/report requests"| node_formatters
node_jobs -->|"post-processes"| node_findings
node_jobs -->|"compares retained result"| node_drift

click node_cli "https://github.com/dembrandt/dembrandt/blob/main/index.ts"
click node_action "https://github.com/dembrandt/dembrandt/blob/main/action.yml"
click node_mcp_server "https://github.com/dembrandt/dembrandt/blob/main/mcp-server.ts"
click node_browser_install "https://github.com/dembrandt/dembrandt/blob/main/lib/install-browser.ts"
click node_browser_access "https://github.com/dembrandt/dembrandt/blob/main/lib/browser.ts"
click node_robots "https://github.com/dembrandt/dembrandt/blob/main/lib/robots.ts"
click node_discovery "https://github.com/dembrandt/dembrandt/blob/main/lib/discovery.ts"
click node_extractors "https://github.com/dembrandt/dembrandt/blob/main/lib/extractors/index.ts"
click node_colors "https://github.com/dembrandt/dembrandt/blob/main/lib/extractors/colors.ts"
click node_typography "https://github.com/dembrandt/dembrandt/blob/main/lib/extractors/typography.ts"
click node_normalization "https://github.com/dembrandt/dembrandt/blob/main/lib/normalize.ts"
click node_ml_model "https://github.com/dembrandt/dembrandt/blob/main/lib/ml/model.onnx"
click node_merger "https://github.com/dembrandt/dembrandt/blob/main/lib/merger.ts"
click node_token_types "https://github.com/dembrandt/dembrandt/blob/main/lib/types.ts"
click node_findings "https://github.com/dembrandt/dembrandt/blob/main/lib/findings.ts"
click node_drift "https://github.com/dembrandt/dembrandt/blob/main/lib/drift.ts"
click node_formatters "https://github.com/dembrandt/dembrandt/blob/main/lib/formatters/dtcg.ts"
click node_jobs "https://github.com/dembrandt/dembrandt/blob/main/lib/mcp/jobs.ts"
click node_mcp_options "https://github.com/dembrandt/dembrandt/blob/main/lib/mcp/options.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,node_action toneBlue
class node_browser_install,node_browser_access,node_robots,node_discovery,node_website toneAmber
class node_extractors,node_colors,node_typography,node_normalization,node_ml_model,node_merger,node_token_types toneMint
class node_findings,node_drift,node_formatters toneRose
class node_mcp_server,node_jobs,node_mcp_options toneIndigo
```

## Components

### Entrypoints

- [CLI orchestration](https://github.com/dembrandt/dembrandt/blob/main/index.ts): Node.js CLI · `index.ts`
- [GitHub Action](https://github.com/dembrandt/dembrandt/blob/main/action.yml): Action package · `action.yml`

### Browser & Discovery

External-network and untrusted-page boundary.

- [Chromium installer](https://github.com/dembrandt/dembrandt/blob/main/lib/install-browser.ts): browser setup · Installs the shared Chromium cache. · `lib/install-browser.ts`
- [Browser access](https://github.com/dembrandt/dembrandt/blob/main/lib/browser.ts): Playwright boundary · Selects or connects Chromium and applies browser options. · `lib/browser.ts`
- [Robots policy](https://github.com/dembrandt/dembrandt/blob/main/lib/robots.ts): crawl policy · `lib/robots.ts`
- [Page discovery](https://github.com/dembrandt/dembrandt/blob/main/lib/discovery.ts): crawler · Discovers pages and sitemap paths. · `lib/discovery.ts`
- **Target websites**: external web · Pages, CSS, fonts, assets, and optional sitemaps.

### Extraction Pipeline

- [DOM extractors](https://github.com/dembrandt/dembrandt/blob/main/lib/extractors/index.ts): raw observation pipeline · Inspects rendered DOM, styles, rules, assets, and interaction evidence. · `lib/extractors/index.ts`
- [Color extraction](https://github.com/dembrandt/dembrandt/blob/main/lib/extractors/colors.ts): extractor · `lib/extractors/colors.ts`
- [Typography extraction](https://github.com/dembrandt/dembrandt/blob/main/lib/extractors/typography.ts): extractor · `lib/extractors/typography.ts`
- [Normalization & inference](https://github.com/dembrandt/dembrandt/blob/main/lib/normalize.ts): token normalization · Applies semantic heuristics, grouping, confidence, and type normalization. · `lib/normalize.ts`
- [Local ML classifier](https://github.com/dembrandt/dembrandt/blob/main/lib/ml/model.onnx): ONNX runtime · Local assets; no remote ML service. · `lib/ml/model.onnx`
- [Cross-page merger](https://github.com/dembrandt/dembrandt/blob/main/lib/merger.ts): aggregation · `lib/merger.ts`
- [Token types](https://github.com/dembrandt/dembrandt/blob/main/lib/types.ts): shared schema · `lib/types.ts`

### Quality & Outputs

- [Quality findings](https://github.com/dembrandt/dembrandt/blob/main/lib/findings.ts): consistency & accessibility · `lib/findings.ts`
- [Baseline drift](https://github.com/dembrandt/dembrandt/blob/main/lib/drift.ts): comparison & enforcement · Produces token changes and CI outcome. · `lib/drift.ts`
- [Format adapters](https://github.com/dembrandt/dembrandt/blob/main/lib/formatters/dtcg.ts): renderers · Terminal, JSON, DTCG, reports, Tailwind, and theme artifacts. · `lib/formatters/dtcg.ts`

### MCP API

- [MCP stdio server](https://github.com/dembrandt/dembrandt/blob/main/mcp-server.ts): MCP protocol · `mcp-server.ts`
- [Retained jobs](https://github.com/dembrandt/dembrandt/blob/main/lib/mcp/jobs.ts): job state · Post-processing operates on stored extraction results. · `lib/mcp/jobs.ts`
- [MCP options](https://github.com/dembrandt/dembrandt/blob/main/lib/mcp/options.ts): option translation · `lib/mcp/options.ts`

## Connections

- GitHub Action → CLI orchestration: runs
- CLI orchestration → Chromium installer: ensures browser
- CLI orchestration → Browser access: starts extraction
- MCP stdio server → MCP options: translates options
- MCP options → Browser access: invokes extraction
- MCP stdio server → Retained jobs: creates and queries
- Browser access → Target websites: loads
- Browser access → Robots policy: checks policy
- Robots policy → Page discovery: permits crawl
- Target websites → Page discovery: pages and sitemaps
- Page discovery → DOM extractors: rendered pages
- Browser access → DOM extractors: single-page render
- DOM extractors → Color extraction: specializes
- DOM extractors → Typography extraction: specializes
- Color extraction → Normalization & inference: raw observations
- Typography extraction → Normalization & inference: raw observations
- Local ML classifier → Normalization & inference: assists classification
- Normalization & inference → Cross-page merger: normalized pages
- Token types → Normalization & inference: defines output
- Cross-page merger → Quality findings: design system
- Cross-page merger → Baseline drift: tokens
- Cross-page merger → Format adapters: normalized extraction
- Baseline drift → GitHub Action: CI result
- Cross-page merger → Retained jobs: stores result
- Retained jobs → Format adapters: export/report requests
- Retained jobs → Quality findings: post-processes
- Retained jobs → Baseline drift: compares retained result
