Anatomy of a Web App
Frontend, backend, database - the map you need before building anything.
Before this: Git Through Your Agent
Objective
Explain how a web app's pieces fit together - browser, server, database - and trace what happens when a user clicks a button, using the words request, response and JSON precisely.
Vocabulary
The words to use when directing your agent.
- frontend
- The part of an app that runs in the user's browser - what they see and click.
- backend
- The part running on a server - logic, secrets, and the door to the database.
- database
- Software that remembers data permanently, organized for fast retrieval.
- HTTP request
- The message a browser sends a server asking for data or an action.
- HTTP response
- The server's reply - data, or an error code.
- JSON
- The text format almost all APIs use to exchange structured data.
Understand it
Why the split exists
The frontend must be fast and pretty; the backend must be trustworthy and secret-keeping; the database must remember. Different jobs, different layers. When your agent proposes putting a secret in frontend code, this map tells you why that is wrong.
Status codes are the truth serum
200 means ok, 404 means nothing there, 500 means the server broke. Agents and browsers both lie less than status codes. Checking the status code is how you verify 'it works' claims.
Core concepts
The three-layer map
Browser (frontend) talks to a server (backend), which talks to a database. Data flows as requests and responses. Every app you use - from a blog to a bank - fits this map; complexity hides in the details, not in extra layers.
The request-response cycle
Click a button and the browser may send a request: 'create this expense'. The backend validates it, touches the database, and responds: success plus the saved record, or an error code. Tracing this cycle is debugging skill number one.
Examples
Loading a page
Browser asks the server for the page; server returns HTML; browser requests the styles and scripts referenced; each comes back with a status code. That cascade happens in under a second.
Saving a todo
Submit sends a POST request carrying JSON; backend saves to database; response confirms. Refresh the page - the todo survives because it lives in the database now, not in your browser tab.
Common mistakes
Common mistake
Thinking the browser 'contains' the data.
Fix
Browser tabs hold copies. Truth lives behind responses. If data matters, it belongs in a database.
Common mistake
Trusting 'it works' without checking the network layer.
Fix
Ask your agent to show the actual request and response - URL, status code, body - for any feature that talks to a server.
Working with your AI agent
New superpower: when a feature misbehaves, ask your agent to 'trace this interaction end to end - which request fires, what status came back, what did the server log?' You are asking for the cycle, not vibes.
Build it
The module’s real project. Your agent builds; you direct and inspect.
Project: Anatomy Lab
With your agent, build a tiny local web page that demonstrates its own existence: it displays its request-response story live - a button triggers a fetch to a free no-key API and shows the raw request URL, the returned status code and a snippet of the JSON response.
Requirements
- Single page runs locally with a simple start command
- One button performs a real HTTP request to https://api.open-meteo.com (no key needed)
- Page displays: the requested URL, the returned status code, and formatted sample JSON from the response
- A short section on the page explains the three-layer map in your own words
Context for your agent
Build a minimal local web app: one page, one button. On click, fetch current weather for a hardcoded city from api.open-meteo.com (free, keyless). Display the request URL, HTTP status code and a formatted excerpt of the JSON response in monospace text. Include a short human-written section explaining the frontend-backend-database map. Keep styling minimal; prioritize clarity over beauty.
Verify it - twice
Check every item yourself first. Then hand your agent the prompt and compare verdicts.
Verification prompt - paste into your AI agent
Review my Anatomy Lab app as a senior engineer. Verify with evidence, PASS or FAIL each: (1) one-command local start, (2) button triggers a genuine fetch to api.open-meteo.com with no API key involved, (3) request URL, status code and JSON excerpt render after click, (4) offline click produces a visible handled error rather than silence, (5) no secrets anywhere in the code. Then trace one full button-click interaction end to end - naming the request, the response status, and where each piece of displayed data came from.
Run this against “Anatomy of a Web App” after your own checklist pass. Where the agent and you disagree, investigate before moving on.
Review questions
Answer out loud. If you cannot, revisit before moving on.
Trace what happens from button press to screen update in your Anatomy Lab.
Where should a password check happen - frontend or backend - and why?
What does a 404 status code tell you that a blank screen does not?
You can now
- Map any app onto the frontend-backend-database picture
- Trace a click through request and response
- Verify behavior with status codes instead of trusting appearances
Up next
Components and User Interfaces