Architecture1 min read
Designing a Scalable Component Registry Architecture in Next.js
How to structure metadata schemas, decouple live previews from source files, and implement dual-axis ordering for large-scale UI libraries.
D
Driss Bakhtaoui
Full-Stack Engineer
- Architecture
- Design Systems
- TypeScript
- Next.js
- Registry

Building a handful of reusable React components inside a single application is straightforward. Turning dozens—or hundreds—of interactive components into a fast, searchable, copy-paste registry like stash.ui requires deliberate architectural boundaries.
If source files, preview wrappers, and routing metadata are tightly coupled, bundle sizes balloon, build times degrade, and adding a single component becomes an error-prone chore.
The Three-Layer Registry Separation
A scalable UI registry separates each component into three distinct responsibilities so that browsing, previewing, and inspecting source code never block one another:
- Pure Source Files (
registry/components/): Self-contained, copy-paste-ready.tsxfiles with zero registry-specific wrappers or documentation boilerplate. - Isolated Preview Harness (
registry/previews/): Lightweight wrapper components that supply mock state, viewport constraints, or sample props needed to demonstrate the component in action. - Typed Metadata Manifest (
registry/categories/): Declarative TypeScript objects mapping slugs, dependencies, file paths, and lazy-loaded preview references.
registry/
├── types.ts # Strict ComponentItem contract
├── index.ts # Sorting, filtering & lookup selectors
├── categories/ # Domain-sliced manifests (heroes, cards, inputs...)
│ ├── heroes.ts
│ └── backgrounds.ts
├── components/ # Clean source code served to users
│ └── heroes/
│ └── gallery-marquee-hero.tsx
└── previews/ # Dynamic client sandboxes
└── heroes/
└── gallery-marquee-hero-preview.tsx