Frontend vs Backend: What's the Difference?
Every app has a part that runs in your browser and a part that runs on a server. Knowing which is which explains why secret keys leak, why some apps need a server and others don't, and what your AI tool actually built. A plain-English guide with a restaurant analogy that actually holds up.
When people talk about building apps, two words come up constantly: frontend and backend. They're the two halves of almost every app, and understanding the difference answers a surprising number of beginner questions — like why your API key leaked, or why your app needs a server at all.
The restaurant analogy
Think of a restaurant.
- The dining room is the frontend. It's what customers see and touch: the menu, the tables, the waiter taking your order. It's designed to look good and be easy to use.
- The kitchen is the backend. Customers never go in there. It's where the real work happens: food is stored, recipes are followed, and decisions are made — like whether you've actually paid.
- The waiter carrying orders between them is the API. The dining room doesn't cook; it asks the kitchen, through a defined way of placing orders. (More on that in What Is an API?)
The frontend: what runs in the browser
The frontend is everything that runs on the user's device — in their web browser or phone. It's built with HTML (structure), CSS (style), and JavaScript (behaviour), often using tools like React, Vue, or Svelte.
The frontend:
- Shows pages, buttons, forms, and animations
- Responds when you click and type
- Sends requests to the backend and shows the results
The key fact: the frontend's code is downloaded to the visitor's computer. Anyone can open their browser's developer tools and read it. Nothing in the frontend is secret.
The backend: what runs on a server
The backend is code that runs on your server, which visitors never see directly. It's written in languages like JavaScript (Node.js), Python, PHP, Ruby, or Go.
The backend:
- Saves and loads data from the database
- Checks who's logged in and what they're allowed to do
- Takes payments
- Sends emails
- Calls other services — like an AI model — using secret keys
The key fact: backend code stays on the server. That's what makes it the right — and only — place for secrets and for decisions that matter.
Why this matters: three beginner mistakes it explains
1. "My API key got stolen"
If an API key is in the frontend, it's been sent to every visitor. Anyone can copy it. Secret keys must live in the backend. This is the single most common security mistake in AI-built apps — see How to Keep API Keys Out of an AI-Built App.
2. "I hid the admin button, so only admins can use it"
Hiding a button in the frontend is like hiding the kitchen door behind a curtain. Anyone who finds the door can walk in. The backend has to check whether each request is allowed. (Authentication vs Authorization explains this.)
3. "Someone paid one cent for my product"
If the frontend tells the backend how much to charge, a user can change the number. Prices must be decided by the backend. (The four rules for Stripe payments.)
The pattern: the frontend is for showing things; the backend is for deciding things.
Does every app need a backend?
No. Some apps are frontend-only:
- A portfolio or landing page.
- A calculator or tool that runs entirely in the browser.
- An app whose "backend" is a hosted service it talks to directly — many AI-built apps use Supabase or Firebase this way, relying on that service's security rules instead of their own server.
But you need a backend as soon as you want to:
- Use a secret key (payments, AI models, email)
- Enforce rules the user can't tamper with
- Run things on a schedule or in the background
"Full-stack" means both
You'll hear full-stack — it just means an app (or a developer) covering both frontend and backend. Frameworks like Next.js, Remix, SvelteKit, and Nuxt let you write both in one project, which is why AI tools love them. The code still splits into the part that runs in the browser and the part that runs on the server, even if it lives in the same folder. (What Is a Framework?)
How to tell what your AI tool built
Ask it directly:
Which parts of this app run in the browser, and which run on a server? Where are the secret keys stored? Is there any code that only runs on the server?
If the answer is "everything runs in the browser" and the app uses secret keys, that's the first thing to fix.
The summary
| Frontend | Backend | |
|---|---|---|
| Runs on | The visitor's device | Your server |
| Visible to users? | Yes — anyone can read it | No |
| Good for | Showing things, interactions | Data, rules, secrets, payments |
| Never put here | Secret keys, pricing decisions, permission checks | — |
EasySpawn runs both halves of your app — frontend and backend — with a managed database and secrets kept in server-side environment variables. See how it works for AI-built apps or join the waitlist.
Related: What Is Web Hosting? · What Is a Database? · HTML, CSS, and JavaScript Explained · Web App vs Mobile App
Keep reading
What Is an API? Explained Without the Jargon
APIs are how apps talk to each other — how your app takes a payment, sends an email, or asks an AI model a question. What an API actually is, what requests and responses look like, what an API key does, and the few terms you'll keep running into.
What Is a Webhook? Explained for Beginners
A webhook is how another service tells your app that something happened — a payment went through, a form was submitted, a file finished processing. How webhooks differ from normal API calls, what you need to receive one, and the three safety rules every webhook handler must follow.