Chapter 1
Library vs Framework
Who calls whom?
Both libraries and frameworks are pre-written code you lean on, but they have a fundamentally different relationship with your app. With a library, you stay in charge — you call its functions when you need them. With a framework, you hand over the keys: it runs the show and calls your code at the right moments. That one distinction — Inversion of Control — drives most of the architectural decisions that follow.
Library — you call it
your codelibrary
const fn = debounce(save, 300)
librarylibrary
lodash.debounce wraps your fn
libraryyour code
fn returned to your code
Framework — it calls you
frameworkyour code
Next.js receives GET /api/users
your codeframework
export async function GET() { … }
frameworkcaller
Framework sends HTTP response
Inversion of Control: a framework owns the loop; a library is a tool you reach for.
Key takeaways
- Libraries: your code calls them when it wants something done
- Frameworks: they call your code at moments they choose (Inversion of Control)
- Frameworks dictate structure; libraries fit into structure you already have
- Most modern stacks combine both — Next.js (framework) + lodash (library)