Framework vs library: what is the difference?
In one sentence:A library is code your app calls when it needs something; a framework calls your code and decides the structure, which is why your whole project takes its shape from the framework you pick.
What it actually is
A library is code your app calls. You install it, import the two functions you need, and use them wherever you decide. A framework flips that relationship: it calls your code. It decides the folder layout, when your files run, and how a URL turns into a page. You write the parts it left blank for you.
Think of it as bricks versus a house frame. A library is a box of Lego bricks: you snap a few into whatever you were already building, and you can put the box away tomorrow. A framework is a house with the frame already up. The rooms are placed and the plumbing runs where it runs. Your job is finishing the interiors, and moving to a different house means packing everything and rebuilding, which is exactly why swapping frameworks mid-project hurts.
The naming out in the wild is messier than the definition. React describes itself as “the library for web and native user interfaces,” and that is accurate: it renders components and does little else. But React’s own docs recommend starting a new app with a framework, and the first one they list is Next.js, which calls itself “The React Framework for the Web” and supplies routing, data loading, and the build setup. So when a tutorial lumps React in with the frameworks, it is wrong on paper and close enough in practice. The React you meet usually arrives wearing a framework around it.
Why your AI just did this
Before your agent writes a single feature, it has to settle structural questions: where files go, and how URLs map to pages. Scaffolding a framework settles all of them at once, which is why “build me an app” starts with npx create-next-app@latest or npm create astro@latest rather than an empty folder. The framework also decides how your pages get built, static files or a live server, which is the SSR vs SSG question. Libraries come later, pulled in one at a time through npm as needs show up: one for dates, another for charts.
The word also appears when your agent explains why it will not move something. “That file is a framework convention” means the structure expects it at that exact path with that exact name. Rename app/page.tsx in a Next.js project, or move a page out of Astro’s src/pages/ folder, and the route quietly disappears, with no error in any code you wrote.
When you’ll run into it
The clearest sighting is your own package.json. The dependencies list names the framework you live in (next, astro, express) alongside a longer tail of libraries. Deploy platforms ask about it too: Vercel’s project setup has a “Framework Preset” dropdown, because the platform needs to know which build command to run and where the output lands. And when you start the dev server in a Next.js or Astro project, the startup banner names the framework and its version before your app even loads.
Here is a rough map of the tools you will meet most:
| Tool | What it is | What it decides for you |
|---|---|---|
| React | Library (its own site’s word) | How components render |
| Next.js | Framework | Routing, file layout, rendering, build |
| Astro | Framework | The same jobs, tuned for content sites |
| Express | Framework, a deliberately small one | How your backend handles requests |
| Tailwind | Calls itself a CSS framework, behaves like a library | Styling classes you sprinkle where you want |
Tailwind earns its odd row. The tagline says “utility-first CSS framework,” yet it imposes no structure on your app: you add classes where you choose, and stripping it out later would be tedious but would not collapse the project’s structure. The label a tool wears matters less than the question underneath. Does it call you, or do you call it?
What to check
- Open
package.jsonand read the dependencies to learn which framework your project is built on;next,astro, orexpressis the tell - Ask your agent what the framework decides for you (routing, file layout, build) before requesting structural changes, so you know which folders are load-bearing
- Search errors together with the framework’s name when they mention files you never created, like
next.config.jsorastro.config.mjs; generic JavaScript answers will miss - Treat “let’s switch frameworks” as a rewrite quote, and ask which parts survive the move before agreeing
- Match any tutorial to your framework and its major version; instructions for one rarely map onto another
Say it like a dev
Instead of: “can we swap React for Vue real quick” Say: “We’re on Next.js, so that’s a migration. What would it cost, and which components survive as-is?”
Instead of: “install the framework for charts” Say: “Add a small charting library. The framework stays Next.js.”
Instead of: “there’s a folder I never made, can we delete it”
Say: “Is src/pages/ a framework convention here? What breaks if we move files out of it?”
People actually ask
“Is React a framework or a library?”
React's own site calls it a library: it renders components and leaves routing, data loading, and build setup to other tools. React's own docs recommend starting a new app with a framework such as Next.js, which supplies those missing pieces and calls React for you. So both answers you hear online are half right, and for day-to-day work the difference rarely bites.
“Can I switch frameworks in the middle of a project?”
You can, but treat it as a partial rewrite rather than a swap. The framework decides your folder layout, routing, and build process, so most files in the project are shaped around it. Components and plain business logic often survive the move; everything wired into the framework's conventions gets rebuilt. Replacing a library, by comparison, usually touches a handful of files.
“Why does my AI keep talking about 'the framework' when I never chose one?”
Your agent chose one the moment it scaffolded your project, because it needed answers about file layout and routing before writing any feature code. Open package.json and read the dependencies: a line like next, astro, or express tells you which framework you are living in. Knowing its name matters, because errors about files you never created are usually framework conventions, and the fix lives in that framework's docs.
Related terms
Go deeper
Checked against
- https://react.dev/
- https://react.dev/learn/creating-a-react-app
- https://nextjs.org/
- https://nextjs.org/docs/app/api-reference/file-conventions/page
- https://astro.build/
- https://docs.astro.build/en/guides/routing/
- https://expressjs.com/
- https://tailwindcss.com/
- https://vercel.com/docs/builds/configure-a-build
Just met this in a real session? Glim reads it in plain words.
Paste what your agent just did, a git diff, your terminal, or its summary, and Glim tells you what changed and what to check before you ship. Nothing stored.
Explain my session →