# holepunchto/bare architecture

> Architecture diagram of the GitHub repository holepunchto/bare, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/holepunchto/bare
- Repository: https://github.com/holepunchto/bare

## Overview

Bare is an embeddable, modular JavaScript runtime for desktop and mobile. Its principal workflow is for an embedder or CLI user to start a process, load JavaScript modules, run or poll the event loop, and eventually tear down the process. Major runtime capabilities include CJS/ESM interoperability, native addons, lightweight threads, process context, and suspension/wakeup lifecycle controls. The README documents these capabilities; sampled source and the SOURCE INDEX support selected internal links, while unsampled call paths are omitted or marked unverified.

Main entry points: [`src/runtime.c`](https://github.com/holepunchto/bare/blob/main/src/runtime.c) (Runtime and loop), [`src/addon.c`](https://github.com/holepunchto/bare/blob/main/src/addon.c) (Native addons), [`src/bare.js`](https://github.com/holepunchto/bare/blob/main/src/bare.js) (CJS / ESM modules), [`include/bare.h`](https://github.com/holepunchto/bare/blob/main/include/bare.h) (C embedding API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Runtime entry"]
  node_cli["Bare CLI<br/>[bare.js]"]
  node_c_api["C embedding API<br/>[bare.h]"]
end

subgraph group_execution["Execution core"]
  node_process["Process setup<br/>[bare.c]"]
  node_runtime["Runtime and loop<br/>[runtime.c]"]
  node_engine["JS engine"]
  node_event_loop["Async event loop"]
  node_suspension["Suspend and wake<br/>[runtime.c]"]
end

subgraph group_modules["Modules and addons"]
  node_module_system["CJS / ESM modules<br/>[bare.js]"]
  node_file_protocol["File protocol<br/>[protocol.js]"]
  node_native_addons["Native addons<br/>[addon.c]"]
  node_addon_api["Addon API<br/>[addon.js]"]
  node_module_registration["Module registration<br/>[module.h]"]
end

subgraph group_concurrency["Threads and context"]
  node_thread_api["Thread API<br/>[thread.js]"]
  node_thread_runtime["Thread runtime<br/>[thread.c]"]
  node_context_registry[("Process context<br/>[context.c]")]
end

node_embedder(("Embedder"))

node_embedder -->|"configures process"| node_c_api
node_embedder -.->|"starts runtime"| node_cli
node_c_api -.->|"sets up and loads"| node_process
node_process -.->|"delegates runtime"| node_runtime
node_runtime -->|"executes JavaScript"| node_engine
node_runtime -->|"drives I/O"| node_event_loop
node_module_system -->|"uses protocol"| node_file_protocol
node_module_system -->|"exposes addons"| node_addon_api
node_module_system -->|"exposes threads"| node_thread_api
node_file_protocol -.->|"resolves modules"| node_native_addons
node_addon_api -.->|"loads addons"| node_native_addons
node_native_addons -->|"registers modules"| node_module_registration
node_thread_api -->|"starts threads"| node_thread_runtime
node_runtime -->|"controls thread lifecycle"| node_thread_runtime
node_runtime -->|"tears down addons"| node_native_addons
node_runtime -->|"tears down context"| node_context_registry
node_context_registry -->|"checks addon seal and current process"| node_native_addons
node_c_api -->|"requests lifecycle changes"| node_suspension
node_suspension -->|"blocks or resumes"| node_event_loop

click node_cli "https://github.com/holepunchto/bare/blob/main/bin/bare.js"
click node_c_api "https://github.com/holepunchto/bare/blob/main/include/bare.h"
click node_process "https://github.com/holepunchto/bare/blob/main/src/bare.c"
click node_runtime "https://github.com/holepunchto/bare/blob/main/src/runtime.c"
click node_module_system "https://github.com/holepunchto/bare/blob/main/src/bare.js"
click node_file_protocol "https://github.com/holepunchto/bare/blob/main/src/protocol.js"
click node_native_addons "https://github.com/holepunchto/bare/blob/main/src/addon.c"
click node_addon_api "https://github.com/holepunchto/bare/blob/main/src/addon.js"
click node_module_registration "https://github.com/holepunchto/bare/blob/main/include/bare/module.h"
click node_thread_api "https://github.com/holepunchto/bare/blob/main/src/thread.js"
click node_thread_runtime "https://github.com/holepunchto/bare/blob/main/src/thread.c"
click node_context_registry "https://github.com/holepunchto/bare/blob/main/src/context.c"
click node_suspension "https://github.com/holepunchto/bare/blob/main/src/runtime.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_c_api toneBlue
class node_process,node_runtime,node_engine,node_event_loop,node_suspension toneAmber
class node_module_system,node_file_protocol,node_native_addons,node_addon_api,node_module_registration toneMint
class node_thread_api,node_thread_runtime,node_context_registry toneRose
class node_embedder toneIndigo
```

## Components

### Runtime entry

- [Bare CLI](https://github.com/holepunchto/bare/blob/main/bin/bare.js): `bin/bare.js`
- [C embedding API](https://github.com/holepunchto/bare/blob/main/include/bare.h): `include/bare.h`

### Execution core

- [Process setup](https://github.com/holepunchto/bare/blob/main/src/bare.c): `src/bare.c`
- [Runtime and loop](https://github.com/holepunchto/bare/blob/main/src/runtime.c): `src/runtime.c`
- **JS engine**
- **Async event loop**
- [Suspend and wake](https://github.com/holepunchto/bare/blob/main/src/runtime.c): `src/runtime.c`

### Modules and addons

- [CJS / ESM modules](https://github.com/holepunchto/bare/blob/main/src/bare.js): `src/bare.js`
- [File protocol](https://github.com/holepunchto/bare/blob/main/src/protocol.js): `src/protocol.js`
- [Native addons](https://github.com/holepunchto/bare/blob/main/src/addon.c): `src/addon.c`
- [Addon API](https://github.com/holepunchto/bare/blob/main/src/addon.js): `src/addon.js`
- [Module registration](https://github.com/holepunchto/bare/blob/main/include/bare/module.h): `include/bare/module.h`

### Threads and context

- [Thread API](https://github.com/holepunchto/bare/blob/main/src/thread.js): `src/thread.js`
- [Thread runtime](https://github.com/holepunchto/bare/blob/main/src/thread.c): `src/thread.c`
- [Process context](https://github.com/holepunchto/bare/blob/main/src/context.c): `src/context.c`

### Other components

- **Embedder**

## Connections

- Embedder → C embedding API: configures process (evidence: `README.md`)
- Embedder → Bare CLI: starts runtime
- C embedding API → Process setup: sets up and loads (evidence: `src/bare.c`)
- Process setup → Runtime and loop: delegates runtime
- Runtime and loop → JS engine: executes JavaScript (evidence: `README.md`)
- Runtime and loop → Async event loop: drives I/O (evidence: `README.md`)
- CJS / ESM modules → File protocol: uses protocol (evidence: `src/bare.js`)
- CJS / ESM modules → Addon API: exposes addons (evidence: `src/bare.js`)
- CJS / ESM modules → Thread API: exposes threads (evidence: `src/bare.js`)
- File protocol → Native addons: resolves modules
- Addon API → Native addons: loads addons
- Native addons → Module registration: registers modules (evidence: `include/bare/module.h`)
- Thread API → Thread runtime: starts threads (evidence: `README.md`)
- Runtime and loop → Thread runtime: controls thread lifecycle (evidence: `src/runtime.c`)
- Runtime and loop → Native addons: tears down addons (evidence: `src/runtime.c`)
- Runtime and loop → Process context: tears down context (evidence: `src/runtime.c`)
- Process context → Native addons: checks addon seal and current process (evidence: `src/context.c`)
- C embedding API → Suspend and wake: requests lifecycle changes (evidence: `README.md`)
- Suspend and wake → Async event loop: blocks or resumes (evidence: `README.md`)
