Library or framework — what the difference really is

The usual explanation is that a library is small and a framework is big. That's not true — there are enormous libraries and tiny frameworks.
The difference is elsewhere, and it fits in one line:
You call a library. A framework calls you.
Here's what that means in practice, and which one to pick.
Who calls whom
A library is a toolbox. You need a date formatted — you reach in, grab the tool, call the function, put it back. Your code is in charge. It decides what runs and when.
A framework is the frame of a house. The walls and floors are already up, with openings left in them. Your job is to fill the openings: a page here, a form handler there. The framework starts up, and it decides when to call your piece.
That flip is called inversion of control, and it's usually phrased Hollywood-style: "don't call us, we'll call you."
An eyeball test that always works: find the place in your project where you call their function. Found one? Library. If it's the other way round — your code sits in a file with the right name and something runs it for you — framework.
What it looks like in code
With a library you write an explicit call:
import dayjs from "dayjs";
const text = dayjs(order.createdAt).format("DD/MM/YYYY"); // you made the call
With a framework you don't write a call at all. You drop a file at app/about/page.tsx — and a page appears at /about. Nobody called it explicitly: the framework found the file by convention and ran it.
That "magic appearance" is the defining trait of a framework. And its main price: while you know the conventions everything flies, and when you don't, you can't even tell where to look.
Six criteria: how they actually differ
- Who's in charge. Library: your code. Framework: the framework itself.
- What it gives. Library: solves one task. Framework: the structure of the whole project.
- Getting started. Library: plug it in and use it. Framework: learn the rules first.
- Freedom. Library: do it your way. Framework: do it the accepted way.
- Cost of leaving. Library: drop one, rewrite a few lines. Framework: rewrite the project.
- When to reach for it. Library: you need one specific function. Framework: the same tasks keep repeating.
The most underrated line here is the second to last. Everyone weighs how fast they can start; almost nobody weighs the cost of leaving — and that's the one that ends up being paid.
Who's who
To make the rule concrete, walk through some familiar names:
- Libraries:
dayjs(dates),axios(requests),zod(validation),chart.js(charts). All of them wait for you to call. - Frameworks: Next.js, Django, Laravel, Rails. Each has its own folder structure and conventions — they run your code themselves.
- Debatable: Express, FastAPI, Flask. They call themselves "minimal frameworks", and that's fair: you write
app.get("/users", ...)— you're handing over your function to be called later. The trait is there, there are simply few rules.
Who should pick what
No fence-sitting.
First project, one-pager, script, bot — libraries. One reason: cost of error. Wrong library? Delete three lines, take another. Wrong framework? You're rewriting everything. Until you know what your project will turn into, keeping decisions reversible is cheaper. You'll also see what each piece does — plugging in one library and understanding it beats taking apart someone else's whole frame.
An app with pages, login and a database — framework. Here the opposite argument wins: without one you'll write your own framework anyway, only worse. By page three you'll be hand-rolling a router; by page five, your own templating system. A framework is the same decisions, made by thousands of people before you.
A note on vibe coding. With a framework the model writes noticeably faster: the conventions are known, so each prompt produces less code. But mistakes cost more — the model will confidently generate code for an older version of the framework and you won't see it. With libraries, an error is usually local and obvious right away.
Short rule: don't know how it ends — start with libraries. Know it will grow — take a framework straight away, the second run costs more.
How to tell you've outgrown libraries
The moment to switch shows up as three signs — recognise two of them and it's time:
- You're writing the same thing for the third time. Your own address parsing, your own check for who's logged in, your own header inserted into every page.
- You're copying the folder structure from your last project. So you already have a structure — it's just undocumented and lives only in your head.
- A newcomer (or a model) can't tell where a file should go. A framework has a ready answer to that question, and that's half of its value.
The reverse sign exists too: you keep fighting the framework, working around its rules with hacks, while using two functions out of it. Then you took a frame where a couple of tools would have done.
Is React a library or a framework?
Formally a library — that's what it calls itself: React only handles rendering the interface. But the moment you add a router, a bundler and data fetching, the bundle feels like a framework. And Next.js, built on top of it, is a framework with no caveats.
Can you use both together?
That's exactly how it normally works. One framework per project — it holds the structure. Alongside it, dozens of libraries: dates, charts, form handling.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





