chaidocs
AI Pitch Deck

Architecture

Suraj Kumar Jha 6 pages 2 min read Updated Sep 7, 2026
On this page
  1. The 10-Minute Pitch Deck Problem
  2. Instant ACK, Poll in Background
  3. Layer 3: Reliable Background Queues
  4. Layer 4A: Structured Slides Generation
  5. Layer 4B: Parallel AI Asset Delivery
  6. Layer 5: Relational Persistence and Delivery

The 10-Minute Pitch Deck Problem

01 On the left, a single user laptop box labeled 'Founder (Bengaluru)'. An arrow points right to a server box labeled 'Next.js App Server'. Inside the server box, a red skull icon with text 'Request Timeout > 30s'. A dashed cross mark shows the connection dropping back to the laptop with an error badge '504 Gateway Timeout'.
Notes
Imagine entering your D2C chai startup idea on a website, but waiting 45 seconds for a single page reload causes your browser to time out and crash. Generating text, structured slides, and 6 custom marketing images takes over 30 seconds of heavy AI work. If your Next.js server blocks on this single request like an IRCTC Tatkal queue at 10:00 AM, the server crashes and the user sees a blank screen. To fix this, modern web apps break long workflows into immediate responses and resilient background pipelines.

Instant ACK, Poll in Background

02 A two-layer vertical flow. Top layer shows 'Next.js UI' with two browser windows: 'CreateDeckForm' sending a quick arrow to 'POST /api/decks' (labeled '40ms return id'), and 'DeckViewer' sending a looping circular arrow labeled 'Poll every 3s' to 'GET /api/decks/[id]'. Below it, a status tracker line displays 4 pills in sequence: 'PENDING', 'GENERATING', 'COMPLETE', and a separate red pill for 'FAILED'.
Notes
When a founder submits an idea like 'Zepto for pet care in Koramangala', Layer 1 and 2 don't wait for AI to finish. The POST /api/decks endpoint inserts a blank deck record with status 'PENDING' into the database and returns a deck ID in under 40 milliseconds. The Next.js frontend immediately redirects to /decks/[id] and polls the GET /api/decks/[id] endpoint every 3 seconds. A clean status pill flips between four distinct states: PENDING, GENERATING, COMPLETE, or FAILED.

Layer 3: Reliable Background Queues

03 A central pipeline diagram showing 7 connected rectangular boxes arranged horizontally inside a large boundary labeled 'Inngest Background Job (generate-deck)'. Left to right arrows connect: 'load-deck' → 'mark-generating' → 'run-agent' → 'save-title' → 'image-1..N' → 'save-slide-1..N' → 'mark-complete'. Above 'image-1..N', a curved rewind arrow is marked 'Step-level Retry (prevents 0 to 1 restarts)'.
Notes
Traditional servers drop jobs if they crash mid-way, but an event queue like Inngest handles heavy lifting safely. When POST /api/decks completes, it dispatches an event 'deck/generate' containing the deckId to an Inngest background worker. The job pipeline executes 7 discrete atomic steps: load-deck, mark-generating, run-agent, save-title, image-generation, save-slides, and mark-complete. If slide 4 image generation fails mid-way, Inngest retries only that specific step instead of regenerating the entire deck from scratch.

Layer 4A: Structured Slides Generation

04 A horizontal sequence box labeled 'Branch A: Text Agent'. Left side shows an input card 'Raw Idea' flowing through a filter box labeled 'Guardrail (length >= 20 chars)'. This points to a central box labeled 'OpenAI Agent (PitchDeckSchema / Zod)'. It outputs a structured JSON document icon showing 3 visible slide blocks, each clearly divided into 'Title', 'Content', and 'ImagePrompt'.
Notes
The background job invokes the OpenAI Agents SDK to transform a raw text prompt into structured presentation slides. First, an input guardrail rejects any startup idea under 20 characters, blocking low-effort submissions like 'make money app'. Next, a Zod schema enforces exact output JSON: a deckTitle plus an array of 5 to 8 slides, each containing a slide title, body copy, and a detailed imagePrompt. A dedicated quality checker agent reviews the draft before saving, preventing hallucinated nonsense or broken layouts.

Layer 4B: Parallel AI Asset Delivery

05 A horizontal pipeline labeled 'Branch B: Media Flow'. On the left, 3 stacked slide cards each pass an 'imagePrompt' arrow into a box labeled 'OpenAI gpt-image-1-mini (Generates PNG)'. The PNG output arrow points into an 'ImageKit Cloud CDN' box labeled 'Upload to /pitch-decks'. An output arrow labeled 'https://ik.imagekit.io/...' exits to the right.
Notes
Text is only half the battle; investors want visual pitch decks with branding and product mockups. Branch B takes the imagePrompt from each of the 6 slides and calls OpenAI's gpt-image-1-mini in parallel. OpenAI generates the raw PNG image, but storing heavy image blobs in a transactional database slows queries to a crawl. Instead, the app streams the PNG straight to ImageKit CDN into a '/pitch-decks' folder and saves only the lightweight CDN URL.

Layer 5: Relational Persistence and Delivery

06 Left side shows an ER diagram with two database tables: 'Deck' (columns: id, idea, status) connected by a 1-to-Many fork arrow to 'Slide' (columns: id, deckId, order, title, imageUrl). Right side shows an arrow pointing up from Neon Postgres into a polished browser box labeled 'DeckViewer Carousel', displaying slide cards with a large image and text bullets.
Notes
All generated content converges in Neon Postgres via the Prisma ORM client across two related models. The Deck table stores metadata: deckId, raw idea, title, and status ('GENERATING' to 'COMPLETE'). The Slide table holds a 1-to-many relationship: order number, slide title, content bullet points, and the final ImageKit CDN URL. Once marked 'COMPLETE', the next 3-second poll from the user's browser fetches all 6 populated slides and reveals an interactive carousel.