# alve-dev/zonetic-vm architecture

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

- Interactive diagram: https://gitdiagram.com/alve-dev/zonetic-vm
- Repository: https://github.com/alve-dev/zonetic-vm

## Overview

ZonVM is a bytecode virtual machine for Zonetic programs. The principal workflow is a user-supplied .zbc file being validated and section-loaded by the executable, then executed by the VM; execution updates registers and RAM, performs arithmetic, memory and control-flow instructions, and handles ECALL services such as printing and exit. The runtime also provides guarded stack allocation and heap/stack services. The excerpts show the loader-to-VM handoff and representative instruction and syscall handling; detailed handler coverage is partial.

Main entry points: [`src/zon_vm.cpp`](https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp) (Instruction dispatch), [`include/zon_vm.hpp`](https://github.com/alve-dev/zonetic-vm/blob/main/include/zon_vm.hpp) (VM RAM), [`src/main.cpp`](https://github.com/alve-dev/zonetic-vm/blob/main/src/main.cpp) (File validation and loading), [`include/common.hpp`](https://github.com/alve-dev/zonetic-vm/blob/main/include/common.hpp) (ISA definitions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_loader["Bytecode loading"]
  node_loader["File validation and loading<br/>[main.cpp]"]
end

subgraph group_runtime["VM execution"]
  node_isa["ISA definitions<br/>[common.hpp]"]
  node_vm["VM state and interface<br/>[zon_vm.hpp]"]
  node_dispatch["Instruction dispatch<br/>[zon_vm.cpp]"]
  node_arithmetic["Integer and FP operations<br/>[zon_vm.cpp]"]
  node_control["Branches and calls<br/>[zon_vm.cpp]"]
  node_strings["String operations<br/>[zon_vm.cpp]"]
end

subgraph group_memory["Memory management"]
  node_ram[("VM RAM<br/>[zon_vm.hpp]")]
  node_allocator["RAM allocator<br/>[zon_vm.hpp]"]
  node_stack["Guarded stack<br/>[zon_vm.hpp]"]
  node_memory_ops["Load and store<br/>[zon_vm.cpp]"]
  node_heap["Heap services<br/>[zon_vm.cpp]"]
end

subgraph group_services["Runtime services"]
  node_ecall["ECALL services<br/>[zon_vm.cpp]"]
  node_output["Print and exit<br/>[zon_vm.cpp]"]
end

node_user(("Program user"))
node_bytecode["Zonetic bytecode"]
node_os(("Host operating system"))

node_user -->|"provides"| node_bytecode
node_user -->|"runs with"| node_loader
node_loader -->|"reads"| node_bytecode
node_loader -->|"loads and runs"| node_vm
node_vm -->|"stores state"| node_ram
node_vm -->|"allocates through"| node_allocator
node_allocator -->|"requests memory"| node_os
node_dispatch -->|"dispatches"| node_arithmetic
node_dispatch -.->|"dispatches"| node_control
node_dispatch -->|"dispatches"| node_memory_ops
node_dispatch -->|"dispatches"| node_strings
node_dispatch -->|"dispatches"| node_ecall
node_arithmetic -->|"uses encodings"| node_isa
node_memory_ops -->|"reads and writes"| node_ram
node_strings -->|"reads and writes"| node_ram
node_ecall -->|"handles print and exit"| node_output
node_ecall -->|"handles heap calls"| node_heap
node_heap -->|"reads and writes"| node_ram
node_allocator -->|"protects stack region"| node_stack
node_stack -->|"sets guard protection"| node_os

click node_loader "https://github.com/alve-dev/zonetic-vm/blob/main/src/main.cpp"
click node_isa "https://github.com/alve-dev/zonetic-vm/blob/main/include/common.hpp"
click node_vm "https://github.com/alve-dev/zonetic-vm/blob/main/include/zon_vm.hpp"
click node_dispatch "https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp"
click node_arithmetic "https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp"
click node_control "https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp"
click node_strings "https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp"
click node_ram "https://github.com/alve-dev/zonetic-vm/blob/main/include/zon_vm.hpp"
click node_allocator "https://github.com/alve-dev/zonetic-vm/blob/main/include/zon_vm.hpp"
click node_stack "https://github.com/alve-dev/zonetic-vm/blob/main/include/zon_vm.hpp"
click node_memory_ops "https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp"
click node_heap "https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp"
click node_ecall "https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp"
click node_output "https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp"

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_loader,node_user toneBlue
class node_isa,node_vm,node_dispatch,node_arithmetic,node_control,node_strings toneAmber
class node_ram,node_allocator,node_stack,node_memory_ops,node_heap toneMint
class node_ecall,node_output toneRose
class node_bytecode,node_os toneIndigo
```

## Components

### Bytecode loading

- [File validation and loading](https://github.com/alve-dev/zonetic-vm/blob/main/src/main.cpp): `src/main.cpp`

### VM execution

- [ISA definitions](https://github.com/alve-dev/zonetic-vm/blob/main/include/common.hpp): `include/common.hpp`
- [VM state and interface](https://github.com/alve-dev/zonetic-vm/blob/main/include/zon_vm.hpp): `include/zon_vm.hpp`
- [Instruction dispatch](https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp): `src/zon_vm.cpp`
- [Integer and FP operations](https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp): `src/zon_vm.cpp`
- [Branches and calls](https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp): `src/zon_vm.cpp`
- [String operations](https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp): `src/zon_vm.cpp`

### Memory management

- [VM RAM](https://github.com/alve-dev/zonetic-vm/blob/main/include/zon_vm.hpp): `include/zon_vm.hpp`
- [RAM allocator](https://github.com/alve-dev/zonetic-vm/blob/main/include/zon_vm.hpp): `include/zon_vm.hpp`
- [Guarded stack](https://github.com/alve-dev/zonetic-vm/blob/main/include/zon_vm.hpp): `include/zon_vm.hpp`
- [Load and store](https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp): `src/zon_vm.cpp`
- [Heap services](https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp): `src/zon_vm.cpp`

### Runtime services

- [ECALL services](https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp): `src/zon_vm.cpp`
- [Print and exit](https://github.com/alve-dev/zonetic-vm/blob/main/src/zon_vm.cpp): `src/zon_vm.cpp`

### Other components

- **Program user**
- **Zonetic bytecode**
- **Host operating system**

## Connections

- Program user → Zonetic bytecode: provides (evidence: `README.md`)
- Program user → File validation and loading: runs with (evidence: `src/main.cpp`)
- File validation and loading → Zonetic bytecode: reads (evidence: `src/main.cpp`)
- File validation and loading → VM state and interface: loads and runs (evidence: `src/main.cpp`)
- VM state and interface → VM RAM: stores state (evidence: `include/zon_vm.hpp`)
- VM state and interface → RAM allocator: allocates through (evidence: `include/zon_vm.hpp`)
- RAM allocator → Host operating system: requests memory (evidence: `include/zon_vm.hpp`)
- Instruction dispatch → Integer and FP operations: dispatches (evidence: `src/zon_vm.cpp`)
- Instruction dispatch → Branches and calls: dispatches (evidence: `src/zon_vm.cpp`)
- Instruction dispatch → Load and store: dispatches (evidence: `src/zon_vm.cpp`)
- Instruction dispatch → String operations: dispatches (evidence: `src/zon_vm.cpp`)
- Instruction dispatch → ECALL services: dispatches (evidence: `src/zon_vm.cpp`)
- Integer and FP operations → ISA definitions: uses encodings (evidence: `include/common.hpp`)
- Load and store → VM RAM: reads and writes (evidence: `src/zon_vm.cpp`)
- String operations → VM RAM: reads and writes (evidence: `src/zon_vm.cpp`)
- ECALL services → Print and exit: handles print and exit (evidence: `src/zon_vm.cpp`)
- ECALL services → Heap services: handles heap calls (evidence: `src/zon_vm.cpp`)
- Heap services → VM RAM: reads and writes (evidence: `src/zon_vm.cpp`)
- RAM allocator → Guarded stack: protects stack region (evidence: `include/zon_vm.hpp`)
- Guarded stack → Host operating system: sets guard protection (evidence: `include/zon_vm.hpp`)
