How dembrandt/dembrandt works
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: merger.ts Cross-page merger · browser.ts Browser access · jobs.ts Retained jobs · normalize.ts Normalization & inference
Components 20
Entrypoints
- CLI orchestration
index.ts - GitHub Action
action.yml
Browser & Discovery
External-network and untrusted-page boundary.
- Chromium installer · Installs the shared Chromium cache.
lib/install-browser.ts - Browser access · Selects or connects Chromium and applies browser options.
lib/browser.ts - Robots policy
lib/robots.ts - Page discovery · Discovers pages and sitemap paths.
lib/discovery.ts - Target websites · Pages, CSS, fonts, assets, and optional sitemaps.
Extraction Pipeline
- DOM extractors · Inspects rendered DOM, styles, rules, assets, and interaction evidence.
lib/extractors/index.ts - Color extraction
lib/extractors/colors.ts - Typography extraction
lib/extractors/typography.ts - Normalization & inference · Applies semantic heuristics, grouping, confidence, and type normalization.
lib/normalize.ts - Local ML classifier · Local assets; no remote ML service.
lib/ml/model.onnx - Cross-page merger
lib/merger.ts - Token types
lib/types.ts
Quality & Outputs
- Quality findings
lib/findings.ts - Baseline drift · Produces token changes and CI outcome.
lib/drift.ts - Format adapters · Terminal, JSON, DTCG, reports, Tailwind, and theme artifacts.
lib/formatters/dtcg.ts
MCP API
- MCP stdio server
mcp-server.ts - Retained jobs · Post-processing operates on stored extraction results.
lib/mcp/jobs.ts - MCP options
lib/mcp/options.ts
Connections 27
- 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