Building a house from raw timber means designing the frame, wiring and plumbing yourself. A pre-fabricated frame lets you skip straight to the parts that make your home unique, provided you accept its dimensions. Frameworks offer software developers that trade. Common jobs such as routing web requests, talking to a database, validating forms and handling logins are already solved, and you fill in the code specific to your application.
Well-known examples include Laravel and Symfony for PHP, Django and Flask for Python, Spring for Java, and Angular or Next.js for JavaScript.
Example
In Laravel, a PHP framework, you register a route and the framework handles the rest of the request cycle:
use Illuminate\Support\Facades\Route;
Route::get('/hello/{name}', function (string $name) {
return "Hello, {$name}!";
});
You never write code to read the URL, match it against patterns or send the HTTP response. Laravel does all of that, then calls your function when a visitor opens /hello/Sam.
Framework vs library
The usual distinction is about who is in control. With a library, your code is in charge and calls into it when it needs something, such as formatting a date. With a framework, the framework runs the show and calls your code at points it defines. This reversal is often called inversion of control, summed up as "don't call us, we'll call you."
Real projects rarely fit the definitions neatly. A Laravel app, for instance, also pulls in dozens of small packages, so you end up using a framework and many libraries side by side.
Trade-offs
Frameworks save time and steer teams toward consistent, tested patterns. In return you must learn their conventions, keep up with their upgrades, and work around them when your needs fall outside what they anticipate. Learning the underlying language first makes any framework easier to pick up.
Explore further
Last updated