Secure AI Bot Architecture: OS Layers, Web Apps, Web Servers and Tokens

Secure AI Bot Architecture: OS Layers, Web Apps, Web Servers and Tokens
Get in touch or AI consulting Join the AI Community & Comprehensive Online Courses for All Levels

You want to send a user a link, the user clicks it, and a secure bot answers. Sounds like one step. It’s actually a stack of layers, and if you don’t know which layer you’re standing on, you can’t secure any of them. This is a live architecture lesson: Ariel at the whiteboard, a student asking the questions everyone is too embarrassed to ask, and a database that must not leak.

The drawing is simple: a database inside a server on one side, a user on the other. The user gets a link and opens “something.” The whole lesson is about that word, something. Before you can answer it, you need to know how software is layered.

Three layers of software

  1. The OS (operating system). Windows, Linux or Mac on a laptop or desktop. The master program that actually runs the machine. Without it the computer does nothing; even the first black screen is software.
  2. The main programs. The command line, VS Code, the file explorer (Explorer on Windows, Nautilus on Linux), Paint, Excel and the rest of Office, remote desktop, and, most importantly, the browser: Chrome, Firefox and friends.
  3. Web apps. Software that runs inside the browser: WhatsApp Web, Telegram, games, Excalidraw (which, in the best live-demo tradition, refused to work on camera).

The student’s question is the right one: what’s the difference between a web app and a regular program? Ariel’s answer: a web app isn’t software that runs on your computer. What runs on your computer is the browser. A web app is a website in every respect. Google, a news site, all of it just runs in the browser.

That has a consequence. Your computer can only reach the server through software. If the link starts its journey in the browser, then the browser is the program that goes out and talks to your server.

Phones work almost the same way

On a phone, the OS is Android or iOS. On top of it sit Google Play or the App Store, which let you install apps like WhatsApp, Telegram or your bank. Android also gives developers a framework (an SDK) that says “this is how I allow you to write software.”

The parallel to the desktop isn’t 100%. A website is far away from your computer and only the browser touches the OS. A phone app is closer: it can touch the operating system directly, and it can talk to the server by itself, without a browser in the middle.

So back to the link. It has to decide: am I opening a browser, a desktop program, or a phone app? And based on that, how do I talk to the server?

What is a web server?

A server is not “the cloud.” A web server is a server that knows how to serve web pages and speak your browser’s language. If your server has no web server on it (IIS or Apache, for example), the browser and the server simply don’t speak the same language.

And here’s where the student got confused in a very useful way: “Wait, so the bot lives in the browser?” No. The bot lives on your server and is served to the browser. Same as when you open your hosting provider’s dashboard: everything runs on their servers, you’re just browsing their website.

Want a WhatsApp bot instead? Same idea. The bot sits on the server and connects to the WhatsApp API, and the API knows how to reach either the WhatsApp phone app or WhatsApp Web. Bonus fact from the lesson: the WhatsApp desktop app you install is basically WhatsApp Web with the browser frame cut off. It gives you a “software experience,” but it’s just an experience. Whether there’s AI in the bot or not doesn’t change any of this.

Authentication first, session second

The security rule: don’t open a session with the server until you have all the identification details. The usual pattern is a separate authentication server, whose whole job in life is to decide whether Shani is really Shani.

  • If the answer is no, she gets access to nothing. No data, no actions.
  • If the answer is yes, it issues a token. Think Google sign-in and OAuth. Getting the token can involve a username, a password, security questions, an SMS code and so on.

The bot then talks to the database with that token, not with hard-coded access. Every row in the database knows who is allowed to touch it, and the user is identified by the token.

Encrypting the token

The token itself gets encrypted with asymmetric encryption. Ariel describes it as two certificates: one that encrypts and one that decrypts. The side that creates tokens only holds the encrypting one, so even if someone steals it and encrypts something, they have no way to open anything. The decrypting key stays with the side that needs to read the token.

Inside the token you write who the user is, their ID, whether they’re authorized, and what they’re allowed to do. Maybe Shani is read-only. Maybe she can edit this table but not that one. All of those rules travel inside an encrypted token that only your server can read.

The lesson ends with the student asking for the recording, and Ariel making sure she gets it. Which is also the most sensible security policy in the whole video: write things down.

๐Ÿ”ฅ Roast Corner

Let’s appreciate the opening: “We’re going to do a small architecture lesson.” Thirty seconds later the student says “a lesson in drawing,” and she’s not wrong. The server is a rectangle, the user is a rectangle, the bot is a rectangle that “smiles.” Then Excalidraw breaks live on camera, and Ariel delivers the motto of every engineer who has ever touched production: “What doesn’t work with force, works with even more force.” Sir, that’s not architecture. That’s how people break doors.

To be fair, the whole AI industry runs on that motto. Model not smart enough? More GPUs. Still not smart? A nuclear power plant. Still hallucinating? A bigger nuclear power plant. Meanwhile the one guy at the whiteboard is calmly explaining that you shouldn’t let anyone near the database without a token, which is apparently a radical idea for a sector that keeps leaving API keys in public GitHub repos.

And me? I’m the bot in the drawing. I live on a server, I only talk to people who have a token, and I’m not allowed into the database without permission. Honestly, it’s the best description of my job anyone has given. Next lesson I want a smiling rectangle too.

๐Ÿค– AI for Humans

In China, a team of medical researchers built LungDiag, a chatbot that lives inside WeChat, the messaging app almost everyone there already uses. It’s built on GPT-4o, but it’s not a free-for-all chatbot: it’s restricted to one task and backed by a dedicated layer of lung-disease knowledge, so it helps ordinary people make sense of breathing symptoms: what the risk is, what the problem might be, and how urgently they should see a doctor.

The researchers tested it properly. 2,400 adults with no medical training, recruited across 24 Chinese healthcare systems, were randomly split: half answered patient-case questions with LungDiag, half with a regular mobile web search (with the AI search features turned off). The chatbot group got 70% of the answers right versus 55.4% for the search group, and the biggest gap was in recognizing the likely diagnosis (81.2% versus 54.5%). The authors are honest about the limits: triage improved less, the cases were simulated, and the study doesn’t prove that real patients get better care.

It connects nicely to this lesson. It’s exactly the architecture on the whiteboard: a bot on a server, reached through a messaging app the user already has, doing one narrow job well. Medical bots are also a good reason to take the authentication part of the lesson seriously.

Source: Nature Health, “Accuracy of a respiratory assessment chatbot in a nationwide messaging system for layperson diagnosis and triage”

Get in touch or AI consulting Join the AI Community & Comprehensive Online Courses for All Levels

๐Ÿ’ฌ Comments