# janet-lang/janet architecture

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

- Interactive diagram: https://gitdiagram.com/janet-lang/janet
- Repository: https://github.com/janet-lang/janet

## Overview

Janet is an embeddable scripting language with a separate shell client for running scripts and providing a REPL. Its principal workflow is a user submitting source through the client, which the runtime parses, compiles, and executes; the README also describes embedding the core in C/C++ programs. The graph preserves documented language, concurrency, I/O, FFI, and debugging capabilities. Some internal stage links are dashed because the supplied excerpts do not show those call sites.

Main entry points: [`src/core/corelib.c`](https://github.com/janet-lang/janet/blob/master/src/core/corelib.c) (Core library), [`src/mainclient/shell.c`](https://github.com/janet-lang/janet/blob/master/src/mainclient/shell.c) (Shell and REPL), [`src/core/compile.c`](https://github.com/janet-lang/janet/blob/master/src/core/compile.c) (Compiler), [`src/core/vm.c`](https://github.com/janet-lang/janet/blob/master/src/core/vm.c) (Virtual machine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_shell["Shell and REPL<br/>[shell.c]"]
  node_api["Embedding API<br/>[janet.h]"]
end

subgraph group_language["Language processing"]
  node_parser["Parser<br/>[parse.c]"]
  node_peg["PEG engine<br/>[peg.c]"]
  node_compiler["Compiler<br/>[compile.c]"]
  node_specials["Macros and specials<br/>[specials.c]"]
  node_emitter["Bytecode emitter<br/>[emit.c]"]
  node_allocator["Register allocator<br/>[regalloc.c]"]
end

subgraph group_runtime["Execution runtime"]
  node_bytecode["Bytecode<br/>[bytecode.c]"]
  node_vm["Virtual machine<br/>[vm.c]"]
  node_fibers["Fibers<br/>[fiber.c]"]
  node_eventloop["Event loop<br/>[ev.c]"]
  node_gc["Garbage collector<br/>[gc.c]"]
end

subgraph group_libraries["Core capabilities"]
  node_corelib["Core library<br/>[corelib.c]"]
  node_io["I/O and processes<br/>[io.c]"]
  node_network["Networking<br/>[net.c]"]
  node_os["Operating system<br/>[os.c]"]
  node_ffi["C FFI<br/>[ffi.c]"]
  node_debug["Debugger<br/>[debug.c]"]
  node_marshal["Serialization<br/>[marsh.c]"]
end

node_user(("Script user"))

node_user -->|"submits script"| node_shell
node_shell -.->|"runs source"| node_parser
node_parser -.->|"produces syntax"| node_compiler
node_compiler -->|"emits bytecode"| node_emitter
node_compiler -->|"allocates registers"| node_allocator
node_emitter -.->|"produces instructions"| node_bytecode
node_bytecode -.->|"executes"| node_vm
node_vm -.->|"runs fibers"| node_fibers
node_vm -->|"uses memory manager"| node_gc
node_user -->|"embeds runtime"| node_api
node_corelib -.->|"offers event APIs"| node_eventloop
node_corelib -.->|"offers I/O APIs"| node_io
node_corelib -.->|"offers socket APIs"| node_network
node_corelib -.->|"offers system APIs"| node_os
node_corelib -.->|"offers FFI"| node_ffi
node_corelib -.->|"offers PEG"| node_peg
node_shell -->|"supports debugging"| node_debug

click node_shell "https://github.com/janet-lang/janet/blob/master/src/mainclient/shell.c"
click node_api "https://github.com/janet-lang/janet/blob/master/src/include/janet.h"
click node_parser "https://github.com/janet-lang/janet/blob/master/src/core/parse.c"
click node_peg "https://github.com/janet-lang/janet/blob/master/src/core/peg.c"
click node_compiler "https://github.com/janet-lang/janet/blob/master/src/core/compile.c"
click node_specials "https://github.com/janet-lang/janet/blob/master/src/core/specials.c"
click node_emitter "https://github.com/janet-lang/janet/blob/master/src/core/emit.c"
click node_allocator "https://github.com/janet-lang/janet/blob/master/src/core/regalloc.c"
click node_bytecode "https://github.com/janet-lang/janet/blob/master/src/core/bytecode.c"
click node_vm "https://github.com/janet-lang/janet/blob/master/src/core/vm.c"
click node_fibers "https://github.com/janet-lang/janet/blob/master/src/core/fiber.c"
click node_eventloop "https://github.com/janet-lang/janet/blob/master/src/core/ev.c"
click node_gc "https://github.com/janet-lang/janet/blob/master/src/core/gc.c"
click node_corelib "https://github.com/janet-lang/janet/blob/master/src/core/corelib.c"
click node_io "https://github.com/janet-lang/janet/blob/master/src/core/io.c"
click node_network "https://github.com/janet-lang/janet/blob/master/src/core/net.c"
click node_os "https://github.com/janet-lang/janet/blob/master/src/core/os.c"
click node_ffi "https://github.com/janet-lang/janet/blob/master/src/core/ffi.c"
click node_debug "https://github.com/janet-lang/janet/blob/master/src/core/debug.c"
click node_marshal "https://github.com/janet-lang/janet/blob/master/src/core/marsh.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_shell,node_api,node_user toneBlue
class node_parser,node_peg,node_compiler,node_specials,node_emitter,node_allocator toneAmber
class node_bytecode,node_vm,node_fibers,node_eventloop,node_gc toneMint
class node_corelib,node_io,node_network,node_os,node_ffi,node_debug,node_marshal toneRose
```

## Components

### Client

- [Shell and REPL](https://github.com/janet-lang/janet/blob/master/src/mainclient/shell.c): `src/mainclient/shell.c`
- [Embedding API](https://github.com/janet-lang/janet/blob/master/src/include/janet.h): `src/include/janet.h`

### Language processing

- [Parser](https://github.com/janet-lang/janet/blob/master/src/core/parse.c): `src/core/parse.c`
- [PEG engine](https://github.com/janet-lang/janet/blob/master/src/core/peg.c): `src/core/peg.c`
- [Compiler](https://github.com/janet-lang/janet/blob/master/src/core/compile.c): `src/core/compile.c`
- [Macros and specials](https://github.com/janet-lang/janet/blob/master/src/core/specials.c): `src/core/specials.c`
- [Bytecode emitter](https://github.com/janet-lang/janet/blob/master/src/core/emit.c): `src/core/emit.c`
- [Register allocator](https://github.com/janet-lang/janet/blob/master/src/core/regalloc.c): `src/core/regalloc.c`

### Execution runtime

- [Bytecode](https://github.com/janet-lang/janet/blob/master/src/core/bytecode.c): `src/core/bytecode.c`
- [Virtual machine](https://github.com/janet-lang/janet/blob/master/src/core/vm.c): `src/core/vm.c`
- [Fibers](https://github.com/janet-lang/janet/blob/master/src/core/fiber.c): `src/core/fiber.c`
- [Event loop](https://github.com/janet-lang/janet/blob/master/src/core/ev.c): `src/core/ev.c`
- [Garbage collector](https://github.com/janet-lang/janet/blob/master/src/core/gc.c): `src/core/gc.c`

### Core capabilities

- [Core library](https://github.com/janet-lang/janet/blob/master/src/core/corelib.c): `src/core/corelib.c`
- [I/O and processes](https://github.com/janet-lang/janet/blob/master/src/core/io.c): `src/core/io.c`
- [Networking](https://github.com/janet-lang/janet/blob/master/src/core/net.c): `src/core/net.c`
- [Operating system](https://github.com/janet-lang/janet/blob/master/src/core/os.c): `src/core/os.c`
- [C FFI](https://github.com/janet-lang/janet/blob/master/src/core/ffi.c): `src/core/ffi.c`
- [Debugger](https://github.com/janet-lang/janet/blob/master/src/core/debug.c): `src/core/debug.c`
- [Serialization](https://github.com/janet-lang/janet/blob/master/src/core/marsh.c): `src/core/marsh.c`

### Other components

- **Script user**

## Connections

- Script user → Shell and REPL: submits script
- Shell and REPL → Parser: runs source
- Parser → Compiler: produces syntax
- Compiler → Bytecode emitter: emits bytecode (evidence: `src/core/compile.c`)
- Compiler → Register allocator: allocates registers (evidence: `src/core/compile.c`)
- Bytecode emitter → Bytecode: produces instructions
- Bytecode → Virtual machine: executes
- Virtual machine → Fibers: runs fibers
- Virtual machine → Garbage collector: uses memory manager (evidence: `src/core/vm.c`)
- Script user → Embedding API: embeds runtime
- Core library → Event loop: offers event APIs
- Core library → I/O and processes: offers I/O APIs
- Core library → Networking: offers socket APIs
- Core library → Operating system: offers system APIs
- Core library → C FFI: offers FFI
- Core library → PEG engine: offers PEG
- Shell and REPL → Debugger: supports debugging
