Chapter 1
Inversion of Control
Who's the conductor?
A library is a toolbox: you reach in and call functions when you need them. A framework is the opposite — it owns the loop, and your code is the thing that gets called. This shift, called Inversion of Control, is what makes a framework feel different from a library, and it's the lens you'll need for everything else in this handbook.
Library — you call it
// your app.ts (entry point)
you decide when
lodash.groupBy(users, ...)
you decide when
dayjs().format('YYYY-MM')
you decide when
// done. you own the loop.
Your code is the conductor. The library is an instrument you reach for.
Framework — it calls you
// next.js owns the entry point
framework dispatches
→ middleware()
framework dispatches
→ app/blog/[slug]/page.tsx
framework dispatches
→ generateMetadata()
response sent
// framework owns the loop.
Who decides timing?
lib: You·fw: Framework
Who owns the loop?
lib: Your code·fw: Framework
Who owns the entry?
lib: Your main()·fw: next start
Key takeaways
- A library waits for you to call it; a framework calls you
- The framework owns the entry point, the lifecycle, and the event loop
- Your code lives inside slots the framework defines (routes, hooks, handlers)
- IoC is what makes upgrades powerful — and what makes "fighting the framework" painful