--- title: Architecture collection: AI Pitch Deck author: Suraj Kumar Jha updated: 2026-09-07 source: https://docs.chaicode.com/ai-pitch-deck/architecture --- # Architecture ![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'.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/5cb4f6062996cd70e4cdddc4086e04003da2e114dafced289f816e39c98b6b48.png) The 10-Minute Pitch Deck Problem — 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. ![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'.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/935a1aeefb301bc153c5a3036668ec2eadf1a309a327c12cf2821a78749b393f.png) Instant ACK, Poll in Background — 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. ![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)'.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/dd81dbe86f1158a1bb5b58d3311961f78e16dd6d21fef84d9deae8b92cbddce2.png) Layer 3: Reliable Background Queues — 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. ![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'.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/015078b101846118a08c9689657c57819ee7ed31597b00f1b682647308336898.png) Layer 4A: Structured Slides Generation — 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. ![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.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/98bbd2cad3eaacbeb4501e6d28e051518bc601a39d7fb6e855b7e8cdd7d640d0.png) Layer 4B: Parallel AI Asset Delivery — 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. ![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.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/db6d887e40ece253eee3ba39291e4eff79ca2d1a7eb5ce41e9766350e62a08ba.png) Layer 5: Relational Persistence and Delivery — 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.