This document introduces Deno at the highest level: what it is, its architectural philosophy, and how the codebase is organized. For detailed information about specific subsystems:
Deno is a secure runtime for JavaScript and TypeScript built on V8, Rust, and Tokio. The codebase delivers:
deno binary) for executing JavaScript/TypeScriptdeno_runtime) providing Web Platform APIsdeno_core) enabling modular functionalitydeno_node) with 300+ polyfilled modulesSources: cli/Cargo.toml1-226 runtime/Cargo.toml1-116 Cargo.toml1-559
The codebase follows strict layering where each layer depends only on layers below:
Layer responsibilities:
Sources: Cargo.toml3-61 cli/Cargo.toml1-226 runtime/Cargo.toml1-116
Functionality is provided through discrete extensions registered with deno_core. Each extension:
#[op2] macroExtension Architecture:
Sources: Cargo.toml95-122 ext/node/lib.rs144-304 ext/http/Cargo.toml1-68
The repository is organized as a Cargo workspace with 63+ member crates:
| Directory | Purpose | Key Members |
|---|---|---|
cli/ | Command-line interface | deno (binary), deno_lib, deno_snapshots |
runtime/ | Runtime library | deno_runtime, deno_permissions, deno_features |
ext/ | Extension crates | deno_* (20+ extensions) |
libs/ | Shared libraries | deno_config, deno_lockfile, node_resolver, eszip |
tests/ | Test infrastructure | test_util, bench_util, integration tests |
Sources: Cargo.toml3-61
Sources: Cargo.toml3-61 cli/Cargo.toml1-226
cli/)The deno binary provides user-facing commands and subcommand dispatch.
Entry point: cli/main.rs16
Key structures:
Flags: Parsed command-line argumentsDenoSubcommand: Enum of all subcommands (run, test, compile, etc.)CliFactory: Dependency injection container for servicesCliMainWorkerFactory: Creates MainWorker instancesMajor subsystems:
cli/tools/test.rs: Test runner implementationcli/tools/bench.rs: Benchmark runnercli/lsp/: Language Server Protocol implementationcli/tsc/: TypeScript compiler integrationSources: cli/Cargo.toml1-226 cli/main.rs16
runtime/)deno_runtime provides the JavaScript execution environment.
Key exports:
MainWorker: Primary execution context for main threadWebWorker: Execution context for Web WorkersBootstrapOptions: Configuration for runtime initializationBootstrap sequence: runtime/js/99_main.js
Deno namespace, Web APIs)Extension registration: Extensions are registered in dependency order during worker creation.
Sources: runtime/Cargo.toml1-116 runtime/lib.rs38
ext/)Extensions provide modular functionality via the deno_core::extension! macro.
Major extensions:
| Extension | Primary Function | Rust Ops | JS Modules |
|---|---|---|---|
deno_core | Extension framework, op system | Core infrastructure | - |
deno_web | EventTarget, Streams, TextEncoder | 50+ | 30+ |
deno_fetch | fetch() API, HTTP client | 20+ | 10+ |
deno_http | Deno.serve(), HTTP server | 30+ | 5+ |
deno_websocket | WebSocket client/server | 15+ | 2+ |
deno_crypto | Web Crypto API, SubtleCrypto | 40+ | 5+ |
deno_fs | FileSystem trait, file ops | 25+ | - |
deno_io | stdio, Deno.File | 10+ | - |
deno_net | TCP/UDP/Unix sockets, TLS | 35+ | 5+ |
deno_ffi | dlopen, FFI | 20+ | 3+ |
deno_kv | Deno.openKv(), AtomicOperation | 15+ | 2+ |
deno_node | Node.js compatibility | 100+ | 200+ |
Extension dependencies (simplified):
deno_fetch depends on deno_web, deno_net, deno_tlsdeno_http depends on deno_web, deno_netdeno_node depends on nearly all other extensionsSources: Cargo.toml95-122 ext/node/lib.rs144-304 ext/http/Cargo.toml1-68 ext/fetch/Cargo.toml1-55 ext/crypto/Cargo.toml1-51
libs/)Reusable libraries used across CLI and runtime:
| Library | Responsibility |
|---|---|
deno_config | Parse deno.json, workspace configuration |
deno_lockfile | Lock file read/write, integrity checking |
deno_npm | NPM package resolution, semver handling |
node_resolver | Node module resolution algorithm |
deno_resolver | Unified module resolution (Deno + Node + NPM + JSR) |
eszip | ES module archive format (ESZIP v2) |
deno_inspector_server | Chrome DevTools Protocol server |
Sources: Cargo.toml124-148
Centralized dependency versions in workspace root:
Workspace dependencies section: Cargo.toml72-148
workspace = true syntaxSources: Cargo.toml1-559
Release profile configuration: Cargo.toml421-428
opt-level = 'z' # Optimize for size
lto = true # Link-time optimization
codegen-units = 1 # Single codegen unit for better optimization
incremental = true # Incremental compilation
split-debuginfo = "packed" # Packed debug info
Per-package optimization overrides: Cargo.toml455-558
deno_core, tokio, hyper, crypto libs) set to opt-level = 3Sources: Cargo.toml421-558
Multi-platform automated builds via GitHub Actions:
Build matrix dimensions: .github/workflows/ci.generate.ts431-496
ci-full, ci-bench)Test phases:
cargo test --libcargo test --testsRelease artifacts:
deno-<platform>.zip: Main binarydenort-<platform>.zip: Runtime-only binary (for deno compile)deno-<platform>.symcache: Debug symbols for crash reportingDistribution:
main → dl.deno.land/canary/<sha>/dl.deno.land/release/<version>/ + GitHub ReleasesSources: .github/workflows/ci.yml1-3523 .github/workflows/ci.generate.ts1-1192
Extensions use the deno_core::extension! macro to declare their interface:
Example - deno_node extension: ext/node/lib.rs144-304
op_require_*, op_node_fs_*, op_node_http_*)deno_io and deno_fsSources: ext/node/lib.rs144-304 ext/http/Cargo.toml1-68
Operations are defined using #[op2] macro with modifiers:
| Modifier | Use Case | Example |
|---|---|---|
#[op2(fast)] | Simple synchronous ops, minimal V8 overhead | op_now() returns current timestamp |
#[op2(async)] | I/O operations, returns Future | op_read_file() reads file asynchronously |
#[op2] | Complex data structures, full V8 integration | op_create_worker() with configuration object |
Common op naming conventions:
op_fs_*: File system operations in deno_fsop_net_*: Network operations in deno_netop_http_*: HTTP server operations in deno_httpop_fetch_*: HTTP client operations in deno_fetchop_node_*: Node.js compatibility operations in deno_nodeSources: ext/node/lib.rs147-303
The deno_node extension provides comprehensive Node.js API compatibility through a three-layer architecture:
Public APIs: ext/node/lib.rs316-527
polyfills/ directoryInternal implementation:
_fs/, _http*/, internal/ modulesNode-specific ops:
ops/ subdirectoryops/http.rs uses deno_http)Coverage: 300+ polyfilled modules providing ~80% Node.js API compatibility
Sources: ext/node/lib.rs1-528 ext/node/Cargo.toml1-76
Deno's module loader handles multiple formats:
| Format | File Extensions | Features |
|---|---|---|
| ES modules | .js, .ts, .mjs, .mts | Native V8 loader, dynamic import, top-level await |
| CommonJS | .cjs, .cts, Node packages | require(), module.exports, interop with ESM |
| TypeScript | .ts, .tsx, .mts, .cts | Transpiled to JavaScript via SWC or TSC |
| JSON | .json | Import assertions/attributes |
| WASM | .wasm | WebAssembly modules |
Module resolution strategies:
https://, file://)node_modules/ resolutionnpm: specifier protocoljsr: specifier protocol for JSR packagesSources: ext/node/lib.rs55-74 cli/Cargo.toml68-199
Two modes for NPM package handling:
Managed Mode (default):
DENO_DIR/npm/ManagedCliNpmResolverBYONM (Bring Your Own node_modules) Mode:
node_modules/ directorynpm install or deno installByonmCliNpmResolverSources: cli/Cargo.toml68-199
The CLI provides integrated development tools sharing common infrastructure:
| Tool | Command | Implementation | Description |
|---|---|---|---|
| Type checker | deno check | cli/tsc/ | TypeScript type checking (TSC or TSGO) |
| Test runner | deno test | cli/tools/test.rs | Test execution with reporters |
| Benchmark | deno bench | cli/tools/bench.rs | Performance benchmarking |
| Linter | deno lint | deno_lint crate | JavaScript/TypeScript linting |
| Formatter | deno fmt | dprint-* plugins | Code formatting |
| LSP | deno lsp | cli/lsp/ | Language Server Protocol |
| Documentation | deno doc | deno_doc crate | API documentation generator |
| Bundle | deno bundle | esbuild_client | Module bundling |
| Compile | deno compile | cli/tools/compile.rs | Standalone executable creation |
Shared services (via CliFactory):
ModuleGraphBuilder: Builds dependency graphsTypeChecker: Runs type checkingCliNpmResolver: Resolves NPM packagesEmitter: Transpiles TypeScript to JavaScriptSources: cli/Cargo.toml68-199 Cargo.toml124-148
Project configuration file supporting:
| Section | Purpose |
|---|---|
compilerOptions | TypeScript compiler settings |
imports | Import map for specifier resolution |
scopes | Scoped import maps |
tasks | Task definitions (like npm scripts) |
lint | Linter configuration |
fmt | Formatter configuration |
test | Test configuration |
workspace | Workspace members for monorepos |
nodeModulesDir | Enable/disable node_modules/ directory |
Parsed by deno_config library: Cargo.toml126
Lock file for deterministic dependency resolution:
Managed by deno_lockfile library: Cargo.toml131
Sources: Cargo.toml124-148
Semantic versioning: MAJOR.MINOR.PATCH
Recent stable releases: Releases.md9-200
Canary builds:
main branchdl.deno.land/canary/<commit-sha>/Stable builds:
dl.deno.land/release/<version>/deno upgrade or install scriptsInstall methods:
curl -fsSL https://deno.land/install.sh | shirm https://deno.land/install.ps1 | iexSources: Releases.md1-600 .github/workflows/ci.yml348-356
Deno's codebase is organized as a modular, layered system:
Architecture layers:
cli/): User interface, tools, command dispatchruntime/): Worker management, event loop, bootstrapext/): 20+ modular extensions for APIsKey design principles:
deno_nodeWorkspace composition:
For deeper exploration of specific components, refer to the related pages listed at the beginning of this document.
Sources: Cargo.toml1-559 cli/Cargo.toml1-226 runtime/Cargo.toml1-116 ext/node/lib.rs1-528 .github/workflows/ci.yml1-3523
Refresh this wiki