ui-guides-agent-rules
CLAUDE.md1 starsChanged 10 months agoMITView on GitHub
This is a React application showcasing Vercel's Web Interface Guidelines. It displays UI/UX principles with interactive good/bad examples, helping developers understand and apply best practices for accessible, performant web interfaces. Routing is path-based (/principles/:id), and every write goes through navigate(). popstate is the only listener needed — with real paths there is no hashchange to miss. Two rules keep history honest: navigate pushes, so each rule is its own entry, while the mount-time correction for landing on / uses replaceState…
In this repository6 other files it gives its agents.
- public/llms-full.txtllms.txt
- public/llms.txtllms.txt
- mdx-content-stackSkill
- principles-authoringSkill
- principle-validation-workflowSkill
- theme-validationSkill
The file
We split this CLAUDE.md into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 71
Create the component in the appropriate category folder
- Very specific: line 76
Add the Principle object to the matching category module in src/data/principles/{category}.ts with example keys
- Very specific: line 77
Create Good/Bad example components in the appropriate category folder (the derived key must match badExampleKey/goodExampleKey exactly — …
- Very specific: line 167
Adding components: Use npx shadcn@latest add <component> - configured in components.json with path aliases (@/components, @/lib/utils, etc.)
- Very specific: line 194
Use compositor-friendly animations (transform, opacity)
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is a React application showcasing Vercel's Web Interface Guidelines. It displays UI/UX principles with interactive good/bad examples, helping developers understand and apply best practices for accessible, performant web interfaces.
Commands
# Development
npm run dev # Start Vite dev server
# Build & Preview
npm run build # Build for production (runs generate:llms first via prebuild)
npm run preview # Preview production build
npm run generate:llms # Regenerate public/llms.txt, llms-full.txt, sitemap.xml
# Code Quality
npm run lint # ESLint check
npm run typecheck # TypeScript type checking
# Data / Sources
npm run validate # Field completeness + example mapping + theme checks
npm run check:sources # Check upstream skill sources for new/uncovered rules
# Testing
npm test # Run tests once
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage report
# E2E Testing (Playwright)
npm run test:e2e # Run all e2e tests
npm run test:e2e:headed # Run with visible browser
npm run test:e2e:ui # Run with Playwright UI
npm run test:e2e:principle # Run principle visual tests onlyArchitecture
Data Flow
- Principles Data (
src/data/principles/): The single source of truth, split into one module per category (interactions.ts,animations.ts,layout.ts,content.ts,forms.ts,performance.ts,design.ts,aesthetics.ts).index.tsis the barrel that re-exportscategories(fromcategories.ts) and a flat, category-groupedprinciplesarray. Import from@/data/principles— never a category file directly. - Agent Rules (
src/data/agentRules.ts): Companion rules for AI agents, keyed by principle ID with type-safe linking - Example Renderer (
src/components/ExampleRenderer.tsx): Auto-discovers example components viaimport.meta.glob
Component Structure
App.tsx: Main layout with keyboard navigation, path-based routing, dynamic page title, sidebar toggleRouting is path-based (
/principles/:id), and every write goes throughnavigate().popstateis the only listener needed — with real paths there is nohashchangeto miss. Two rules keep history honest:navigatepushes, so each rule is its own entry, while the mount-time correction for landing on/usesreplaceStateso it does not sit behind the user's first Back press as a phantom entry.Legacy hash URLs are rewritten on mount and that code is permanent.
llms.txtdeep-linked categories by hash andllms-full.txtcarried a hash permalink for all 411 rules — published, in the wild, uncontrollable.routeFromLegacyHashinsrc/lib/routes.tsmaps them onto paths. Deleting it breaks citations we made.URLs derive from the principle id, never from
category+ slug. Hierarchy is derivable (every id is category-prefixed) but it would couple a permanent URL to mutable metadata: recategorise a rule and its page moves. Same reasoning that moved WordPress permalinks off/category/post.isDesktopmust never affect render output.useMediaQuerycannot know the viewport on the server, so branching on it while rendering guarantees a hydration mismatch. Layout is expressed in CSS (md:variants); the hook is used only in effects and event handlers.Sidebarsetsinert/aria-hiddenin an effect for the same reason.PrincipleView.tsx: Displays principle details with side-by-side good/bad examplesExampleRenderer.tsx: Lazy-loads examples automatically from./examples/**/*.tsxSidebar.tsx: Navigation with search, focus trap, andoverscroll-behavior: containNavigation.tsx/Header.tsx: Chrome components
Example Components Pattern
Examples live in src/components/examples/{category}/ with naming convention:
{PrincipleName}Good.tsx- Correct implementation{PrincipleName}Bad.tsx- Anti-pattern demonstration
Examples are automatically discovered - no manual registration needed. Just:
- Create the component in the appropriate category folder
- Export the component as a named export
- The file path is converted to a key:
forms/EnterSubmitsBad.tsx→forms-enter-submits-bad
To add a new principle:
- Add the
Principleobject to the matching category module insrc/data/principles/{category}.tswith example keys - Create Good/Bad example components in the appropriate category folder (the derived key must match
badExampleKey/goodExampleKeyexactly — beware acronym casing, e.g.ZIndex→zindex, notz-index) - Optionally add an agent rule to
src/data/agentRules.ts - Verify:
npm run typecheck && npm run validate
Types
src/types/principle.ts defines:
Principle: Main data structure for each guidelinePrincipleCategory: Union type for categoriesPatternSource/PatternSourceInfo: Multi-source tagging systemAgentRule/AgentRulePriority: Rule types with MUST/SHOULD/NEVER
Multi-Source Tagging System
Principles can be tagged with their pattern source for the "brain center" concept:
type PatternSource = 'vercel' | 'wcag' | 'aria' | 'design-system' | 'custom';Each principle has an optional source field linking it to its origin (Vercel guidelines, WCAG criteria, ARIA practices, etc.). This enables filtering and attribution.
Agent Rules System
Agent rules in src/data/agentRules.ts provide AI-consumable guidelines:
type AgentRulePriority = 'MUST' | 'SHOULD' | 'NEVER';
interface AgentRule {
priority: AgentRulePriority;
rule: string;
codeExample?: string;
}Rules are keyed by principle ID with type-safe linking to ensure every rule maps to a valid principle.
Source Sync System
Rules are hand-transcribed from upstream "skill" sources, so a small sync system keeps us aligned. The authority is the source catalog src/data/sources.ts (sourceCatalog), which mirrors the Obsidian provenance report "UI · Animation · Design Skills — Source Directory 2026". It's decoupled from the app's PatternSource/badge system: a source can be catalogued (for coverage) before any of its rules are onboarded. Each entry has a check mode:
github— rules live as raw markdown bullet/numbered lists (rawUrls). Verified auto-diffable: Vercelcommand.md, RaunoREADME.md, Emil Kowalskireview-animations/SKILL.md.manual— no diffable rule file; reminded on areviewEveryDayscadence.
Scripts (shared extraction in scripts/lib/rules.ts — tokenize/extract/classify/fetch):
npm run check:sources— freshness. Fetches github sources, extracts rules, fuzzy-diffs against the whole corpus, writes uncovered ones todoc/pending-rules.json(flaggedneeds-examples, with auto-classified category + tags).-- --mark-reviewed=<id>stamps a manual source (doc/source-review-state.json).npm run sources:build -- <id> [--limit=N]— onboard a source: fetch → extract → classify category + tags → scaffoldstatus:'draft'Principle entries intosrc/data/principles/drafts.ts. Requires the source to havecheck.mode:'github'+ apatternSource(add to thePatternSourceunion + asource-registry.tsbadge first).npm run sources:catalog— diffssourceCatalogagainst the Obsidian report → flags report repos not yet catalogued.-- --report="/path"to override.
Drafts (draftPrinciples in src/data/principles/drafts.ts) are NOT in the principles array, so they're hidden from the app until promoted: author their Good/Bad examples, move the entry into its category module, drop status. Never auto-mutates published data.
Tags — src/data/tags.ts derives cross-cutting filter tags (motion, a11y, typography, forms, color…) at runtime from category + keywords, merged with explicit tags. Applied in the barrel via withTags(), surfaced by the sidebar TagFilter (alongside SourceFilter).
See doc/specs/2026-07-12-source-freshness-sync.md.
Note: the MDX content layer under
content/principles/was removed — it duplicatedprinciples.tsand was never rendered by the app.principles/**is now the sole source of truth.
Discoverability & Attribution
Each rule is a prerendered page at /principles/<id> carrying its own title, meta, canonical, OG card and JSON-LD, plus the rule and its reasoning as real text. Three consequences shape this layer:
scripts/generate-llms.ts(run byprebuild, sonpm run buildalways refreshes it) emitspublic/llms.txt,public/llms-full.txt, andpublic/sitemap.xmlfrom the principle data.llms-full.txtis the only machine-readable copy of the corpus — it's what agents actually fetch and cite. Never hand-edit those three files; editsrc/data/principles/*and regenerate.public/robots.txtis hand-written and allows all AI crawlers.llms.txtmust follow llmstxt.org, and that means Markdown links. Every section is a list of- [Name](url): notesbuilt through thelink()helper. A section of bare URLs reads fine to a human and gets rejected by validators as "does not appear to contain any links" — which is how this broke once already. The generator asserts an H1 and a link count before writing, so a regression fails the build instead of shipping. Sources with no upstream URL (e.g.custom) point at/#sourcesrather than degrading to plain text.scripts/generate-agent-layers.ts(alsoprebuild) emits the sliceable payloads an agent in another repo fetches:public/principles/index.md,must.md,<id>.md,<id>.json, andpublic/categories/<category>.md. These are gitignored — 800+ generated files would drown every diff, and Vite copiespublic/intodist/so they ship on the deploy regardless. The three discovery files stay tracked because their diffs are how a corpus change gets reviewed.The reason this layer exists is token cost:
llms-full.txtis ~166k tokens, so it is almost never the right fetch. The ladder is index (~8k) → category (6k–26k) ormust.md(~11k) → one rule (~1.4k). The per-rule payload is the only endpoint carrying the example component source — 823 components, 3.3 MB, otherwise unreachable — and the generator throws if any principle would ship without both, since that code is the reason the payload exists.index.mdis searched, not read top-to-bottom. Every rule line ends in match tokens: the surfaces it applies to and the symbols its examples use. Surfaces are the "what am I building" axis, modelled on the WAI-ARIA APG — an agent works on a dialog or a form, not on "the animations category", and a modal needs focus, motion and ARIA rules that live in three different ones. APG can partition cleanly because each page is a component; this corpus cannot — measured, a rule belongs to 2.1 surfaces on average, so surfaces are labels, not folders. Re-partitioning the files by surface would force false single-parents or duplicate rules on disk. 368/411 carry a surface; the 43 that do not stay reachable by category and symbol, and the index says so.Trigger symbols are the second axis, and that is what makes titles unnecessary. A title does not tell an agent whether a rule applies to the file in front of it ("Enter Submits" never says
onSubmit), and the tag vocabulary cannot help — 7 tags across 411 rules, 39% untagged. So each rule is annotated with the concrete symbols its own examples use, mined from the good and bad source plus the rule text, then filtered by document frequency: anything above 15% of the corpus is boilerplate (onClick,useState,<button>) and discriminates nothing. That reaches 264/411 — the mechanical rules; the rest are judgment calls reachable by category. Deriving symbols from the difference between good and bad was tried and is worse (it turnsforms-enter-submitsintoonClick), because the two examples usually share the relevant API and differ only incidentally.scripts/lib/corpus.tsholdsSITE/published/loadExampleSources()so the two generators cannot disagree. Example keys are re-derived throughpathToKey, never reconstructed from ids — acronym casing makes the reverse lossy.- Discovery pointers exist in three places because three different clients look in three different places.
index.htmlhas<link rel="alternate">for DOM-parsing crawlers;netlify.tomlsets an HTTPLinkheader for headless fetchers that never read the body; andFooter.tsxcarries ansr-only aria-hiddensentence namingllms-full.txt, for the case where a human pastes the URL into a chat model that only sees rendered text. The.txtfiles staytext/plainon the wire on purpose —text/markdownmakes browsers download them, and the footer links a human tollms-full.txt. - Authorship is expressed by a shared
@id. The JSON-LD inindex.htmlnames the author as{"@id": "https://glebstroganov.com/#person"}— the same node glebstroganov.com publishes in its/about.json. That is what merges the project into its author's works graph instead of creating a second, unlinked "Gleb Stroganov".src/components/Footer.tsxcarries the visible credit withrel="author me"to the same URL. Keep the footer href, the JSON-LD@id/sameAs, and the generator's attribution block in sync. scripts/prerender.ts(after both Vite builds) writesdist/principles/<id>/index.htmlfor every rule. It renders the real component tree viasrc/entry-server.tsx, not a hand-written template — a template would duplicate the JSX and drift from it.main.tsxcallshydrateRootwhen the container already has markup, so React attaches rather than re-rendering.Two things are held back from the static HTML so server and client agree, both gated on
useMounted: the example components (interactive demos, not indexable prose — 823 of them, and making them server-safe would be open-ended work with no payoff), and the sidebar beyond the current rule's category (all 411 links is 340 KB per page, 137 MB across the corpus; one category is ~6% of that and still gives a crawler real links).
Where this landed: sitemap.xml lists 415 URLs, up from 3. Per-rule OG images are still generic — the metadata is per-rule, the picture is not.
UI Components (shadcn/ui + Radix)
Uses shadcn/ui (new-york style) with Radix UI primitives in src/components/ui/.
Pattern: Components use class-variance-authority (CVA) for variants, extracted to .variants.ts files for fast-refresh compatibility.
Adding components: Use npx shadcn@latest add <component> - configured in components.json with path aliases (@/components, @/lib/utils, etc.)
Custom Animations
Defined in src/index.css using Tailwind v4's @theme and @utility directives:
motion-safe-fade-in-slide: Respectsprefers-reduced-motionanimate-scale-in,animate-scale-in-from-top: Menu animationstransition-transform-shadow,transition-transform-opacity: Compositor-friendly transitions
Tech Stack
- React 18 with TypeScript (strict mode)
- Vite with
@tailwindcss/viteplugin - Tailwind CSS v4 (CSS-based config)
- HUGEICONS for icons (@hugeicons/react)
- Vitest for unit testing
- ESLint with react-hooks and react-refresh plugins
UI/UX Guidelines Reference
This project implements principles from Vercel's Web Interface Guidelines. When working on this codebase, follow the same principles being demonstrated:
- Full keyboard accessibility with visible focus rings (
:focus-visible) - Focus traps in modals with focus return on close
- Hit targets ≥24px (≥44px on mobile)
- Proper form semantics with labels, autocomplete, and validation
- Respect
prefers-reduced-motion - Use compositor-friendly animations (
transform,opacity) - Never
transition: all overscroll-behavior: containin modals/drawers- Dynamic page titles matching current context
See doc/vercel-web-guides.md for the full source guidelines and doc/vercel-web-guides-agent.md for the condensed agent rules.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

