apps/v4/content/docs/registry/getting-started.mdx
This guide will walk you through the process of setting up your own component registry. It assumes you already have a project with components and would like to turn it into a registry.
If you're starting a new registry project, you can use the registry template as a starting point. We have already configured it for you.
You are free to design and host your custom registry as you see fit. The only requirement is that your registry items must be valid JSON files that conform to the registry-item schema specification.
If you'd like to see an example of a registry, we have a template project for you to use as a starting point.
The registry.json is the entry point for the registry. It contains the registry's name, homepage, and defines all the items present in the registry.
Your registry must have this file (or JSON payload) present at the root of the registry endpoint. The registry endpoint is the URL where your registry is hosted.
The shadcn CLI will automatically generate this file for you when you run the build command.
Create a registry.json file in the root of your project. Your project can be a Next.js, Vite, Vue, Svelte, PHP or any other framework as long as it supports serving JSON over HTTP.
{
"$schema": "https://ui.shadcn.com/schema/registry.json",
"name": "acme",
"homepage": "https://acme.com",
"items": [
// ...
]
}
This registry.json file must conform to the registry schema specification.
Add your first component. Here's an example of a simple <HelloWorld /> component:
import { Button } from "@/components/ui/button"
export function HelloWorld() {
return <Button>Hello World</Button>
}
registry
└── new-york
└── hello-world
└── hello-world.tsx
To add your component to the registry, you need to add your component definition to registry.json.
{
"$schema": "https://ui.shadcn.com/schema/registry.json",
"name": "acme",
"homepage": "https://acme.com",
"items": [
{
"name": "hello-world",
"type": "registry:block",
"title": "Hello World",
"description": "A simple hello world component.",
"files": [
{
"path": "registry/new-york/hello-world/hello-world.tsx",
"type": "registry:component"
}
]
}
]
}
You define your registry item by adding a name, type, title, description and files.
For every file you add, you must specify the path and type of the file. The path is the relative path to the file from the root of your project. The type is the type of the file.
You can read more about the registry item schema and file types in the registry item schema docs.
npm install shadcn@latest
Add a registry:build script to your package.json file.
{
"scripts": {
"registry:build": "shadcn build"
}
}
Run the build script to generate the registry JSON files.
npm run registry:build
You can change the output directory by passing the --output option. See the shadcn build command for more information.
If you're running your registry on Next.js, you can now serve your registry by running the next server. The command might differ for other frameworks.
npm run dev
Your files will now be served at http://localhost:3000/r/[NAME].json eg. http://localhost:3000/r/hello-world.json.
To make your registry available to other developers, you can publish it by deploying your project to a public URL.
Here are some guidelines to follow when building components for a registry.
registry/[STYLE]/[NAME] directory. I'm using new-york as an example. It can be anything you want as long as it's nested under the registry directory.name, description, type and files.registryDependencies. A registry dependency is the name of the component in the registry eg. input, button, card, etc or a URL to a registry item eg. http://localhost:3000/r/editor.json.dependencies. A dependency is the name of the package in the registry eg. zod, sonner, etc. To set a version, you can use the name@version format eg. zod@^3.20.0.@/registry path. eg. import { HelloWorld } from "@/registry/new-york/hello-world/hello-world"components, hooks, lib directories.To install a registry item using the shadcn CLI, use the add command followed by the URL of the registry item.
npx shadcn@latest add http://localhost:3000/r/hello-world.json
See the Namespaced Registries docs for more information on how to install registry items from a namespaced registry.