This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
PersianLabs/ui — an RTL-first, copy-paste component library for Persian interfaces, distributed as a shadcn-compatible registry (not an npm package). Users run npx shadcn add @persianlabsui/<name> — the namespace is listed in shadcn's registry directory — and the component source lands directly in their codebase. The direct-URL form (npx shadcn add https://ui.persian-labs.ir/r/<name>.json) also works. Install commands shown in the docs use the @persianlabsui/<name> form.
Turborepo monorepo, bun package manager ([email protected], workspaces: apps/*, packages/*).
Run from repo root (turbo fans out to workspaces):
bun install bun run dev # apps/web on http://localhost:3000 bun run build # runs `shadcn build` (prebuild) then `next build` in apps/web bun run lint bun run format bun run typecheck bun run test
Scope to one workspace with turbo filters, e.g. bunx turbo build --filter=web, or cd into apps/web / packages/ui and run the same script names directly (bun run lint, etc.) — each workspace's package.json defines the same script set.
Tests live in packages/ui (vitest + Testing Library) and run from the
repo root with bun run test. Run them before pushing whenever your
change touches packages/ui/src/lib/** or packages/ui/src/hooks/**,
and add tests for new utilities there.
Before every push, run bun run lint and bun run format. Resolve any errors and include Prettier's formatting changes in the same commit before pushing.
This is the one thing that isn't obvious from browsing a single directory. Every UI component is maintained in two parallel copies with different import aliases:
packages/ui/src/components/*.tsx— the internal@workspace/uipackage. Used byapps/webitself (docs site previews, examples) via@workspace/ui/lib/utils,@workspace/ui/components/*, etc. This is a normal internal workspace package, not what end users install.apps/web/registry/base/ui/*.tsx(plusregistry/base/lib/*.tsfor helpers likepersian-provinces.ts) — the consumer-ready source. Same component logic, but imports resolve the way a consumer's shadcn-configured project would (@/lib/utilsinstead of@workspace/ui/lib/utils). This tree is what actually ships:apps/web/registry.jsonpoints at these files,shadcn build(theprebuildstep) compiles them intoapps/web/public/r/*.json, andapps/web/lib/component-source.tsreads straight fromregistry/base/ui/*.tsx/registry/base/lib/*.tsto render "copy source" blocks on the docs pages.
When adding or editing a component, update both copies — they differ only in import paths (e.g. @workspace/ui/lib/utils vs @/lib/utils), not in logic. After changing apps/web/registry.json or any registry/base/** file, run bun run build (or cd apps/web && bun run registry:build) to regenerate apps/web/public/r/*.json.
To register a new component end-to-end:
-
Add the implementation to
packages/ui/src/components/<name>.tsx(internal alias imports). -
Add the consumer copy to
apps/web/registry/base/ui/<name>.tsx(@/...alias imports), plus any shared lib files underregistry/base/lib/. -
Add an entry to
apps/web/registry.json(name, type, title, description,registryDependencies,dependencies,files). -
Wire it into the docs — pages are markdown, built with fumadocs-mdx: create
apps/web/content/docs/components/<name>.mdx(frontmattertitle/description, optionalbadge; body uses<ComponentPreview name="<example>" />,<ComponentSource name title />,<InstallTabs command packages sourceName />, and<ApiReference title rows={…} />islands — see an existing page as template) and add its slug toapps/web/content/docs/components/meta.json(page-tree order). API table rows live inapps/web/lib/api-data/<name>.ts(imported by both the MDX and the markdown processor) and the module must be registered inapps/web/lib/api-data/index.ts(export * as <camelName> from "./<name>") — the.md/copy-page endpoint resolves rows through that table, and a missing entry renders API tables with headers but zero rows.apps/web/lib/docs-nav.tsis still the sidebar + site search index (apps/web/components/site-search.tsx, the ⌘K palette) — any enabled entry there is automatically searchable, so add the nav entry too; never hardcode a separate search index.- Markdown copy +
.mdendpoint: free.<url>.mdis served from the MDX itself byapps/web/app/markdown/[[...slug]]/route.ts(islands expand to code fences, Credits/LastEdited are stripped). No per-page strings or route maps to maintain — just curl the.mdURL once before pushing to confirm 200.
- Markdown copy +
-
Add example components under
apps/web/components/examples/<name>-<variant>.tsx(see Naming conventions below) — these import from@workspace/ui/components/*, not@/components/ui/*, since they run live insideapps/webitself. -
Every new component or utility must include both a preview image and an Open Graph image — and so must every guide page in the Components nav group (Charts ships one too); a page whose themed preview is missing or misnamed renders "No preview available" in the sidebar hover tooltip. Create two preview modules:
apps/web/components/previews/<name>.tsxexporting<Name>Preview(themed — colors via thepreviewtoken const from./shared, CSS variables) andapps/web/components/previews/og/<name>.tsxexporting<Name>Preview(Satori-safe — the same layout with hardcoded hex colors, since Satori can't resolve CSS variables). Both use plain inline styles, never Tailwind classes. The themed export name is resolved mechanically bycomponents/docs-sidebar.tsxas${docs-nav title with spaces removed}Preview, so keep the title's exact casing, acronyms included — "Input OTP" →InputOTPPreview, "QR Code" →QRCodePreview, "National ID Input" →NationalIDInputPreview(notNationalIdInputPreview). The barrels (components/previews/index.ts,components/previews/og/index.ts) and the slug→component map (components/previews/og/__map__.ts) regenerate automatically via predev/prebuild (scripts/generate-preview-map.mts) — never edit them by hand. Then wire the themed name into the catalog islandapps/web/components/mdx/components-catalog.tsx(renders/docs/components). OG images need no per-page route:apps/web/app/docs/og/[...slug]/route.tsxreads every docs page's frontmatter title/description plus the matchingog/<name>preview throughOG_PREVIEWS. Skipping this step is easy to miss — the doc page works fine without it, but the component never appears in/docs/components, loses its sidebar hover image, and gets no social preview image. -
Add the slug to
apps/web/app/llms.txt/route.ts's hand-maintained group lists (COMPONENT_GROUPS/UTILITY_GROUPS) —/llms.txtis generated exclusively from those arrays and silently omits anything not listed, as happened to Status Button at launch. -
Add a
Creditssection (apps/web/components/credits.tsx) to the doc page, directly underLastUpdated. If it's not clear where the component/data was copied from, what (if anything) was changed versus the source, or whether it's published, ask the user rather than guessing — don't invent attribution. Every RTL-motivated diff from the upstream source belongs in thechangesarray, worded as a diff ("Replaced X with Y for RTL"), not as a feature description. -
Give every doc page an explicit RTL section (
<ComponentPreview dir="rtl">) with real Persian/Farsi example content — not just relying on the built-in LTR/RTL toggle button that<ComponentPreview>already renders for every preview.
A component that isn't installable via the shadcn CLI yet (still exploratory) shouldn't get a registry.json entry or gallery card — see Typography for the pattern (docs-nav.ts entry + doc page only, no registry/source-copy machinery, since it's a styling guide rather than a component).
Blocks (apps/web/app/docs/blocks) aren't implemented yet — the nav entry is disabled ("Coming soon"). When they land, follow shadcn's own convention: registry:block items named <use-case>-<two-digit-number> (e.g. dashboard-01, login-02), each composed from existing registry components rather than new bespoke ones, with their own preview page under /docs/blocks/<name>. Confirm this convention still matches shadcn's current docs before building the first one — don't assume it's frozen from this note.
apps/web— Next.js 16 docs/marketing site. Renders component docs, live previews, and serves the registry JSON frompublic/r/.apps/web/content/docs/— all doc pages as MDX (components/<name>.mdx,utilities/<name>.mdx, plus index/theming/charts), compiled by fumadocs-mdx. Ordering lives in per-foldermeta.json; one renderer atcomponents/mdx/docs-doc-page.tsxserves everything throughapp/docs/page.tsx(root) andapp/docs/[...slug]/page.tsx. MDX islands are mapped inapps/web/mdx-components.tsx(headings, code fences via rehype-pretty-code fromsource.config.ts,<ComponentPreview>/<ComponentSource>resolving examples by name through the generatedcomponents/examples/__map__.ts).apps/web/registry/base/— consumer-ready component/lib source, mirrored intopublic/r/*.jsonbyshadcn build.apps/web/registry.json— the registry manifest (source of truth for what's installable and its dependency graph).apps/web/components.json— shadcn CLI config for this repo;rtl: true, base colorneutral, stylebase-nova, icon librarylucide.apps/web/lib/site.ts/apps/web/lib/github.ts— canonical site URL (SITE_URL) and GitHub repo slug (GITHUB_REPO); update both if the domain or repo location changes.apps/web/components/site-search.tsx— the header's ⌘K command palette, built on theCommandcomponent. Its index is generated fromapps/web/lib/docs-nav.ts, not maintained separately.
packages/ui— the@workspace/uiinternal package (components, hooks, lib, Tailwind globals) consumed only byapps/web.packages/eslint-config,packages/typescript-config— shared lint/tsconfig bases (base,next,react-internal/base,nextjs,react-library) extended by each workspace.
- Components are built on Base UI (
@base-ui/react), styled with Tailwind v4, variants viaclass-variance-authority, class merging via the sharedcnutil. - RTL-first: logical CSS properties and mirrored icons are the default; components must also work LTR.
- Prettier: no semicolons, double quotes,
trailingComma: es5,printWidth: 80, withprettier-plugin-tailwindcsssorting classes againstpackages/ui/src/styles/globals.css(functionscn,cvaare class-sorted too). - ESLint: flat config per workspace (
apps/web/eslint.config.js,packages/ui/eslint.config.js) extending@workspace/eslint-config;eslint-plugin-only-warnmeans lint issues surface as warnings, not hard failures. - Every component doc page must credit where it came from via
<Credits>(apps/web/components/credits.tsx), placed right under<LastUpdated>. Never fabricate a source, a "what changed" list, or publish status — if it isn't already known from context, ask the user for it first.
Every new or edited component must be checked against Vercel's web-interface-guidelines — an accessibility/performance/polish checklist covering:
- Interactions: full keyboard support, visible
:focus-visiblerings, 24px minimum hit targets (44px on mobile), 16px minimum mobile input font-size (see the Bank Input exception below),touch-action: manipulationon tap targets, no blocked paste, properautocomplete/inputMode,spellCheck={false}on sensitive fields, inline errors, unsaved-changes warnings. - Animation: honor
prefers-reduced-motion, animate onlytransform/opacity(never layout properties likeheight/width), never use baretransition/transition-all, correcttransform-origin, interruptible/input-driven gestures. - Layout: respect safe areas (
env(safe-area-inset-*)), no unwanted scrollbars, Flex/Grid over JS measurement. - Content & Accessibility: skeletons mirror final content,
font-variant-numeric: tabular-numsfor numbers, redundant status cues beyond color, accuratearia-label/aria-hidden, text truncation paired withmin-w-0on flex parents, locale-aware formatting,translate="no"on identifiers (card numbers, IBANs, shortcut keys). - Performance: virtualize lists over 50 items, prevent CLS with explicit image dimensions, minimize re-renders.
- Dark Mode & Hydration:
color-schemeset on:root,theme-colormeta tag, native<select>needs explicit background/color, controlledvaluealways paired withonChange. - Design: layered (ambient + direct) shadows, nested radii (child ≤ parent), prefer APCA over WCAG 2 for contrast.
Two repo-specific trade-offs decided against this checklist — don't "fix" them back without asking first:
- Button never hides content while loading.
loadingalways renders the spinner alongsidechildren, neverhideContentOnLoading-style content-swapping — matches Vercel Geist's own Button behavior (stays focusable, keeps its label, announces busy state). - Bank Input intentionally uses sub-16px text on mobile.
CardNumberInput/ShabaInputdeliberately break the 16px mobile-input-size guideline so a full 16–24 digit card/IBAN number fits without wrapping or horizontal scroll; the resulting iOS zoom-on-focus is an accepted trade-off, not a bug.
- Component names: kebab-case everywhere a slug is needed (file names,
registry.jsonname, doc route segment, e.g.hover-card,message-scroller). The human-readabletitleand doc<h1>are Title Case (e.g. "Hover Card"). Component function/export names are PascalCase matching the title (HoverCard,MessageScroller). - Example files:
apps/web/components/examples/<component>-<variant>.tsx, exporting<Component><Variant>Example(e.g.bubble-reactions.tsxexportsBubbleReactionsExample). The default/overview example is<component>-demo.tsx→<Component>DemoExample. The RTL example is always<component>-rtl.tsx→<Component>RtlExample, even when the component needs no RTL-specific CSS fix — it still gets a real Farsi example, per the checklist above. - Branches:
feat/<slug>for new features,fix/<slug>for bug fixes,docs/<slug>for documentation-only changes (like this one),chore/<slug>for tooling/dependency work. New components use the scoped formfeat/component/<slug>(e.g.feat/component/plate-input). Git forbids:in branch names, so the conventional-commit colon form is never used for branches. Slug is a short kebab-case description, not an issue number. - Commits: Conventional-commit-style prefixes, as seen throughout
git log:feat:,fix:,docs:,chore:, optionally scopedfeat(table):/fix(bubble):when the change is localized to one component or area. Body explains why, not a restatement of the diff. - Blocks (future, see below):
<use-case>-<two-digit-number>, e.g.dashboard-01.
--muted/--secondary/--accentare translucent overlays, not opaque fills (packages/ui/src/styles/globals.css, e.g.--muted: --alpha(var(--color-black) / 4%)). They're designed to sit on top of an opaque backdrop likebg-card/bg-popover/bg-background(hover states, subtle washes). Usingbg-mutedfor a standalone floating chip (a badge, a reaction pill) renders it almost invisible — usebg-popoverorbg-cardinstead when the element needs to be opaque on its own. This bit theBubblereactions pill; see its Credits section for the fix.- Base UI's
renderprop only picks up children placed inside the render target, not children passed to the wrapping trigger.<PopoverTrigger render={<Button/>}>{<Icon/>}</PopoverTrigger>silently renders an empty button — the icon never merges in. Every working example in this repo (Dialog, Sheet, Drawer, Tooltip, Pagination) puts the content on the target element itself:<PopoverTrigger render={<Button><Icon/></Button>} />. Always follow that pattern, never the former. - Third-party hooks that read
Date.now()/Math.random()during render break Next 16's Cache Components prerender with a "blocking prerender" error, even inside a"use client"component — Server Components still SSR client components on first paint.@tanstack/react-table'suseReactTable()does this internally. Deferring the component withnext/dynamic(..., { ssr: false })(wrapped in its own"use client"file, since that option is illegal directly in a Server Component page) did not reliably clear the error for this library — the Table doc page dropped its TanStack example entirely rather than keep fighting it. Treat this as a real constraint when picking example dependencies for a doc page, not just a config detail to work around. - RTL conversion checklist when porting an upstream (shadcn/other) component:
left-/right-→start-/end-,pl-/pr-→ps-/pe-,ml-/mr-→ms-/me-,border-l/border-r→border-s/border-e,text-left/text-right→text-start/text-end,-space-x-*→ addrtl:space-x-reverse, directional icons (chevrons, arrows) → keep the same icon and addrtl:-scale-x-100rather than swapping which icon renders per direction (seebreadcrumb.tsx,pagination.tsx). Leave a component's classes untouched (and say so in Credits withchanged: false) if it has no directional CSS to begin with — don't invent a change for its own sake. - Never use Persian characters (words or ۰-۹ digits) inside OG previews (
apps/web/components/previews/og/*). OG images are meant to render correctly everywhere they get unfurled (Slack, Twitter/X, Discord, etc.), and Persian glyphs have shown up mis-rendered/tofu'd in that pipeline — English text and Latin digits only, even though the live component itself is Persian-first (e.g.CalendarPreviewshows "August 2026", not "مرداد ۱۴۰۴"). The one narrow exception: a utility whose entire purpose is displaying a Persian character, likeNormalizePersianDigitsPreviewshowing "۱۲۳۴۵ → 12345" — there the Persian digit is the subject being demonstrated, not decoration. - Never call
new Date()/Date.now()/anything that reads the current time (today(),isPast/isFuture/isTodayfrompersian-date, a bareuseState(() => new Date())oruseMemo(() => new Date(), [])initializer) directly in a component's render body. It runs once during SSR and again during client hydration at slightly different real times, producing a hydration mismatch (Cannot destructure ... as it is nullor visibly different rendered text). Fix: defer it —useState<T | null>(null)+useEffect(() => { const init = () => setValue(...); init() }, []), thenif (!value) return nullbefore rendering. Route the effect'ssetStatethrough a locally-named inner function (init) rather than a bare top-level call, to avoid tripping thereact-hooks/set-state-in-effectlint rule — this is the exact patternuseCountdown/useDate/useTimeAgoalready use. Do not reach for<Suspense fallback={...}>as a workaround — it was tried once to silence Next's "unstable valuenew Date()" prerender error and it left previews permanently stuck in their fallback state in dev mode; always fix the actual render-time read instead.