Frontend vs Backend: What's the Difference?
What the frontend and backend of an app are, how they differ, how they talk to each other and why AI calls and secret keys belong on the backend.
Short answer: the frontend is the part of an app you see and touch in the browser or on your phone, while the backend is the part running on a server that stores data, applies the rules and sends answers back. If you wonder what the backend is, think of a restaurant: the dining room is the frontend and the kitchen is the backend.
What Is the Frontend?
The frontend (also called the client side) is everything the user interacts with: layout, buttons, forms, colours, animations. For websites it is built with HTML for structure, CSS for style and JavaScript for behaviour. It runs on the user's own device.
What Is the Backend?
The backend (the server side) runs on computers you control. It receives requests from the frontend and does the work users never see:
Reading and writing data in a database
Checking who the user is and what they may do
Applying business rules, such as "an order needs at least one item"
Calling other services, including AI models, with secret keys that must stay hidden
Frontend vs Backend: What Is the Difference?
Point | Frontend | Backend |
|---|---|---|
Where it runs | User's browser or phone | A server |
Main job | Show things and collect input | Store data, enforce rules, do heavy work |
Typical tools | HTML, CSS, JavaScript | Python, JavaScript (Node.js), databases |
Can the user see the code? | Yes | No |
Secrets such as API keys | Never safe here | Kept here |
How Do They Work Together?
The frontend sends an HTTP request, the backend processes it and returns a response, usually JSON. This conversation is carried over an API. For example, when you press "Place order", the frontend sends a request such as POST /orders, the backend saves the order and replies with a status code and the new order's details, and the frontend shows "Order placed". The REST methods define the verbs used in these requests.
A Tiny Backend in Python
Here is a complete backend using only Python's standard library. Run it, then open http://127.0.0.1:8000/hello in a browser:
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
body = json.dumps({"message": "Hello from the backend", "path": self.path}).encode()
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
self.wfile.write(body)
if __name__ == "__main__":
HTTPServer(("127.0.0.1", 8000), Handler).serve_forever()
A frontend could call it with one line of JavaScript, fetch("http://127.0.0.1:8000/hello"), and show the message on the page. In real projects a framework such as FastAPI replaces this low-level code. The chapter What a backend does walks through requests, routes and responses step by step.
Where Does AI Fit In?
When an app uses a language model, the call to the model belongs in the backend. The backend holds the API key, adds the system prompt, limits usage and logs results. The frontend only shows the chat window.
Common Mistakes
Putting secrets in the frontend. Users can read frontend code, so a key placed there is public.
Trusting only frontend checks. Form validation in the browser is for convenience. The backend must validate again.
Thinking one is more important. Both are needed, and "full-stack" simply means working on both.
Key Takeaway
The frontend is what users see and use; the backend is the server that stores data, enforces rules and guards secrets. They talk through requests and responses, and AI calls belong on the backend. To learn how the web fits together, read How the web works.
Ready to start? You will build a real backend with FastAPI, test it and publish it with Git, step by step. Begin with the free course Git, APIs and Backend for AI: Beginner.
Related articles
More in APIs and Backend
How to Keep API Keys Safe: .env Files and Secrets
Keep API keys out of your code: use .env files and environment variables, ignore them in Git, and know exactly what to do if a key leaks.
4 min readNov 14, 2026HTTP Status Codes Explained: 200, 404, 500 and More
What HTTP status codes mean, from 200 and 404 to 500, how the five groups work and how your code should react to each.
4 min readNov 9, 2026What Is JSON and Why Do APIs and AI Use It?
JSON is a simple text format for structured data. See what it looks like, its data types, how to read it in Python, and why APIs and AI apps depend on it.
3 min readNov 6, 2026REST API Methods Explained: GET, POST, PUT, PATCH, DELETE
What each REST API method does, with a to-do list example, typical status codes, PUT vs PATCH, and what safe and idempotent mean.
4 min readNov 4, 2026What Are Git and GitHub? The Difference Explained
Git tracks your code's history on your computer; GitHub hosts it online for sharing and teamwork. Learn the difference, the key terms and your first commands.
4 min readNov 2, 2026What Is an API and How Does It Work?
An API explained with a restaurant analogy, then the real parts: endpoints, methods, JSON, status codes and API keys, with a small Python example.
4 min readOct 31, 2026
Comments
Sign in to join the discussion.

