How nutlope/qrgpt works
Project Type and Purpose
• This is a full-stack web application built on Next.js (App Router) that lets users generate AI-powered QR codes in seconds.
• It combines a server-rendered/frontend UI with serverless API routes that call an external AI model (Replicate), and uses Vercel Blob and KV for storage and rate-limiting.
File Structure
• Top-level “app/” directory follows Next.js App Router:
– app/page.tsx: marketing/home page
– app/start/[id]/page.tsx & app/start/page.tsx: code-generation flow
– app/waitlist/page.tsx: waitlist signup
– app/api/generate/route.ts: serverless API endpoint
• “components/” contains UI primitives (Shadcn UI + custom components)
• “utils/” holds services & clients: ReplicateClient.ts, downloadQrCode.ts, env.ts, service.ts, types.ts
• Config files: next.config.js, postcss.config.js, tailwind.config.js, tsconfig.json
README Insights
• Tech Stack: Next.js App Router, Replicate (AI), Vercel Blob (image storage), Vercel KV (Redis-style storage + rate limiting), Shadcn UI
• Deployment on Vercel with environment variables for Replicate API key, KV namespace, Blob bucket
Main Components & Their Interactions
a. Client Browser (React/Next.js frontend)
b. Next.js Serverless Layer (app/api/generate)
c. External AI Service (Replicate)
d. Vercel Blob Storage (stores generated QR images)
e. Vercel KV Storage (stores usage counts, rate-limits, waitlist data)
f. Static Assets & UI Components
Interaction flow:
1. User clicks “Generate” on frontend → POST request to /api/generate.
2. Next.js route handler reads env (utils/env), checks rate-limit in KV (utils/service).
3. Handler invokes ReplicateClient (utils/ReplicateClient) → calls external Replicate API.
4. On image result, handler writes image to Vercel Blob → obtains Blob URL.
5. Handler persists any metadata or increments usage counters in Vercel KV.
6. Handler returns QR-code URL to frontend.
7. Frontend displays image (components/QrCard.tsx) and offers download (utils/downloadQrCode).
Architectural Patterns & Design Principles
• Serverless micro-endpoints (Next.js API routes)
• Separation of concerns: UI vs. service logic (utils folder)
• 12-factor app: environment config (example.env, env.ts)
• Component-based UI (Shadcn + custom)
• Scalability via external managed services (Replicate, Vercel Blob & KV)