How jordanliu/themecn works
Project Type and Purpose
• This is a Next.js 13+ full-stack web application (app router) whose primary function is an interactive “theme studio” for generating, previewing, sharing, and importing/exporting design themes targeting the shadcn/ui component library.
High-Level Components
a. Client (Browser) – React components under /app & /components + CSS/JS bundles
b. Next.js Server – Server-side rendering, routing, and API endpoints under /app/api/registry
c. Data Store – Simple JSON (“app/dashboard/data.json”) for registry; URL-encoded theme state for shareable links
d. Static Assets – /public folder (images, open-graph)
Relationships & Data Flow
1. Browser requests page → Next.js server performs SSR or SSG → delivers HTML + JS bundles
2. Client React tree hydrates; ThemeProvider (in app/layout.tsx) reads theme settings from:
• URL query (encoded via lib/theme-url.ts)
• Local store (lib/store.ts)
4. UI updates client state; Live preview updates CSS variables (via globals.css and React custom hooks)
5. For “Share” or “Registry” features:
• “Share” encodes theme in URL → updated URL shown in UI
• “Registry” POST/GET calls Next.js API at /api/registry/[id]/route.ts → reads/writes data.json → returns stored themes
Architectural Patterns & Principles
• Componentized UI (shadcn/ui + custom React components)
• Server-Client separation via Next.js App Router (React Server Components vs Client Components)
• API-driven data persistence (flat JSON store; easily swap for database)
• CSS-in-JS / CSS Variables for real-time theming
• URL-first state sharing (no server sessions required)