An open API service indexing awesome lists of open source software.

https://github.com/ravidsrk/frontguard

AI-powered frontend visual regression testing. Detect, understand, and fix visual bugs before production.
https://github.com/ravidsrk/frontguard

ai automated-testing cli frontend-testing playwright screenshot-testing testing typescript visual-regression-testing

Last synced: 5 days ago
JSON representation

AI-powered frontend visual regression testing. Detect, understand, and fix visual bugs before production.

Awesome Lists containing this project

README

          

# πŸ›‘οΈ Frontguard

[![CI](https://github.com/ravidsrk/frontguard/actions/workflows/ci.yml/badge.svg)](https://github.com/ravidsrk/frontguard/actions/workflows/ci.yml)
[![npm: @frontguard/cli](https://img.shields.io/npm/v/@frontguard/cli?label=%40frontguard%2Fcli)](https://www.npmjs.com/package/@frontguard/cli)
[![npm: @frontguard/playwright](https://img.shields.io/npm/v/@frontguard/playwright?label=%40frontguard%2Fplaywright)](https://www.npmjs.com/package/@frontguard/playwright)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
[![Tests](https://img.shields.io/badge/tests-1000+-brightgreen)]()

**AI-powered frontend visual regression testing. Detect, understand, and fix visual bugs before production.**

Backend has Datadog, Sentry, PagerDuty β€” a $20B+ monitoring ecosystem. Frontend gets... manual QA and hoping for the best. Frontguard changes that.

> **1000+ tests** Β· **multi-browser** Β· **AI vision analysis** Β· **self-hostable** Β· **MIT**


πŸ“½οΈ Demo: frontguard init β†’ doctor β†’ run β†’ AI classification.

See the VHS tape script β€” render the GIF locally with vhs demo/frontguard-demo.tape.

## Why Frontguard?

- **🧠 AI-powered analysis** β€” Doesn't just say "pixels differ." It classifies the change (regression vs intentional vs content update), explains *why*, and suggests a fix. This kills the #1 pain of visual testing: false positives.
- **🎯 Anti-flake rendering** β€” Multi-render consensus eliminates the flaky-screenshot noise that makes teams disable their visual suites.
- **πŸ”“ Open-source & self-hostable** β€” CLI-first, free forever. No per-screenshot pricing cliff, no dashboard lock-in, BYO AI key.

## What It Does

```
Developer pushes code β†’ Frontguard renders every page β†’ Compares to baselines β†’
AI explains what changed and why β†’ Suggests fixes β†’ Posts PR comment
```

- **Detect** β€” Pixel diff + DOM diff catches what humans miss
- **Understand** β€” AI explains *why* something broke, not just "pixels differ"
- **Fix** β€” Verified code fixes, re-rendered to confirm they work (Phase 2)

## Quick Start

**Prerequisites:** [Node.js](https://nodejs.org/) 20+ and npm 9+

```bash
# Install
npm install @frontguard/cli

# Initialize config (auto-detects your framework, --ci adds a GitHub Action)
npx frontguard init --ci

# Verify your environment is ready
npx frontguard doctor

# Run visual regression tests
npx frontguard run --url http://localhost:3000

# Accept current screenshots as new baselines
npx frontguard update-baselines
```

> **Full documentation:** [frontguard.dev](https://frontguard.dev) Β· [`docs/`](./docs/) folder

## Features

- **Zero-config route discovery** β€” Auto-crawls your app to find all pages
- **Multi-browser** β€” Chromium, Firefox, WebKit via Playwright
- **AI-powered analysis** β€” BYOK (OpenAI/Anthropic) classifies regressions vs intentional changes
- **Smart rendering** β€” Dependency graph renders only pages affected by your changes
- **Preview deployments** β€” Auto-detects Vercel/Netlify preview URLs
- **Git-native baselines** β€” Stored in orphan branch, zero main branch bloat
- **Framework detection** β€” Next.js, Remix, SvelteKit, Nuxt, Astro out of the box
- **Security hardened** β€” Shell injection prevention, path traversal guards, API key redaction
- **Memory managed** β€” Streaming buffers, temp file cleanup, bounded concurrency
- **PR thumbnails** β€” Baseline/current/diff images embedded in PR comments (R2/S3/GitHub artifacts)
- **Per-route thresholds** β€” Strict on `/checkout`, relaxed on `/blog` β€” all in one config

## How Frontguard Compares

| | Frontguard | Percy | Chromatic | BackstopJS | Lost Pixel |
|---|:---:|:---:|:---:|:---:|:---:|
| Open source | βœ… | ❌ | ◐ | βœ… | ◐ (archived) |
| CLI-first | βœ… | ❌ | ❌ | βœ… | βœ… |
| **AI change classification** | βœ… | ❌ | ❌ | ❌ | ❌ |
| Anti-flake rendering | βœ… | ◐ | ◐ | ❌ | ❌ |
| Self-hostable | βœ… | ❌ | ❌ | βœ… | ◐ |
| Free tier | Forever (CLI) | Trial β†’ $399/mo | Storybook hobby | Free | Dead |
| Actively maintained | βœ… | βœ… | βœ… | ❌ (6yr) | ❌ |

> Migrating? See the [BackstopJS](https://frontguard.dev/docs/guides/migrate-from-backstopjs) and [Lost Pixel](https://frontguard.dev/docs/guides/migrate-from-lost-pixel) guides.

## AI Classification Example

```
✘ /dashboard @ 375px β€” 2.34% changed
πŸ”΄ AI Analysis β€” Regression (94% confidence)
"The sidebar overlaps the main content on mobile. A flex-direction
change in Dashboard.module.css:28 removed the column stacking."
Suggested fix: restore `flex-direction: column` at the < 768px breakpoint.

βœ“ /pricing @ 1440px β€” 0.8% changed
🟒 AI Analysis β€” Intentional (91% confidence)
"New 'Enterprise' pricing tier added. Layout intact, content expanded."
```

## Configuration

```typescript
// frontguard.config.ts
export default {
version: 1,
baseUrl: 'http://localhost:3000',

// Auto-discover routes (zero config)
discover: {
startUrl: '/',
maxDepth: 3,
exclude: ['/admin/*', '/api/*'],
},

// Or explicit routes
// routes: ['/', '/pricing', '/checkout'],

viewports: [375, 768, 1440],
browsers: ['chromium'],
threshold: 0.1,

// AI analysis (optional, BYOK)
ai: {
provider: 'openai',
model: 'gpt-4o',
},

// Ignore dynamic content
ignore: [
{ selector: '.dynamic-timestamp' },
],
};
```

## How It Works

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ROUTE DISCOVERY │───▢│ RENDER PAGES │───▢│ PIXEL DIFF β”‚
β”‚ Crawl / Config β”‚ β”‚ Playwright Γ— β”‚ β”‚ pixelmatch β”‚
β”‚ / Filesystem β”‚ β”‚ viewports Γ— β”‚ β”‚ fast gate β”‚
β”‚ β”‚ β”‚ browsers β”‚ β”‚ (90% pass here)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ changed
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ PR COMMENT │◀───│ AI ANALYSIS │◀───│ DOM DIFF β”‚
β”‚ Visual diffs β”‚ β”‚ GPT-4V / Claude β”‚ β”‚ Structural + β”‚
β”‚ Explanation β”‚ β”‚ Classify + β”‚ β”‚ computed styles β”‚
β”‚ Fix suggestion β”‚ β”‚ explain + fix β”‚ β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

## CLI Output

```
frontguard v0.1.0

πŸ” Discovering routes... found 47 routes
πŸ“Š 12/47 routes affected by changed files
πŸ–₯ Rendering 12 routes Γ— 3 viewports

───────────────────────────────────────────
RESULTS 12 routes
───────────────────────────────────────────
βœ“ / 375 768 1440 PASS
βœ“ /pricing 375 768 1440 PASS
⚠ /checkout 375 768 1440 WARNING
✘ /dashboard 375 768 1440 REGRESSION
β˜… /settings 375 768 1440 NEW
───────────────────────────────────────────

✘ /dashboard @ 375px
AI: "Sidebar overlaps main content on mobile.
flex-direction change in Dashboard.module.css:28"
Severity: πŸ”΄ Critical (confidence: 94%)

1 regression Β· 1 warning Β· 9 passed Β· 1 new
```

## Plugins

Frontguard ships with a plugin architecture (6 lifecycle hooks) and 5 built-in plugins:

| Plugin | Description | Key Features |
|--------|-------------|--------------|
| **Figma** (`src/plugins/figma.ts`) | Design-to-code comparison | Figma API integration, design token extraction, component mapping |
| **Performance Budgets** (`src/plugins/perf-budgets.ts`) | Web Vitals & budgets | LCP/CLS/TTFB thresholds, violations correlated with the visual diff |
| **Accessibility** (`src/plugins/accessibility.ts`) | axe-core audits | WCAG checks (contrast, alt text, target size, focus, headings) in the same render pass |
| **Third-Party Scripts** (`src/plugins/third-party-scripts.ts`) | Script drift detection | Flags ad/analytics/widget origins that appear or disappear between runs |
| **Monitor** (`src/plugins/monitor.ts`) | Production visual monitoring (CLI + optional cloud scheduler) | Live-URL checks, threshold alerting, history tracking |

**Plugin lifecycle hooks:** `beforeDiscover`, `afterDiscover`, `afterRender`, `afterCompare`, `afterRun`, `onError`

```typescript
// frontguard.config.ts
import { createFigmaPlugin } from '@frontguard/cli/plugins';

export default {
// ...base config
plugins: [
createFigmaPlugin({ fileKey: 'your-figma-file-key' }),
],
};
```

## Architecture

```
src/
β”œβ”€β”€ cli/ # CLI entry point (Commander.js)
β”œβ”€β”€ core/ # Pipeline orchestrator, types, config, plugin system
β”œβ”€β”€ discovery/ # Route discovery (crawler + filesystem)
β”œβ”€β”€ render/ # Playwright rendering engine
β”œβ”€β”€ diff/ # Pixel diff + AI vision analysis
β”œβ”€β”€ storage/ # Git orphan branch baselines
β”œβ”€β”€ report/ # Console, JSON, HTML, GitHub PR reporters
β”œβ”€β”€ plugins/ # Figma, perf budgets, accessibility, third-party scripts, monitoring
└── utils/ # Redaction, logging, retry
```

Pipeline: `discover β†’ filter β†’ render β†’ diff β†’ analyze β†’ report`

Each stage is independent with error boundaries β€” one page failing doesn't kill the run.

## Documentation

See [`docs/`](./docs/) for:
- [Product deep-dive](./docs/PRODUCT.md) β€” Architecture decisions and design rationale
- [Research](./docs/research/) β€” Market data, technical feasibility, competitive landscape

## Roadmap

See [ROADMAP.md](./docs/ROADMAP.md) for the full milestone history and upcoming plans.

## Environment Variables

```bash
# AI Analysis (optional, BYOK β€” bring your own key, pick one)
FRONTGUARD_OPENAI_KEY=sk-...
FRONTGUARD_ANTHROPIC_KEY=...

# GitHub PR comments
GITHUB_TOKEN=ghp_...
```

> **Note:** AI keys are optional. Frontguard works without them β€” pixel diff and DOM diff run locally. AI analysis (classification, explanations, fix suggestions) activates only when a key is provided.

## Contributing

Contributions welcome! See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines, development setup, and how to submit PRs.

## License

MIT