How ibelick/prompt-kit works
Project Type and Purpose
• A Next.js-based documentation and demo site for an AI UI component library (“prompt-kit”).
• Combines static docs (MDX), dynamic demo pages, and serverless API routes to prototype/chat with LLMs.
• Ships as a customizable React/TypeScript component suite built on top of shadcn/ui.
File Structure Analysis
• Top-level “app” directory: Next.js 13 App Router pages, layouts, dynamic routes ([slug]), MDX docs under app/docs.
• app/api: serverless functions for “demo” and “primitives” (chatbot & tool-calling).
• components/*: library of reusable React components (grouped by feature: ui primitives, prompt-kit facades, demo helpers, blocks).
• lib + hooks: shared utilities, code-rendering, API-key handling, viewport helpers.
• scripts: Node scripts generating JSON registries and LLM lists, feeding build-time data into the site.
• public: static assets (images, JSON schemas) served directly.
• Config files: Next.js, Tailwind/PostCSS, ESLint, TypeScript.
Key Insights from README
• Exposes prompt-kit components via npx shadcn add prompt-kit/....
• Focus is on composable chat UIs, file-upload, code previews, streaming responses, etc.
• No traditional database—state is ephemeral in serverless routes or in-browser.
Main Components
a. Client (Browser)
– Renders React pages (SSG/SSR) and components.
– Invokes demo pages and interactive primitives.
b. Next.js Server (Node.js Lambdas)
– Routes under app/ handle SSR and SSG of MDX pages, dynamic route params.
– API endpoints (/api/demo/*, /api/primitives/*) proxy or orchestrate calls to external LLM services.
c. External LLM Services
– OpenAI, ChatGPT, MistralAI, or custom LLMs (configured via lib + scripts).
d. Static Asset Store (CDN)
– public/ folder serves JSON schemas and images.
e. Build & Registry Pipeline
– scripts/registry-*.ts and generate-llms-txt.js produce JSON/text files in public/ at build time.
f. Component Library
– components/prompt-kit (the public API), wrapping lower-level components/ui and components/primitives.
– Used both in docs examples and intended for consumer projects.
Relationships and Data Flows
• User ➔ Browser: requests page (docs, demo, component preview).
• Browser ➔ Next.js Server: SSR/SSG page generation or client-side navigation.
• Next.js Server ➔ External LLMs: via API routes when user interacts (e.g., chat).
• Build Scripts ➔ Public Assets: inject LLM lists and component registries consumed by the site.
• Browser ➔ CDN: fetch static JSON schemas and OpenGraph images.
Architectural Patterns & Principles
• “File-based Routing” with App Router (Next.js 13).
• Component-driven development: atomic UI → primitives → composite prompt-kit.
• ISR/SSG for docs, on-demand SSR for dynamic pages.
• Serverless functions for external HTTP calls (decoupled from UI).
• Build-time code generation for registry and LLM support lists.