How netmods/drapes-ui works
Project type and purpose
• This is a Next.js (React + TypeScript) “full-stack” UI library and demo site named Drapes-UI.
• It provides an interactive catalog of customizable, shader-driven canvas backgrounds, live previews, code-snippet generation, and a favorites system.
• It also includes a GitHub Action that programmatically generates and saves thumbnail images for each background.
File structure
• Top-level folders
– app/: Next.js App Router routes (/, /bg, /test).
– backgrounds/: One folder per background effect (config + React/TSX entry), plus two helper scripts (generate-code.ts, generate-index.ts).
– components/: Reusable UI and layout atoms/molecules (layout, navbar, palette, sliders, toggles, etc.).
– hooks/: Custom React hooks (local storage, media queries).
– lib/: Utilities (analytics, registry loader, GitHub integrations, types, helpers).
– actions/: Node script for GitHub Action (saveThumbnail.ts).
– public/: Static assets (videos, manifest, pre-generated thumbnails).
• Config and build files: next.config.ts, proxy.ts (dev proxy), tsconfig.json, postcss.config.mjs.
• Package and workspace management: package.json, pnpm-lock.yaml, pnpm-workspace.yaml.
README for additional insights
• Confirms the interactive preview and code-copy flows.
• Mentions zero external deps (pure canvas + WebGL).
• Describes the “favorites” system (likely persisted client-side).
• Describes the GitHub Action workflow for thumbnails.
Main components
a. Next.js Server / Build Pipeline
– App Router handing SSR/SSG endpoints (app/page.tsx, app/bg/page.tsx, app/test/*.tsx).
– Dynamic import via lib/registry.ts of background modules.
– Static file serving from public/.
– proxy.ts for any dev-time API proxy routes.
– GitHub Action runner that invokes actions/saveThumbnail.ts on CI.
b. Browser Client (React)
– UI components (components/ui and components/layout).
– Canvas Background Engine (dynamically loaded from backgrounds/*).
– Control Panel & Code Snippet Generator components.
– State management via hooks/use-local-storage and hook state (favorites, settings).
– Analytics events via lib/analytics.ts.
c. Background Registry & Modules
– backgrounds/registry.config.ts ← maps effect names to config + component.
– backgrounds/*/config.ts + index.tsx defining each shader/canvas effect.
d. Persistence & Assets
– localStorage in the browser for favorites.
– public/thumbnails & public/data assets.
e. CI/CD / GitHub Action
– actions/saveThumbnail.ts runs headless to snapshot each background.
– Commits updated thumbnails back to the repo.
Relationships and interactions
• Browser → HTTP GET → Next.js Server → SSR/SSG pages + JSON listing (registry).
• On page load, Next.js injects the list of available backgrounds (via registry).
• User selects an effect → React loads the TSX module (code-split import) → initializes Canvas/GL.
• Control UI ↔ Canvas Engine: user changes settings → immediate re-render in the canvas.
• “Copy Code” action reads from registry + user settings → displays snippet.
• Favorites toggled → update via use-local-storage hook → persisted in browser storage.
• Analytics events fired client-side → POST to analytics endpoint (could be a 3rd-party or custom serverless function).
• On CI, GitHub Action checks out code → runs saveThumbnail.ts → uses headless Canvas to snapshot each background → updates public/thumbnails → commits.
Architectural patterns & design principles
• Module registry pattern for pluggable backgrounds.
• Atomic design in UI (atoms, molecules, layouts).
• Separation of concerns:
– UI logic in components/,
– Effect definitions in backgrounds/,
– Utility logic in lib/,
– Build/CI logic in actions/.
• SSR/SSG for marketing and SEO (Next.js App Router).
• Client-side hydration and code-splitting for performance.
• Hook-based state management, local persistence.