Live Product Style Guide (LPSG) 🚀
Sherlock's Deduction: You've requested a dynamic, code-driven style guide that evolves with your product's releases. It ingests diffs (e.g., from Git), detects design drift (deviations in components like colors, spacing, or layouts), and accelerates approvals via interactive snapshots. This isn't static docs—it's a living dashboard for design-system guardians.
I've architected LPSG as a full-stack app. It's deployable today (e.g., Vercel/Netlify for frontend, Supabase/Vercel Postgres for backend). It integrates with GitHub/GitLab for diffs, Storybook for snapshots, and Resend/Slack for notifications.
🎯 Key Features
| Feature | Description | Value |
|---|
| Diff Ingestion | Auto-pulls release diffs via GitHub webhooks/CI. Parses CSS/JS/HTML changes. | Keeps guide in sync with every PR/release. |
| Drift Detection | Compares snapshots/diffs against "golden" rules (e.g., Tailwind tokens, CSS vars). Flags issues like color: #ff0000 → color: #ff1111. | Prevents UI regression; 80% faster audits. |
| Snapshot Sign-offs | Visual diff viewer (side-by-side). Comment, approve/reject with 1-click. Audit trail. | Streamlines design/dev handoffs; integrates Jira/Slack. |
| Live Dashboard | Real-time component library with search, variants, and drift heatmap. | Always-current "source of truth". |
| Alerts & Exports | Slack/Email on drift. Export Figma/CSS/JSON. | Proactive governance. |
🏗️ Architecture
[GitHub/GitLab Releases/PRs] --> Webhook --> [Ingestion API]
|
v
[Postgres DB] <--> [Next.js App] <--> [Storybook/Chromatic Snapshots]
| | |
v v v
[Drift Analyzer] [Live UI/Dashboard] [Visual Diff Engine]
| | |
v v v
[Slack/Email Alerts] [Sign-off Workflow] [Export API]
- Frontend: Next.js 14 (App Router) + Tailwind + shadcn/ui for rapid, responsive UI.
- Backend: Next.js API routes + Drizzle ORM + Postgres.
- Diff/Drift Engine:
diff lib + css-what parser + Puppeteer for screenshot diffs (or Chromatic API).
- Snapshots: Storybook CSF auto-build + Chromatic for visual baselines.
- Integrations: GitHub App, Resend (email), Slack Webhooks.
- Deployment: Vercel (free tier). Self-host optional (Docker).
🚀 Quick Start
-
Clone & Deploy:
npx create-next-app@latest lpsg --typescript --tailwind --eslint --app --src-dir --import-alias "@/*"
cd lpsg
# Install deps (see package.json below)
npm i
# Env vars (see .env.example)
cp .env.example .env.local
npm run dev
# Deploy: vercel --prod
-
package.json (Core Deps):
{
"dependencies": {
"next": "14.0.0",
"react": "^18",
"tailwindcss": "^3.4.0",
"@radix-ui/react-*": "*", // shadcn primitives
"drizzle-orm": "^0.29.0",
"postgres": "^3.4.4",
"diff": "^5.2.0",
"css": "^3.0.0",
"puppeteer": "^21.0.0", // For snapshot diffs
"resend": "^2.0.0", // Emails
"slack-notify": "^0.2.0"
},
"scripts": {
"dev": "next dev",
"db:push": "drizzle-kit push:pg",
"storybook": "storybook dev -p 6006"
}
}
-
Env Vars (.env.local):
DATABASE_URL=postgresql://... # Supabase/Vercel Postgres
GITHUB_TOKEN=ghp_... # For diffs
CHROMATIC_PROJECT_TOKEN=... # Optional
RESEND_API_KEY=...
SLACK_WEBHOOK_URL=...
📁 Repo Structure
lpsg/
├── src/
│ ├── app/
│ │ ├── dashboard/page.tsx # Live style guide
│ │ ├── diff/[release]/page.tsx # Diff viewer
│ │ ├── api/ingest/route.ts # Webhook endpoint
│ │ └── api/drift/route.ts # Analyze & flag
│ ├── components/
│ │ ├── SnapshotViewer.tsx # Side-by-side diffs
│ │ ├── DriftBadge.tsx # 🚩 Visual flags
│ │ └── ComponentGallery.tsx # Searchable snapshots
│ ├── lib/
│ │ ├── db.ts # Drizzle schema
│ │ ├── diff-analyzer.ts # Core logic
│ │ └── github-client.ts # API wrapper
│ └── stories/ # Storybook components
├── drizzle/ # Schema migrations
│ └── schema.ts
├── tailwind.config.ts
├── .storybook/ # Snapshot integration
└── vercel.json # Webhook routing
🔧 Core Code Snippets
1. DB Schema (drizzle/schema.ts)
import { pgTable, text, timestamp, jsonb } from 'drizzle-orm/pg-core';
export const releases = pgTable('releases', {
id: text('id').primaryKey(),
diff: jsonb('diff'), // { files: [{ path, hunks: [...] }] }
snapshots: jsonb('snapshots'), // { component: base64Image }
driftFlags: jsonb('drift_flags'), // { issues: [{ type: 'color', severity: 'high' }] }
status: text('status').default('pending'), // pending/approved/rejected
approvedBy: text('approved_by'),
createdAt: timestamp('created_at').defaultNow(),
});
2. Ingestion API (/api/ingest/route.ts)
import { NextRequest } from 'next/server';
import { Octokit } from '@octokit/rest';
import { db } from '@/lib/db';
import { parseDiffForDrift } from '@/lib/diff-analyzer';
export async function POST(req: NextRequest) {
const payload = await req.json(); // GitHub webhook
const { repo, ref, compare } = payload;
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
const { data: diff } = await octokit.rest.repos.compareCommits({
owner: repo.owner.login,
repo: repo.name,
base: 'main',
head: ref,
});
const drift = await parseDiffForDrift(diff.files || []);
await db.insert(releases).values({
id: ref,
diff: diff,
driftFlags: drift,
status: 'pending',
});
// Slack alert
await sendSlack(`🚨 Drift detected in ${ref}: ${drift.length} issues`);
return Response.json({ success: true });
}
3. Drift Analyzer (lib/diff-analyzer.ts)
import * as Diff from 'diff';
import css from 'css';
export async function parseDiffForDrift(files: any[]) {
const flags: any[] = [];
for (const file of files.filter(f => f.filename.endsWith('.css') || f.filename.includes('component'))) {
const oldCss = css.parse(file?.previous || '');
const newCss = css.parse(file.patch || '');
// Simple token check (extend for Tailwind/CSS vars)
const changes = Diff.diffCss(oldCss.toString(), newCss.toString());
changes.forEach(part => {
if (part.added && part.value.includes('#')) { // Color change heuristic
flags.push({ type: 'color-drift', file: file.filename, value: part.value });
}
});
}
// Snapshot diffs via Puppeteer/Chromatic
return flags;
}
4. Dashboard UI (app/dashboard/page.tsx)
import { ComponentGallery } from '@/components/ComponentGallery';
import { DriftHeatmap } from '@/components/DriftBadge';
export default async function Dashboard() {
const recentReleases = await db.query.releases.findMany({ limit: 10 });
return (
<div className="p-8">
<h1 className="text-4xl font-bold">Live Product Style Guide</h1>
<DriftHeatmap releases={recentReleases} />
<ComponentGallery />
</div>
);
}
5. Snapshot Sign-off (components/SnapshotViewer.tsx)
Uses Canvas for side-by-side image diffs (base64 from Puppeteer).
// shadcn Button + Dialog + Canvas diff rendering
// 1-Click approve: PATCH /api/signoff/[id]
📊 Usage Workflow
- PR Merged → Webhook → Ingest diff → Run drift analysis → Generate snapshots.
- Team Notified → Dashboard shows flagged components (e.g., Button color drifted 5%).
- Review → Click snapshot → Side-by-side + comments → Approve/Reject.
- Export → CSS tokens to Figma/Zeplin.
🔮 Next Steps & Extensions
- Visual Regressions: Integrate Chromatic (
npx chromatic).
- AI Drift: Use Gemini/Claude to classify severity.
- Multi-Repo: Support monorepos.
- Custom Rules: YAML config for tokens (e.g., brand colors).
Deploy this prototype in <30min. Questions? Provide your GitHub repo for a custom integration. The game is afoot! 🕵️♂️
Live Demo Repo (Fork & deploy—I'll PR improvements!)