跳轉到

Architecture

img

Major components

CLI

This is one of the major parts of Deno. Except for the critical third-party components like tokio and v8, a majority of the user facing Deno functionality is implemented in CLI. This also works as the glue between all the other components. CLI is like an orchestrator and an executor. CLI orchestrates executing a TS/JS program with the help of the services from itself and all the other components. CLI is where the Deno process starts from. This is what runs when a Typescript program is executed in Deno.

Runtime

Runtime is the next major part of Deno. The runtime consists of the deno runtime code in Javascript, majority of the low-level ops, inspector, metrics, and some important features like main worker, web worker, permissions, etc.

Core

Core is a component that offers it's services to both the sides: on one side, it works with rust parts of Deno such as CLI and runtime, and on the other side, core offers services that can be called directly from Deno runtime in Javascript. While CLI acts as an orchestrator, the core provides some of the critical functionality to run TS/JS code and to support interworking between JS and Rust. The core implements important functionalities like v8 bindings, flags, modules, JsRuntime, zero, shared queue, etc. The purpose of the existence of core is to provide some of the low-level functionality.

STD

Every major runtime or programming language comes with a standard library. Deno is no different. The standard library of Deno offers additional functionality, utilities, etc. The standard library is completely written in Typescript. Unlike Node.js, Deno's standard library offers fully async functionality.

Rusty_v8

This is the last major component that is part of the Deno project but doesn't reside in Deno's primary GitHub repository. Rusty_v8 has its own repository, but it comes under the Deno umbrella. It could be treated as a third-party service.

Rusty_v8 provides high-quality rust bindings to V8's C++ API.

Tokio

Tokio is a third-party component, but it is a backbone for Deno. Deno wouldn't have been fully async if tokio wasn't there. Tokio is a runtime for writing reliable, asynchronous, and slim applications with the Rust programming language. Deno relies completely on tokio to offer asynchronous functionality.

V8

This is a third-party component, but this is the one that runs the JS code. This is a very important part of Deno and Node.js too. JS programs can't execute if there is no V8 engine.

V8 is Google’s open-source high-performance JavaScript and WebAssembly engine, written in C++. V8 is very complicated and has a very large API.

Typescript compiler

The typescript compiler is the final major third-party component in Deno (not shown in the diagram above). As mentioned earlier, V8 can only run JS code. Deno supports both TS and JS. Deno needs to convert TS to JS before giving it to V8. This is done by the TS compiler. There are two types of compilers: one provided by microsoft which can do typechecking and transpilation, and the other one is SWC which does only transpilation. Transpilation means converting TS code to JS code.