High-Level Overview
Deno is built on three core technologies:V8
Google’s JavaScript and WebAssembly engine
Rust
Systems programming language for the runtime
Tokio
Asynchronous runtime for Rust
Architecture Layers
Deno’s architecture is organized into several key layers:Key Directories
CLI Layer (cli/)
The user-facing interface and high-level integration.
cli/args/flags.rs
cli/args/flags.rs
Command-line flag parsingDefines the structure of all CLI commands and their flags. This is where you add new commands or modify existing command options.
cli/tools/
cli/tools/
CLI tools and subcommandsEach tool (fmt, lint, test, bundle, etc.) has its own module here. Simple tools are single files, complex tools have their own directories.Examples:
cli/tools/fmt.rs- Code formattercli/tools/test/- Test runner (complex)cli/tools/repl/- Interactive REPL
cli/main.rs & cli/lib.rs
cli/main.rs & cli/lib.rs
Entry point and command routing
main.rs is minimal - it just calls deno::main() from lib.rs. The lib.rs file contains the main logic for routing commands to their handlers.cli/module_loader.rs
cli/module_loader.rs
Module loading and resolutionHandles how Deno loads and resolves modules, including TypeScript compilation, remote modules, and import maps.
cli/lsp/
cli/lsp/
Language Server ProtocolPowers the Deno extension for editors like VS Code, providing features like autocomplete, diagnostics, and type checking.
Runtime Layer (runtime/)
Assembles the JavaScript runtime and integrates all extensions.
runtime/worker.rs
runtime/worker.rs
Worker initialization and managementCreates and manages JavaScript execution contexts. This is where extensions are registered and the V8 isolate is configured.Key concepts:
- Main Worker - The primary JavaScript execution context
- Web Workers - Background workers for parallel execution
- Extension Registration - Wiring up native functionality
runtime/permissions.rs
runtime/permissions.rs
Permission systemImplements Deno’s security model with granular permissions for network, filesystem, environment variables, and more.
Extensions Layer (ext/)
Extensions provide native functionality to JavaScript.
ext/fs/
Filesystem operations (read, write, stat, etc.)
ext/net/
TCP and UDP networking
ext/http/
HTTP server and client APIs
ext/fetch/
Fetch API implementation
ext/webgpu/
WebGPU API for GPU access
ext/kv/
Key-value database
ext/node/
Node.js compatibility layer
ext/web/
Web standard APIs (streams, encoding, etc.)
Extension Structure
Each extension typically contains:- Rust code - Implements “ops” (operations) that JavaScript can call
- JavaScript code - Provides high-level APIs that wrap the ops
- Tests - Both unit and integration tests
Core Layer (libs/core/)
The foundation that powers everything.
Op System
Op System
Operations (Ops) are Rust functions that can be called from JavaScript.The op system provides:
- Fast FFI between JavaScript and Rust
- Async operation support
- Resource management
- Type safety
V8 Integration
V8 Integration
Manages the V8 JavaScript engine:
- Isolate creation and configuration
- Snapshot support for fast startup
- Garbage collection integration
- Inspector protocol support
Module System
Module System
Handles module loading and resolution:
- ES modules
- Dynamic imports
- Import maps
- Module caching
Test Infrastructure
tests/specs/
Spec Tests - Main integration tests that execute CLI commands and validate output
tests/unit/
Unit Tests - TypeScript/JavaScript unit tests
tests/testdata/
Test Data - Fixtures and test files used by the test suite
tests/wpt/
Web Platform Tests - Tests for web standards compliance
Key Concepts
Workers
Workers are JavaScript execution contexts in Deno.- Main Worker
- Web Workers
The primary JavaScript execution context that runs your program.Created in
runtime/worker.rs, it:- Loads and executes the main module
- Has access to all granted permissions
- Can spawn web workers
Resources
Resources are managed objects that are passed between Rust and JavaScript. Examples:- File handles
- Network sockets
- Database connections
- Process handles
Permissions
Deno’s security model is based on explicit permissions:--allow-read
Filesystem read access
--allow-write
Filesystem write access
--allow-net
Network access
--allow-env
Environment variable access
--allow-run
Subprocess execution
--allow-ffi
Foreign function interface
runtime/permissions.rs.
Module Resolution
Deno supports several module types and resolution strategies:Module Types
Resolution Flow
Extension System
Extensions are the bridge between JavaScript and native code.How Extensions Work
Extension Lifecycle
- Initialization - Extension is registered with the runtime
- Snapshot - JavaScript code is included in the V8 snapshot for fast startup
- Runtime - Ops are callable from JavaScript
- Cleanup - Resources are freed when the runtime shuts down
Execution Flow
Here’s what happens when you rundeno run script.ts:
Communication Patterns
JavaScript ↔ Rust
Sync vs Async Ops
- Sync ops - Block until complete, used for fast operations
- Async ops - Return a promise, use Tokio for async I/O
- Fast ops - Optimized sync ops with minimal overhead
Performance Considerations
Snapshots
V8 snapshots enable fast startup by pre-compiling core JavaScript
Op Optimization
Fast ops minimize crossing the JS/Rust boundary
Async I/O
Tokio provides efficient async operations
Resource Pooling
Resources are pooled and reused where possible
Next Steps
Now that you understand the architecture:Development Guide
Learn the development workflow and common tasks
Building from Source
Build Deno on your local machine
Start Contributing
Make your first contribution to Deno
Explore the Code
Browse the source code on GitHub