
How to Create Your Own Shadcn/UI Component Registry
Shadcn/ui has revolutionized how developers think about UI components. Unlike traditional component libraries that come as black-box npm packages, shadcn/ui provides beautiful, accessible components that you actually own. When you install a shadcn component, the code lands directly in your project - fully customizable, no dependencies to worry about, no version conflicts.
But here's what makes shadcn truly powerful: the registry system. This innovative approach lets you distribute components without the traditional npm packaging friction. Instead of installing packages, you pull components directly into your codebase where you have complete control.
The benefits are game-changing:
🎯Full Ownership
Components become part of your codebase. Customize, modify, and extend them however you need.
📦No Dependencies
No more dependency hell. No version conflicts. Just clean code in your project.
⚡Easy Distribution
Share components with a simple URL. No npm publishing, no complex setup.
🔧Perfect for Teams
Maintain consistency across projects while allowing customization.
Ready to create your own component registry? In this guide, I'll show you how to build a registry that others can install with a simple npx shadcn add command - just like the official shadcn/ui components.
What We're Building
By the end of this tutorial, you'll have:
OrganisationUnitTree componentnpx shadcn add https://ui.derrick.rw/r/organisation-unit-tree.jsonPrerequisites
Step 1: Initialize Your Next.js Project
First, let's create a new Next.js project with shadcn/ui:
Step 2: Install Required Components
Install the base components we'll need:
npx shadcn@latest add input button badge cardStep 3: Create the Registry Structure
Create the required folder structure:
# Create registry directories
mkdir -p registry/default/uiYour project structure should now look like:
my-component-registry/
├── registry/
│ └── default/
│ └── ui/
├── public/
│ └── r/ (this is auto generated)
├── src/
│ └── components/
│ └── ui/
└── registry.json (we'll create this)Step 4: Create Your Component
Create the OrganisationUnitTree component:
# Create the component file
touch registry/default/ui/organisation-unit-tree.tsxAdd the following code to registry/default/ui/organisation-unit-tree.tsx:
"use client"
import type React from "react"
import { useCallback, useEffect, useState, useMemo } from "react"
import { Input } from "@/components/ui/input"
import { Badge } from "@/components/ui/badge"
import { Card, CardContent } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Loader2, Search, Users, ChevronDown, ChevronRight, X } from 'lucide-react'
import { cn } from "@/lib/utils"
// ... continue the componentStep 5: Create Registry Configuration
Create registry.json in your project root:
{
"$schema": "https://ui.shadcn.com/schema/registry.json",
"name": "my-component-registry",
"homepage": "https://ui.derrick.rw",
"items": [
{
"name": "organisation-unit-tree",
"type": "registry:ui",
"title": "Organisation Unit Tree",
"description": "A tree component for selecting organisation units with lazy loading support",
"files": [
{
"path": "registry/default/ui/organisation-unit-tree.tsx",
"type": "registry:ui"
}
],
"dependencies": ["lucide-react"],
"registryDependencies": ["input", "button", "badge", "card"]
}
]
}Step 6: Build the Registry
Run the shadcn build command to generate the registry files:
npx shadcn buildThis creates JSON files in the public/r/ directory that can be consumed by the shadcn CLI.
Step 7: Deploy Your Registry
Deploy your project to Vercel (or your preferred hosting):
https://your-domain.vercel.app/r/organisation-unit-tree.jsonStep 8: Test Installation from Your Registry
Now anyone can install your component:
npx shadcn@latest add https://your-domain.vercel.app/r/organisation-unit-tree.jsonAdvanced Features
Adding Multiple Components
To add more components to your registry, simply:
registry/default/ui/registry.jsonnpx shadcn build againv0.dev Integration
Create a link to open your component in v0.dev:
https://v0.dev?registry=https://your-domain.vercel.app/r/organisation-unit-tree.jsonConclusion
You now have your own component registry! Users can install your components with a simple command, and you can iterate and improve them over time.
Key benefits:
The OrganisationUnitTree component we built includes:
Start building your component library today and share it with the world!