Overview
2026Generative AI & App EngineSTAR Case Study

AppForge

I built an AI app builder that compiles natural-language prompts into strict Zod-validated React component trees and isolated Postgres tables.

Ask Copilot morphs into the JSON builder to stream Zod-validated components into live preview.

81.4%
Full layout pass rate
92.8%
Component node validity
91
Lighthouse perf median
Full-Stack ArchitectMay 2026 to Nov 2026

Next.js 16, React 19, TypeScript, Groq / Gemini AI SDK, Upstash Redis, Supabase PostgreSQL, Clerk, Motion, Sentry, Tailwind CSS v4

SSituation

Raw LLM code generation breaks UIs and multi-tenant isolation

Streaming raw JSX from an LLM into an iframe fails on minor syntax hallucinations, exposes cross-site scripting risks, and stalls when primary inference keys hit rate limits. Earlier iterations also shipped unvalidated DDL helpers, an unused Upstash Kafka dependency, and a third-party shader library that inflated landing bundle weight.

Baseline constraints before the refactor
  • Executing model-written JSX with eval() causes white-screen crashes on malformed syntax
  • Mid-stream fallback between two LLMs corrupts JSON output by concatenating tokens from different models
  • Dynamic schema sync must never allow DROP TABLE, SQL injection, or cross-tenant table reads
  • Client bundle and main-thread motion must stay responsive under 50ms task budgets

Unchecked JSX eval() & Legacy DDL

Syntax & SQL Risk
Copilot & SchemaUnchecked AST
Unvalidated JSX + raw SQL strings
Fragile generation & DDL

Strict Zod AST & Parameterized DDL

81.4% Eval Pass
Pre-Chunk Failover92.8% valid nodes
format('%I') DDL + Clerk RLS (192 tests)
Zero eval() · Lighthouse 91

Unchecked JSX eval() versus strict Zod AST validation and tenant-isolated DDL.

TTask

Build a deterministic AST pipeline, harden multi-tenancy, and benchmark every layer

Redesign AppForge into a production-hardened runtime: enforce per-component Zod validation, guarantee atomic single-provider streams, lock down dynamic Postgres DDL and RLS, and measure reliability with an automated 100-prompt evaluation suite and 192 tests.

0 eval() calls + safe node fallback

Strict AST & Fallback Boundary

Validate every Header, Statistic, DataTable, Card, Grid, and ButtonAction node with .strict() Zod schemas and isolate malformed nodes in InvalidNodeFallback.

Groq primary → Gemini fallback

Pre-First-Chunk Multi-Provider Failover

Allow provider failover only before chunk #1 leaves the stream; lock the stream once committed and normalize cache keys in Upstash Redis.

192 tests (148 unit + 44 DB)

Parameterized DDL & Tenant RLS

Replace raw SQL string building with format('%I') identifiers, a strict column-type whitelist, removed DROP TABLE, and Clerk sub RLS policies.

AAction · Architecture & Implementation

Prompts stream into strict Zod trees and isolated Postgres schemas

Copilot normalizes prompts in Upstash Redis, streams through pre-first-chunk Groq/Gemini failover, validates every node against strict Zod schemas, and syncs tables via parameterized Supabase RPCs.

Architecture components
Hero & Native ShaderRenders domain-warped mesh & live config demo.
Redesigned AppForge landing hero with NativeMeshShader and live config-to-UI reactive preview.

Redesigned AppForge landing hero with NativeMeshShader and live config-to-UI reactive preview.

Explanatory figures & telemetry

Measured system behavior across benchmarks and fault injections

Figure 1

Copilot 100-Prompt Evaluation Suite (Groq openai/gpt-oss-120b)

Dashboards (19/19)100.0%

48/48 valid nodes · 1 prompt 429-limited

CRUD Interfaces (18/18)100.0%

46/46 valid nodes · 2 prompts 429-limited

Overall Non-429 (48/59)81.4%

141/152 valid nodes (92.8% node validity)

Forms (10/20)50.0%

41/50 valid nodes · includes 2 safety refusals

Settings (1/2)50.0%

6/8 valid nodes · 5 prompts 429-limited

Per-category full layout pass rates excluding HTTP 429 rate-limited prompts (59 completed of 67 attempted; 141/152 valid nodes overall). Source: EVALS.md.EVALS.md · scripts/run-evals.mjs
Figure 2

Pre-First-Chunk Failover & Strict Schema/DDL Gate

