Vibe Coding Foundations · Season 1 · Lesson 2
Language: English · 한국어
A number changing in the interface does not prove the server’s data has changed. The frontend handles what people see and touch; the backend handles requests and shared rules; a database is one way to persist records. These roles often work together, but a working button is not evidence that all three were involved.
One question guides this lesson: “Why does my page say a seat was claimed when nobody else sees that change?” The key skill is knowing where a result becomes authoritative.
1. Frontend, backend, and database are roles—not three mandatory machines
- Frontend: The user-facing interface and interaction. In the browser this commonly means HTML, CSS, and JavaScript.
- Backend: Receives a request, checks validity and permissions, applies shared rules, and returns a result.
- Database: One approach to storing and retrieving records that must survive beyond the current view.
A managed backend may include database services. A static website may need no application backend or database at all, even though a web server delivers its files. Choose what the product actually needs.
2. Trace the full round trip
- Browser: Someone clicks Claim a seat. The click may only trigger a local visual update.
- Request: The frontend sends the action to a backend. A click and a delivered request are different events.
- Decision and write: The backend checks authorization and availability and updates a record where needed.
- Response and display: The backend reports confirmed success or failure; the UI reflects what was actually confirmed.
Remember request → server-side decision → record change → response → UI. MDN explains the client/server exchange in its Client-server overview.
3. Where should state live? Ask three questions
Before asking an AI to “save this,” define scope, lifetime, and authority: who should see it, how long should it last, and which component is allowed to declare it true?
| Question | Page state | Browser storage | Shared record |
|---|---|---|---|
| Who can see it? | This page or tab | Usually this browser and origin | Authorized users and devices |
| How long does it last? | May reset with the page | Depends on user settings and storage | Depends on confirmed writes and retention rules |
| Who decides the truth? | Current UI | Local browser record | The service’s shared rules and persisted result |
An open dropdown belongs in page state. A personal note on one device may fit browser storage. Shared inventory or seat claims require an authoritative decision. localStorage does not automatically become a multi-user database.
4. Try a page that looks interactive but books nothing
The following is a complete, fictional learning demo: no account, package, API key, backend, or persistence. Create a plain text file named seat-demo.html (not .txt), paste the code, save it, and open it in a browser.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Practice Seat Counter</title>
<style>
body { font: 1rem/1.6 system-ui,sans-serif; max-width: 36rem;
margin: 3rem auto; padding: 0 1rem; }
button { padding: .7rem 1rem; margin: 0 .4rem .5rem 0; }
button:focus-visible { outline: 3px solid currentColor; }
</style>
</head>
<body>
<h1>Practice Seat Counter</h1>
<p>For learning only. No real booking or server storage.</p>
<p id="result" role="status" aria-live="polite"></p>
<button id="apply" type="button">Claim a seat</button>
<button id="reset" type="button">Reset this page</button>
<script>
let remaining = 2;
const result = document.querySelector('#result');
const apply = document.querySelector('#apply');
function render() {
result.textContent = 'Seats left in this tab: ' + remaining;
apply.disabled = remaining === 0;
}
apply.addEventListener('click', () => {
if (remaining > 0) remaining -= 1;
render();
});
document.querySelector('#reset').addEventListener('click', () => {
remaining = 2;
render();
});
render();
</script>
</body>
</html>
- In one tab, click Claim a seat. The count moves from 2 to 1; after two clicks the button disables.
- Open the same file in a new tab. The new tab still starts at 2. The tabs do not share their variables.
- Refresh the first tab. Its number returns to 2 because its JavaScript restarts.
- Reset this page only resets that tab. It does not undo any actual server-side reservation.
The variable remaining lives in each tab’s JavaScript memory. render() paints the value, and nothing is sent to a server. Renaming the message to “Booking complete” would not create a booking.
5. Four common false conclusions
- “The button works, so it saved.” It may have updated only the UI. Look for evidence of the intended write.
- “It survives refresh, so everyone sees it.” Browser storage is not automatically shared across accounts or devices.
- “The server returned success, so the database committed.” Poor backend code can respond too early. Verify the write and a subsequent read.
- “Show success immediately; handle errors later.” Optimistic UI must also handle rollback and failure messaging.
6. Ask the AI for an ownership contract, not a button
Weak prompt: “Make this button reserve a seat and save it.”
Better prompt: “Design a fictional two-seat claiming flow. Do not use a browser variable as the authority for shared capacity. The frontend should distinguish pending, success, and failure. Describe how a backend would check authorization and concurrent claims, confirm persistence, and then return a result. Specify double-click, reload, another-device behavior, and error recovery. If you only build a frontend demo, label it a simulation.”
This clarifies who approves the action, when it counts as finished, and what evidence the user can verify—regardless of coding tool.
7. What should acceptance testing prove?
| Scenario | Evidence to check | False confidence |
|---|---|---|
| Page-only demo | Local count responds to clicks | A real booking succeeded |
| Backend feature added | Request, permission check, write, and subsequent read agree | Success banner looks correct |
| Two concurrent claims | Shared availability and records remain consistent | Each tab’s local count is trusted |
| Rejected or interrupted request | Clear error, misleading success rolled back | UI keeps showing success |
Recovery matters: Reset or Refresh restarts this demonstration. In a real service, resetting a screen and cancelling a reservation are separate actions with separate permissions and records. Without a backend, shared persistence has not been tested.
8. When not to add a backend or database
A portfolio, static guide, temporary calculator, or personal simulation may not need a database. Avoid needless complexity. Revisit the architecture when people need synchronized shared state, permissions, or reliable retention.
Quick review
- Does an open menu need a database? Usually no; page state may be enough.
- Can two browsers decide who gets the last seat? No; a shared decision with concurrency handling is needed.
- What is still unknown when the page says Done? Whether an authorized write actually completed and a later read agrees.
Keep learning
If source code and the rendered page still feel interchangeable, revisit Lesson 1 · HTML, CSS, and JavaScript. For notes that vanish after refresh, see Vibe Coding Clinic 1 · Diagnose Browser Storage. Lesson 3 will clarify what “logged in” really means: sessions, cookies, and tokens.