How serafimcloud/21st works
Project type and purpose
• 21st.dev is a full-stack, open-source registry and community platform for sharing React UI components.
• It combines a Next.js frontend (“apps/web”), a custom bundler service (“apps/backend”), serverless database functions (under “supabase/functions”), shared UI/config packages, and external services for auth, storage, billing, and analytics.
File structure
• Top-level “apps” directory:
• apps/web – Next.js 14 application with pages, API routes, UI components, hooks, lib and config.
• apps/backend – A Bun-based microservice that handles bundling, CSS processing, video conversion, and R2 uploads.
• “supabase/functions”: Deno-based serverless functions for embedding, search, notifications, etc.
• “packages”: shared ESLint/TS configs and a UI component library.
• Additional scripts for embedding demos, backups, and database seeds.
README architecture section
• Frontend: Next.js 14
• Database: Supabase (PostgreSQL + edge functions)
• Auth: Clerk
• File storage: Cloudflare R2
• Analytics: Amplitude
• Billing: Stripe
a. Frontend (apps/web)
• Next.js pages & API routes
• Sandpack in-browser editor
• Client components and static assets
b. Backend bundler service (apps/backend)
• HTTP entrypoint (serve.ts)
• Bundler layer (Vite integration)
• CSS processor, video converter
• R2 upload module
c. Database & serverless functions (Supabase)
• PostgreSQL metadata store
• Edge functions under “supabase/functions”
d. Shared packages
• UI primitives (packages/ui)
• Config libraries (packages/*-config)
e. External services
• Clerk for authentication
• Cloudflare R2 for code/video storage
• Stripe for subscription/billing
• Amplitude for analytics
Relationships and data-flow
• User → Next.js frontend
• Frontend ↔ Supabase (auth, data, edge functions)
• Frontend ↔ apps/backend bundler API
• apps/backend → Cloudflare R2 (storage)
• Supabase edge functions → Supabase DB & R2
• Frontend & backend emit events to Amplitude
• Frontend listens for Stripe webhooks (via API routes)
Architectural patterns and principles
• Monorepo with turbo/pnpm workspace – shares code, configs, and types.
• Server-side rendering + API routes in Next.js for public and protected content.
• Dedicated microservice for bundling to isolate long-running tasks.
• Supabase edge functions for lightweight serverless logic co-located with the DB.
• External auth (Clerk) and billing (Stripe) rather than rolling your own.
• Storage-as-a-service (Cloudflare R2) for large assets.
Essential details
• Monorepo structure and code sharing packages/ui & config.
• Where environment variables (Clerk keys, R2 credentials) feed into apps/web and apps/backend.
• Third-party webhooks (Stripe webhook routes).
• Call out analytics events path (frontend → Amplitude).