Programming concepts
What is a Framework?
Definition
A framework is a reusable structure that calls your code: it defines the shape of the application and invokes the parts you supply at the points it decides.
Also known as: Software framework
Framework in more detail
The distinguishing property is inversion of control, often put as the Hollywood principle — don't call us, we'll call you. With a library, your code is in charge and calls in when it wants something. With a framework, the framework is in charge: it owns the entry point, the lifecycle and the flow, and your components, routes, handlers and hooks are called by it at the moments it defines. Django, Rails, Spring, Angular and Next.js all work this way.
That inversion buys structure. A framework decides the directory layout, the configuration conventions, the request lifecycle, the testing approach and often the data-access story, so a team is spared a hundred small architectural arguments and a new hire recognises the shape of the project immediately. It also brings a community, documentation and an ecosystem of extensions that already assume the same conventions.
The cost is that you are inside someone else's design. Doing something the framework did not anticipate ranges from awkward to impossible, upgrades arrive on the maintainers' schedule rather than yours, and the concepts are not portable — Rails knowledge does not transfer to Spring. That is the real trade against assembling libraries yourself, which gives complete control and hands you every decision, including the ones you would rather not make.
Framework example
Library — YOUR code calls IT
import { format } from "date-fns";
const label = format(new Date(), "yyyy-MM-dd"); // you decide when
Framework — IT calls YOUR code
// Next.js: you never call this; the framework does,
// at a moment and in a context it controls.
export default async function Page({ params }) {
const { slug } = await params;
return <article>{slug}</article>;
}
# Django: you register a view; the framework routes,
# builds the request, calls you, and renders the response.
urlpatterns = [ path("orders/<int:pk>/", views.order_detail) ]
Who owns the entry point is the whole distinction.Framework — common questions
- What is the difference between a framework and a library?
- Control flow. You call a library when you need it; a framework calls your code from inside a structure it owns. That inversion of control is the definition, not the size of the package.
- Is React a library or a framework?
- React describes itself as a library for building user interfaces, and its core is one. In practice it inverts control — it decides when your components render — and full-stack tools built on it such as Next.js are unambiguously frameworks.
- Should I use a framework or build from libraries?
- A framework is usually the faster and safer default: shared conventions, security defaults and an ecosystem you do not have to assemble. Composing libraries makes sense when your requirements genuinely do not fit any framework's assumptions.
Keep reading
Every definition in the set is indexed A-Z in the developer glossary, and the cheat sheets cover the syntax once you know what you are looking for.
Browse the A-Z glossary