The three tiers of a web application
A web application is split into three parts, called tiers. Each tier has one job and runs in a different place.
After you tap Place order in a food delivery app, the screen changes to Order confirmed and lists an order number, your two items and the total. The order number did not exist a moment ago. Several programs on different computers worked together to produce this screen.
Every web application has these three tiers. Read the cards from left to right: the user's device, your server, then the database.
The browser
Shows the page or app screen. Runs on the user's device, which you do not control.
The application server
Applies the rules and holds the database password. Runs on your server.
The database
Stores the data in tables. Only the application server may ask it questions.
More detail
Each tier is built with different tools. A framework is a ready-made toolkit for building the application tier. Pick one to see what you would write and where each tier runs. The steps a request takes are the same in every framework.
Press Play and watch one tap on View order travel through the three tiers and back.
Show the code
More detail
Look at the same part in two other ways: as the page's tree of elements, or as the user sees it.
Suppose the browser could talk to the database directly. The database password would then sit in code on the user's device, where anyone can read it and run any query, including one that lists every user's orders. So only the application tier holds the password, and it decides which requests the database may answer.
You can now say which tier should hold the database password and why.
More detail
AI tools can write much of this code for you. You still need to know where each tier runs and what passes between them, because that tells you where a check must happen. The browser is on a device the user controls, so a check made only there can be skipped.