How grillsdev/grills works
Project Type & Purpose
• Full-stack, server-rendered web application built on Next.js (App Router) and TypeScript.
• Purpose: a “Your Own Gen UI Platform” that generates unstyled UI code via LLMs, previews it in a sandbox, and lets users copy-and-paste into their own projects.
• Key features: AI chat UI, code-generation sandbox (E2B), pluggable LLM backends, Drizzle/Cloudflare Hyperdrive DB, optional Redis, and Cloudflare Workers edge runtime.
Main Components
A. Client / Browser (React)
– Next.js pages & server components under src/app and src/components.
– UI sub-systems: Chat interface, Home/marketing pages, ShadCN-style unstyled components.
B. Next.js Server & API Layer
– App Router under src/app handles SSR/SSG and API endpoints under src/app/api (auth, completion, sandbox, theme).
– Middleware (src/middleware.ts) for auth checks.
C. E2B Sandbox Service
– e2b-nextjs-sandbox-template directory: Docker-based service that spins up a preview container of generated UI code.
– Controlled via a REST endpoint (src/app/api/sandbox/route.ts).
D. Database & ORM
– Postgres (LOCAL_DB_URL) managed via Drizzle ORM (drizzle.config.ts, drizzle.db.config.ts).
– Cloudflare Hyperdrive binding (wrangler.toml/jsonc) for production edge DB.
– Migrations & schema files under src/db.
E. Cache & Session Store (optional)
– Upstash Redis for caching, rate-limiting, session store (configured via .env).
F. External Services
– LLM providers (OpenAI, Anthropic, etc.) called from src/lib/fetchers.ts.
– OAuth (Google) and Better-Auth for user authentication.
– Cloudflare Workers runtime (via wrangler) for edge deployment.
Component Relationships & Data Flows
1. User Browser → Next.js Frontend
• Fetch SSR pages, static assets (public/*).
• Client-side React calls API routes.
2. Next.js API Routes → Business Logic
• Auth route invokes Better-Auth and/or Google OAuth.
• Completion routes call LLM fetchers, apply reasoning, store/retrieve chats in Postgres.
• Sandbox route triggers E2B service and streams sandbox progress to the client.
• Theme route persists user theme preferences in DB or Redis.
3. API → Database (Drizzle ORM)
• Reads/writes chat history, user models, theme settings.
• Migrations keep schema in sync.
4. API → External LLMs
• src/lib/fetchers.ts abstracts provider calls.
5. API → E2B Sandbox Service
• Launches preview containers via Docker; streams logs/status.
6. Deployment
• Next.js and API routes deployed as Cloudflare Workers (edge functions).
• Cloudflare Hyperdrive provides the Postgres binding at edge.
• Wrangler config manages local vs. production DB connections.
Important Architectural Patterns
• Server Components + Client Components (Next.js App Router)
• Serverless / Edge Functions (Cloudflare Workers)
• Micro-service for E2B sandbox (isolated Docker container)
• ORM + Migrations (Drizzle) with a hybrid local/postgres-edge strategy
• Pluggable adapters for LLM providers (strategy pattern in src/lib/fetchers.ts)