# supabase/edge-runtime architecture

> Architecture diagram of the GitHub repository supabase/edge-runtime, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/supabase/edge-runtime
- Repository: https://github.com/supabase/edge-runtime

## Overview

This project – Supabase Edge Runtime – is a high-performance, self‐hosted Deno web server built to run JavaScript, TypeScript, and WASM services at the edge. It is organized into multiple Rust crates (each handling core functionality such as the base runtime, filesystem, HTTP utilities, Deno interfacing, etc.), a CLI tool, examples, and even extensions (“ext” directory) that provide additional integrations. The README clearly defines two key “runtimes”: the Main runtime (which handles entry, proxying, and security tasks such as authentication and environment variable management) and the User runtime (which executes user functions under controlled resource limits like memory and timeouts).

##### Main Components
- HTTP Request Interface – an entrypoint that accepts incoming HTTP requests.
- Main Runtime – the gateway that authenticates, validates, and then proxies requests.
- User Runtime – the sandboxed execution environment where user functions run with restrictions (e.g., limited memory, timeouts).
- Supporting Modules/Crates – core libraries including the “base” crate, “fs” (file system), “http_utils”, “deno_facade”, “cpu_timer”, and others that provide features such as module loading (eszip_trait), caching, and runtime utilities.
- CLI Tool – provides command‐line functionality to launch the server and manage configurations.
- Extensions (“ext” directory) – enhance integration with external APIs and add support for Node-like polyfills.

##### Relationships and Interactions
- Examples of how supporting crates (like “fs” for file caching and “cpu_timer” for monitoring execution time) are used to underpin the low-level functionalities.

## Diagram (Mermaid)

```mermaid
graph TD
  subgraph "Entry Layer"
    http_interface["HTTP Request Interface"]:::external
  end

  subgraph "Runtimes"
    main_runtime("Main Runtime"):::runtime
    user_runtime("User Runtime"):::runtime
  end

  subgraph "Supporting Modules"
    base_crate["Base Crate"]:::support
    fs["Filesystem"]:::support
    http_utils["HTTP Utilities"]:::support
    deno_facade["Deno Interfacing"]:::support
    cpu_timer["CPU Timer"]:::support
    eszip["Module Loader / eszip trait"]:::support
  end

  subgraph "Tools & Extensions"
    cli_tool["CLI Tool"]:::tool
    extensions["Extensions"]:::tool
  end

  http_interface -->|"incoming"| main_runtime
  main_runtime -->|"proxies"| user_runtime

  main_runtime -->|"uses"| base_crate
  main_runtime -->|"uses"| fs
  main_runtime -->|"uses"| http_utils
  main_runtime -->|"calls"| deno_facade
  user_runtime -->|"calls"| cpu_timer
  user_runtime -->|"loads"| eszip

  cli_tool -->|"launches"| main_runtime
  extensions -->|"integrates"| main_runtime

  click http_interface "https://github.com/supabase/edge-runtime/blob/develop/deno/http_util.rs"
  click http_interface "https://github.com/supabase/edge-runtime/blob/develop/crates/http_utils/src/lib.rs"
  click main_runtime "https://github.com/supabase/edge-runtime/blob/develop/crates/base/src/server.rs"
  click user_runtime "https://github.com/supabase/edge-runtime/blob/develop/crates/base/src/worker/driver/user.rs"
  click base_crate "https://github.com/supabase/edge-runtime/tree/develop/crates/base"
  click fs "https://github.com/supabase/edge-runtime/tree/develop/crates/fs"
  click http_utils "https://github.com/supabase/edge-runtime/tree/develop/crates/http_utils"
  click deno_facade "https://github.com/supabase/edge-runtime/tree/develop/crates/deno_facade"
  click cpu_timer "https://github.com/supabase/edge-runtime/tree/develop/crates/cpu_timer"
  click eszip "https://github.com/supabase/edge-runtime/tree/develop/crates/eszip_trait"
  click cli_tool "https://github.com/supabase/edge-runtime/tree/develop/cli"
  click extensions "https://github.com/supabase/edge-runtime/tree/develop/ext"

  classDef runtime fill:#FEE2E2,stroke:#E11D48,stroke-width:2px,rx:15,ry:15
  classDef support fill:#DBEAFE,stroke:#1D4ED8,stroke-width:2px
  classDef external fill:#DCFCE7,stroke:#16A34A,stroke-width:2px
  classDef tool fill:#FEF9C3,stroke:#CA8A04,stroke-width:2px
```
