How oven-sh/bun works
Bun is a single-executable JavaScript/TypeScript toolkit: its principal user workflow is invoking bun to run an app or script, with built-in package management, bundling, and testing as major companion capabilities. The graph combines README-documented product flows with source-indexed implementation areas. Several capabilities are documented but their runtime wiring was not sampled, so those links are cited to the README rather than presented as source-verified calls.
Main entry points: GarbageCollectionController.rs JS runtime · bun.js.rs Bun executable · bundle_v2.rs Bundler · HttpContext.h HTTP handling
Components 18
CLI and runtime
- Bun executable
src/bun.js.rs - JS runtime
src/jsc/GarbageCollectionController.rs - Runtime config
src/bunfig/bunfig.rs
Language processing
- AST and syntax
src/ast/e.rs - Module resolution
src/resolver/lib.rs - Transpilation
src/bundler/transpiler.rs
Developer tools
- Bundler
src/bundler/bundle_v2.rs - Test runner
src/runtime - Package commands
src/runtime/cli/package_manager_command.rs - Package installer
src/install/PackageManager.rs
Runtime services
- HTTP server
packages/bun-uws/src/App.h - HTTP handling
packages/bun-uws/src/HttpContext.h - HTTP responses
packages/bun-uws/src/HttpResponse.h - WebSockets
packages/bun-uws/src/WebSocket.h - HTTP client
src/http/h2_client/ClientSession.rs - Web streams
src/jsc/bindings/webcore/streams/JSReadableByteStreamController.cpp - System calls
src/sys/lib.rs
Other components
- Developer
Connections 19
- Developer → Bun executable: invokes
README.md - Bun executable → JS runtime: runs scripts
README.md - Bun executable → Package commands: dispatches commands
README.md - Package commands → Package installer: installs packages
README.md - Bun executable → Bundler: bundles apps
README.md - Bun executable → Test runner: runs tests
README.md - JS runtime → Runtime config: uses configuration
- JS runtime → AST and syntax: processes source
- AST and syntax → Module resolution: resolves imports
- Bundler → AST and syntax: transforms syntax
- Bundler → Module resolution: resolves modules
- Bundler → Transpilation: transpiles modules
- JS runtime → HTTP server: offers server API
README.md - HTTP server → HTTP handling: registers routes
packages/bun-uws/src/App.h - HTTP handling → HTTP responses: writes responses
packages/bun-uws/src/HttpContext.h - HTTP handling → WebSockets: upgrades connections
packages/bun-uws/src/HttpContext.h - JS runtime → HTTP client: provides fetch
README.md - JS runtime → Web streams: provides streams
README.md - JS runtime → System calls: uses system calls