Warming up the neural circuits...
By the end of this chapter you will:
A backend exists because someone has to store the data, apply the rules, and enforce the security — and none of that is safe to do in a browser.
You open QuickBite (think Zomato or Swiggy), browse restaurants, pick a Margherita pizza, and tap Place Order. Instantly your screen shows "Order placed! 🎉 Arriving in 30 min."
That screen — the buttons, the pizza image, the countdown timer — is the frontend. It's what you see and touch.
But who actually saved your order? Who charged your card? Who notified the restaurant? Who will track the delivery? That's the backend.
Nobody sees the kitchen. But without it, you get zero pizza. 🍕
Throughout this entire guide we'll build QuickBite — a food delivery . Every concept you learn will be applied directly to it.
No matter what technology you use — NestJS, Django, Rails, Spring — every backend has exactly three layers. You will hear these terms constantly, so learn them now.
This layer sits in front of your app and handles things every request needs:
You usually don't write this layer yourself. It's handled by an API gateway, a , or like Helmet.
This is where your NestJS code lives. It receives a request, figures out what to do, talks to the database, and sends a response back:
Your app is stateless — it doesn't remember anything between requests. All is stored here:
State goes DOWN (into the database). Code goes UP (into the app). Never the other way around.
What does this mean in practice?
❌ Wrong: Write business logic in the database (stored procedures, triggers with business rules)
❌ Wrong: Store state in the app (in-memory variables that pods don't share)
✅ Right: Business logic in the service layer. State in PostgreSQL or Redis.
Let's trace exactly what happens — step by step — when a user submits an order:
Every chapter in this guide covers one piece of that flow:
orders and order_items tablesOrdersModule, OrdersService, and OrdersControllerJwtGuard authenticationBy chapter 9, you will build this exact endpoint yourself.
You might have heard of Express — the most popular Node.js framework. NestJS is built on top of Express, and adds structure that Express doesn't have.
Without structure, a large Express codebase turns into chaos — controllers call models directly, services call controllers, everything imports everything. NestJS forces a clean architecture by design.
In QuickBite:
OrdersModule, RestaurantsModule, UsersModule, PaymentsModule…)| Mistake | Why it's wrong | What to do instead |
|---|---|---|
| Writing business logic in the database | Code splits between and — impossible to test | Business logic in services |
| Storing state in app memory | Other pods don't see it; restarts wipe it | Use PostgreSQL or Redis |
| Putting HTTP logic in a service | Service becomes tightly coupled to HTTP | Services know nothing about HTTP |
A backend is: receive request → validate → apply business rules → read/write data → return response. Your job is to write the business rules layer. Everything else is plumbing.