The Big Picture
When you build an app, you’re really building two things that talk to each other: a frontend (what users see) and a backend (where data lives and logic happens). Think of it like a restaurant: the frontend is the dining room where customers interact, and the backend is the kitchen where the real work gets done.Where Does Your Data Live?
This is the #1 source of confusion. Your data exists in three different places, and understanding this is critical:Browser Memory
Temporary data while the page is open. Disappears on refresh.
Session Storage
Temporary data for your browsing session. Gone when you close the tab.
Database
Permanent storage. Data persists forever (until you delete it).
The Todo List Example
Imagine you’re building a todo list app:Frontend vs Backend: The Restaurant Analogy
| Frontend (Dining Room) | Backend (Kitchen) |
|---|---|
| What users see and interact with | Where data is stored and processed |
| Runs in the browser | Runs on a server |
| HTML, CSS, JavaScript | Node.js, Python, databases |
| Makes requests for data | Responds with data |
| Cannot directly access databases | Has full database access |
Why They’re Separate
Your frontend code runs on the user’s computer (in their browser). Your backend runs on your server. This means:- The frontend has to ask the backend for data
- The backend decides if the request is allowed
- The frontend waits for the response
- The backend sends data back
The Request/Response Cycle
Here’s what actually happens when you click a button in an app:
This happens in milliseconds, but it’s not instant. That’s why you see loading spinners - the frontend is waiting for the backend to respond.
Code Example
Notice how the frontend cannot directly access the database. It must go through the backend. This is a security feature - you don’t want users able to access your database directly from their browser.
What Is a Database?
A database is permanent storage for your app’s data. Think of it like a super-organized filing cabinet that never forgets.MongoDB Basics
MongoDB stores data in collections of documents. Think of it like this:- Database = The entire filing cabinet
- Collection = A drawer in the cabinet (e.g., “users”, “todos”, “posts”)
- Document = An individual file/record in that drawer
Documents Look Like JavaScript Objects
If you know how to work with JavaScript objects, you already know how to work with MongoDB documents!
CRUD: The Four Things You Do With Data
Every app is basically doing these four operations in different combinations:Create
Add new data (signup, create post, add todo)
Read
Get existing data (login, view profile, show todos)
Update
Change existing data (edit profile, mark todo done)
Delete
Remove data (delete account, remove todo)
How Code Actually Runs
Frontend Code (Browser)
Backend Code (Server)
- Connect to databases
- Store secrets and API keys
- Validate data before saving
- Control who can access what
Environment Variables: Keeping Secrets Secret
Your database password, API keys, and other secrets go in a special file called.env:
Collections and Relationships
What Is a Collection?
A collection is a group of similar documents. Common collections include:users- All your user accountsposts- All blog posts or contentcomments- All comments on poststodos- All todo items
Connecting Related Data
Let’s say you have users and posts. How do you know which posts belong to which user?- Get the post
- Look up the user by
authorId - Display both together
The Schema Question
MongoDB doesn’t enforce a schema (structure) by default, which means you can do this:Async/Await: Why Things Don’t Happen Instantly
When you fetch data from a database or API, it takes time. You need to wait for the response:await keyword says “pause here until the data arrives”. Any function using await must be marked async as a best practice.
Putting It All Together
Here’s the complete flow of a typical app feature, using the same example of the to-do app:Key Takeaways
Frontend = Display
Shows data and collects input. Runs in the browser.
Backend = Logic
Processes requests and stores data. Runs on your server.
Database = Memory
Permanent storage. Survives refreshes and restarts.
API = Middleman
Connects frontend and backend through endpoints.
The hardest part about learning to code isn’t the syntax - it’s understanding where code runs, where data lives, and how it all connects. Master these concepts and everything else falls into place.