1. Ingress
POST /api/copilot

x-real-ip guest quota + Upstash normalized cache lookup

Instant stream on cache hit (7-day TTL)
2. Stream Gate
createCopilotStream()

Groq primary → Gemini 2.5 Flash failover ONLY pre-chunk #1

Zero cross-model token concatenation
3. AST Check
lib/validation.ts (.strict())

Per-component Zod parse + InvalidNodeFallback wrapper

92.8% valid nodes; 0 white-screen crashes
4. Schema Sync
execute_app_ddl RPC

format('%I') + type whitelist + (select auth.jwt()->>'sub') RLS

No DROP TABLE; strict tenant isolation
Fault path:
Mid-stream socket drop after chunk #1 → Lock out remaining providers & emit terminal error event → Client retries cleanly instead of parsing hybrid JSON
How Copilot prevents mixed-model JSON corruption while isolating per-node errors and securing dynamic Postgres table creation.lib/copilot-pipeline.ts · actions/schema.ts
Figure 3

UX Polish & Gate (b) Native Shader Performance Budget

Production Lighthouse Median (vs 88 baseline)91 / 100
Lighthouse Performance (3-run median: 94, 91, 90)

LCP 1.2s · CLS 0 · TBT 290ms (down from 340ms)

91 score(91%)
NativeMeshShader Control Delta (10-run median)

Domain-warped FBM fragment shader + KHR_parallel_shader_compile

1.00ms(5%)
Copilot Morph Max Main-Thread Task

0 long tasks > 50ms during layoutId pill-to-panel morph

23.98ms(4%)
Dependencies Removed3 packages

Dropped framer-motion, @paper-design/shaders-react, and Upstash Kafka.

Test Coverage192 tests

148 unit tests + 44 real Postgres RLS & cross-tenant isolation tests.

Logo & Theme Contrast>15:1

Inverted solid tile mark + View Transitions 450ms circular theme ripple.

Measured client runtime numbers after consolidating onto motion/react, removing framer-motion, and replacing @paper-design/shaders-react with NativeMeshShader.context/progress-tracker.md · Gate (b) & Lighthouse runs
Action · Trade-offs

Four architectural choices that hardened reliability and speed

Action · Bugs fixed

Four production bugs fixed during UX polish and hardening

Copilot floating panel collapsed to 28px inside Monaco container

7043f88
Symptom

Opening Copilot collapsed the dialog into an invisible 28px box clipped by overflow.

Cause

Panel used calc(100% - 32px) inside a 0-width containing block with overflow: hidden.

Fix

Moved CopilotFloatingPill to workspace root and sized with min(480px, calc(100vw - 32px)).

Motion bundle inflated landing page JS overhead

36e5b12
Symptom

Landing route shipped full Motion runtime solely for nav pill transitions.

Cause

Shared Navbar imported Motion primitives directly on the public landing page.

Fix

Replaced landing nav indicator with pure CSS sliding indicator and consolidated on motion/react.

Monaco swallowed pointer events during split-pane resize

b5507ee
Symptom

Dragging the builder divider stalled whenever the cursor crossed the Monaco iframe/canvas.

Cause

Custom divider lacked pointer capture isolation over Monaco and preview panes.

Fix

Migrated to react-resizable-panels with drag-state body cursor lock and transparent overlay.

Third-party Paper Shaders added compile overhead and license coupling

1bcf981
Symptom

Landing hero carried external shader bundle and PolyForm Shield notice.

Cause

Third-party React wrapper bundled extra shader plumbing on mount.

Fix

Implemented zero-dep NativeMeshShader with async parallel shader compilation (1.00ms median).

Copilot Layout Accuracy
Before:Unchecked JSX strings + legacy type-only check
After:81.4% full layout pass (100% Dashboards/CRUD) · 92.8% node validity
EVALS.md (Groq 120b)
Multi-Tenant Security
Before:Raw DDL strings & unguarded dev cookie bypass
After:format('%I') whitelist DDL + Clerk RLS + 44 DB tests passing
vitest --project database
Frontend Performance
Before:88 Lighthouse median + 340ms TBT + PolyForm shader dep
After:91 Lighthouse median + 290ms TBT + 1.00ms NativeMeshShader
context/progress-tracker.md
Roadmap

Introduce a strict Tailwind utility className sanitizer for public /apps/[appId] routes and re-run the 100-prompt eval suite under v1.4.0 .strict() schemas.