# How to Build and Maintain Your Own shadcn-Compatible Component Registry

> Inside Haze UI's build pipeline: generating registry.json, public/r/*.json, Markdown twins, and quality checks from 371 entries.

- Category: Architecture · Published: 2026-09-11 · Updated: 2026-11-21 · Reading time: 10 min read
- Canonical URL: https://hazeui.com/guides/private-shadcn-component-registry-architecture-guide
- Tags: shadcn-registry, design-systems, architecture, ci-cd, astro

## Executive Summary

Building a custom shadcn-compatible component registry requires matching install paths to source paths, deriving npm and registry dependencies automatically from imports, compiling public/r/*.json via shadcn build, and running automated validation gates. Haze UI ships 371 entries statically using globbed *.meta.ts manifests and Node validation scripts with zero database or API server.

Once a team maintains more than fifteen UI components across two or three apps, publishing a monolithic npm package creates a slow upgrade treadmill: every minor CSS tweak forces package releases, version bumps across repositories, and painful overrides whenever one product needs a small layout adjustment.

Serving your UI library as a static **shadcn-compatible registry** reverses that dynamic. Teams install clean `.astro` (or `.tsx`) source files straight into their repo with `npx shadcn@latest add`, keep 100% ownership, and host the entire registry as plain static JSON files on any CDN.

Haze UI runs this exact architecture at 371 entries (241 UI components and 130 page blocks). Here is the blueprint for building and governing your own registry without maintenance rot.

## 1. Mirror source paths directly to install paths

The cleanest decision you can make on day one is keeping source paths inside your registry repository **identical** to consumer install paths:

```text
src/
  components/haze/ui/<slug>.astro       -> installs to src/components/haze/ui/<slug>.astro
  components/haze/blocks/<slug>.astro   -> installs to src/components/haze/blocks/<slug>.astro
  lib/haze/utils.ts                     -> installs to src/lib/haze/utils.ts
  styles/haze.css                       -> installs to src/styles/haze.css
```

Why does this eliminate whole classes of bugs? When `hero-centered.astro` imports `import Button from "../ui/button.astro"` and `import { cn } from "../../../lib/haze/utils"`, those exact relative paths work inside your documentation preview **and** inside every consumer's project after installation. You need zero brittle AST import rewriting during CLI installation.

Pair that with explicit `target` fields in each item of `registry.json`:

```json
{
  "name": "hero-centered",
  "type": "registry:block",
  "title": "Hero: centered with announcement badge",
  "dependencies": ["@lucide/astro"],
  "registryDependencies": ["@haze/badge", "@haze/button", "@haze/placeholder", "@haze/utils"],
  "files": [
    {
      "path": "src/components/haze/blocks/hero-centered.astro",
      "type": "registry:block",
      "target": "src/components/haze/blocks/hero-centered.astro"
    }
  ]
}
```

## 2. Derive dependencies automatically from source imports

Maintaining dependency arrays by hand guarantees drift: someone adds a Lucide icon or `Badge` import to a block and forgets to update JSON, breaking installs for downstream consumers.

Instead, Haze UI's generator (`scripts/gen-registry.mjs` and `scripts/lib/entries.mjs`) scans every `import ... from "..."` line in each `.astro` file's frontmatter:

- Imports matching `../ui/<name>.astro` or `./<name>.astro` emit `@your-org/<name>` in `registryDependencies`.
- Imports pointing to `lib/haze/utils` emit `@your-org/utils`.
- Bare package specifiers (`@lucide/astro`, `clsx`, `tailwind-merge`) populate npm `dependencies`.
- **Exception for `@haze/theme`:** Never inject the theme file into every component's `registryDependencies`, because re-installing it over a consumer's customized `haze.css` stops `shadcn add` on interactive overwrite prompts. Document theme setup as a one-time initial command instead.

## 3. Co-locate typed metadata alongside every component

Instead of maintaining a central 2,000-line catalog file that causes Git merge conflicts on every PR, place a typed `<slug>.meta.ts` file beside each component:

```ts
import { defineMeta } from "../../../site/meta";

export default defineMeta({
  slug: "button",
  title: "Button",
  kind: "ui",
  category: "actions",
  tags: ["action", "trigger", "link"],
  summary: "Button or link styled as a button across seven variants and four sizes.",
  useWhen: ["Triggering form submissions or primary page actions"],
  avoidWhen: ["Plain inline prose navigation; use a standard link"],
  alternatives: ["button-group", "copy-button"],
  props: [/* typed prop docs */],
  a11y: { notes: ["..."], keyboard: [{ keys: "Enter / Space", action: "Activate" }] },
  interactivity: "none",
  examplePrompts: ["Add a secondary button with loading state"],
  source: [],
  addedAt: "2026-11-17",
});
```

From that single globbed manifest set, `pnpm gen` generates **six outputs in one deterministic pass**:

1. `src/styles/haze.css` (from DTCG tokens in `tokens/haze.tokens.json`)
2. `registry.json` (root shadcn registry manifest)
3. `public/r/*.json` (via `shadcn build -o public/r`, one self-contained JSON payload per entry)
4. `public/llms.txt`, `public/llms-full.txt`, and `public/DESIGN.md`
5. `public/{ui,blocks,guides}/*.md` (Markdown twins for every entry)
6. `public/sitemap.xml` and `public/robots.txt`

## 4. Automated quality gates that scale past 300 entries

Once a registry grows past a few dozen blocks, manual PR review misses subtle errors. Five fast Node checks keep Haze UI clean before Astro ever runs `astro check`:

| Check script | What it enforces |
|---|---|
| `check-portable` | Bans framework-bound helpers (`set:html`, `define:vars`, `<style>`, `class:list` inside portable blocks) and raw colors |
| `check-vocab` | Compiles every utility class against `tailwindcss` + `haze.css` so typos, `transition-all`, and invented shadows fail CI |
| `check-meta` | Validates schemas, verifies every `alternatives` and dependency slug exists, ensures `interactivity` matches `<script>` presence, and prevents duplicate summary boilerplate |
| `check-contrast` | Composites 312 foreground/surface/tint pairs in dark and light modes against WCAG AA thresholds |
| `check-dupes` | Measures structural similarity across normalized markup shingles so no category fills up with copy-swapped clones |

## 5. Serving static `/r/*.json` reliably

On static hosts like Cloudflare Pages, add explicit cache and CORS headers in `public/_headers` for `/r/*` (`Access-Control-Allow-Origin: *`, short CDN cache with `stale-while-revalidate`) and test an end-to-end `shadcn add` command inside a clean scratch Astro project during release verification.

Inspect Haze UI's live [Registry index](/r/registry.json), examine real component metadata pages like [Button](/ui/button) and [Code Preview](/ui/code-preview), or start consuming the registry in your own project with [How to Use the shadcn CLI in an Astro Project](/guides/shadcn-cli-for-astro-without-react).

## Mentioned Haze UI Entries

- [Button](https://hazeui.com/ui/button.md): Button or link styled as a button, in seven variants and three text sizes, plus a square icon size and press and loading states.
- [Card](https://hazeui.com/ui/card.md): Bordered surface with an optional header, a body slot and a footer band; it can lift on hover when the whole card is a link.
- [Code preview](https://hazeui.com/ui/code-preview.md): Docs-style panel with a Preview and a Code pane: a live example in the slot, its source in a scrolling pre, and a copy button.
- [Diff viewer](https://hazeui.com/ui/diff-viewer.md): Unified and side-by-side code diff viewer with addition/deletion counts and monospace line numbers.
- [Developer tools bento](https://hazeui.com/blocks/bento-developer-tools.md): Four tiles with color image placeholders: build time with its change, a copyable command, release checks and build phases.

## Frequently Asked Questions

### How are npm and @haze/* registry dependencies populated in registry.json?

scripts/gen-registry.mjs parses import statements directly from each .astro file's frontmatter, mapping relative ../ui/<slug>.astro imports to @haze/<slug>, utils imports to @haze/utils, and bare package specifiers like @lucide/astro to npm dependencies.

### Why should registry items declare explicit target paths?

Explicit target paths guarantee that relative imports inside copied files resolve identically both in your documentation site repository and in any consumer's project—without rewriting import specifiers at install time.

### Can I host a static shadcn registry on Cloudflare Pages or GitHub Pages?

Yes. Running shadcn build -o public/r generates static JSON files for every entry, so any static host or CDN serves both public installations and private team registries with simple CORS headers.
