Concept · client and server

Many clients, one server.

Every website and app you use is split in two. The client is the thing in your hand that asks. The server is a computer somewhere else that answers. We’ll use an app you already know, the debate rebuttal app, and follow what happens in the seconds after you press Generate rebuttal.

That form is the client side. Everything that happens after you press the button is the subject of this page.

The two roles

ClientYour browser showing the debate form. It asks: “give me the page”, “here is my speech, write a rebuttal”, “open that saved practice”. Every student’s browser is a separate client. They come and go.
ServerThe debate app’s code, running as a Cloudflare Worker. It answers. It holds the OpenAI key, talks to the database and to OpenAI, and sends back the finished rebuttal.

They never share memory. The only thing that crosses between them is a message, an HTTP request, and the message that comes back, an HTTP response.

The picture

Client–server architectureSix clients on the left send requests across the internet to one server. The server talks to a database and to the OpenAI API on the right.THE INTERNETAna · con caseBen · on a busChen · coachDee · pro caseEli · saved one>_curl · a scriptCLIENTS · as many as you likeServeryour code + API keySQLHTTPSDatabaseusers, messagesOpenAI APIthe LLM backendgenerates replies
Every student’s browser talks to the same debate-app server. No browser ever talks to the database or to OpenAI directly: only the server does, because only the server holds the keys.

Why put a server in the middle?

The life of one request

Ana is on the con side. She pastes her constructive (“We negate. Contention 1: Affordability and competition…”), picks Con, and presses Generate rebuttal. Here is everything that happens, in order. Step through it.

HTTP request life cycle: browser, DNS, server, database, OpenAIBrowserthe clientDNSthe phone bookServeryour codeDatabaseremembersOpenAIthe LLMwhere is debate-app…workers.dev?1a Cloudflare IP address2connect (TLS 🔒 only on https://)3POST /?/generate topic, side, draft4check the form5resolution + your speech + API key6rebuttal + why each point weakens7INSERT practice (topic, side, …)8saved, id = ba60ccb1…9200 OK the rebuttal10show the rebuttal11
Step 1 of 11 Look up the address

You clicked Generate rebuttal. The browser knows the name debate-app.debate-app.workers.dev, but computers find each other by number (an IP address). It asks DNS, the internet’s phone book. (It already did this when the page first loaded, so this time the answer is remembered and the step is skipped.)

Solid arrows are requests, dashed arrows are answers. Notice that the server is in the middle of almost every line, and that the one slow arrow is OpenAI writing the speech.

What the request actually looks like

HTTP is just text. This is step 4, roughly what leaves Ana’s browser when she presses the button. The three form fields travel in the body, exactly as they are named in the form:

HTTP request · browser → server
POST /?/generate HTTP/1.1
Host: debate-app.debate-app.workers.dev
Content-Type: application/x-www-form-urlencoded

topic=Should+major+economies+prioritize+domestic+energy+independence…
&side=con
&draft=We+negate.+Contention+1%3A+Affordability+and+competition…

And step 10, the response that comes back:

HTTP response · server → browser
HTTP/1.1 200 OK
Content-Type: text/html

…You argued con. The reply is pro.
720 words, about 3:36–4:14 at 170–200 words per minute.
[the rebuttal speech, point by point, with why each one weakens your case]

The real app uses a little JavaScript, so the browser actually sends the same three fields packed slightly differently and gets the result back as data instead of a whole new page. The idea is identical: one request in, one response out. Open your browser’s developer tools (Network tab) on the debate app and press the button to watch it happen.

Every button is a request

Generating a rebuttal is the big one, but everything you do in the debate app is a request of its own. Notice which ones need OpenAI and which only need the database:

Open the appGET /serverdatabaseLoads the form, plus the Saved practices list read from the database.
Press Generate rebuttalPOST /?/generateserverOpenAIdatabaseThe walk-through above. Slow (seconds), costs money.
Click a saved practiceGET /?task=ba60ccb1…serverdatabaseReads that practice back by its id. No OpenAI: the rebuttal was already written and saved, so it’s instant and free.
Delete this practicePOST /?/deleteserverdatabaseRemoves the row. It disappears from everyone’s list.

The ?task=… in the address bar is the id the database gave the practice in step 9. Copy that link to a friend and their browser sends the same GET; the server looks up the same row; they see the same rebuttal.

The server’s side, in code

The debate app is built with SvelteKit, the same tool as this site. Its server side could look something like this sketch (not the app’s actual code, but the same shape). You won’t write this by hand: you’ll ask your agent for it. But now you can read what it wrote.

src/routes/+page.server.js · a sketch
import OpenAI from 'openai';
import { fail } from '@sveltejs/kit';

// GET /  and  GET /?task=…  : only the database
export async function load({ url, platform }) {
  const db = platform.env.DB;
  const tasks = await db.prepare('SELECT id, topic, student_side FROM tasks ORDER BY created_at DESC').all();
  const id = url.searchParams.get('task');
  const selected = id ? await db.prepare('SELECT * FROM tasks WHERE id = ?').bind(id).first() : null;
  return { tasks: tasks.results, selected };
}

export const actions = {
  // POST /?/generate
  generate: async ({ request, platform }) => {
    const form = await request.formData();                       // 4  read the request
    const topic = form.get('topic'), side = form.get('side'), draft = form.get('draft');
    if (!topic || !draft || !['pro', 'con'].includes(side))      // 5  check the form
      return fail(400, { error: 'Fill in every field.' });

    const openai = new OpenAI({ apiKey: platform.env.OPENAI_API_KEY }); // key stays here
    const ai = await openai.responses.create({                   // 6–7 call the LLM
      model: 'gpt-5-mini',
      input: `Resolution: ${topic}\nThe student argued ${side}. Their constructive:\n${draft}\n\n` +
             `Write the opposing rebuttal. Answer the claims they actually made.`,
    });

    const id = crypto.randomUUID();
    await platform.env.DB                                        // 8–9 save it
      .prepare('INSERT INTO tasks (id, topic, student_side, draft, speech, created_at) VALUES (?, ?, ?, ?, ?, ?)')
      .bind(id, topic, side, draft, ai.output_text, new Date().toISOString())
      .run();

    return { id, speech: ai.output_text };                       // 10 the response
  },

  // POST /?/delete
  delete: async ({ request, platform }) => {
    const id = (await request.formData()).get('id');
    await platform.env.DB.prepare('DELETE FROM tasks WHERE id = ?').bind(id).run();
  },
};

Many clients at once

While Ana waits for her rebuttal, Dee is generating one for the pro side, Eli is opening a saved practice on the bus, and a whole debate class may be pressing the button at once. The server handles each request on its own: it doesn’t remember Ana between requests, which is exactly why it can serve a whole class (or thousands of people). Everything that must be remembered goes into the database; the clever part, writing the speech, comes from OpenAI; the server is the traffic controller in the middle.

Say it to your agent“Add a ‘judge’s ballot’ button to the debate app. It sends POST /?/judge with the task id; the server loads that practice from the database, asks OpenAI who won and why, saves the ballot next to the practice, and returns it. Keep the API key in a secret, never in the browser.” Now you know what every word means.