# programmerkr/proxpl architecture

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

- Interactive diagram: https://gitdiagram.com/programmerkr/proxpl
- Repository: https://github.com/programmerkr/proxpl

## Overview

#### 1. Repository Purpose and Entrypoints
ProXPL is a C/C++ implementation of a statically typed systems language: it compiles `.prox` source to stack-VM bytecode or LLVM-backed native output. The native executable entrypoints are `main.c` and `src/main.c`; public subsystem contracts are in `include/compiler.h` and `include/vm.h`. Build orchestration is CMake-based through `CMakeLists.txt`.

A Node.js developer CLI wraps execution, builds, and REPL workflows: `src/cli/index.js`, `src/cli/commands/run.js`, and `src/cli/commands/build.js`.

#### 2. Frontend: Source to Validated AST
The compiler frontend tokenizes ProX syntax, constructs ASTs, resolves imports, and performs static semantic/type validation. This is the primary language-definition boundary: syntax and semantic changes normally span scanner, parser/AST, and checker.

- Lexer: `src/compiler/lexer/scanner.c`
- AST/parser: `src/compiler/parser/ast.c`, `src/compiler/parser/parser.c`
- Imports and typing: `src/compiler/importer.c`, `src/compiler/type_checker.c`

Source modules may draw on language-level standard-library modules under `std/lib/`, such as `std/lib/math.prox` and `std/lib/io.prox`.

#### 3. Lowering and Compilation Backends
Validated ASTs lower into an intermediate representation, which is optimized before selecting a code-generation path. This creates the key boundary between language semantics and executable representation.

- IR construction and optimization: `src/compiler/ir_gen.c`, `src/compiler/ir.c`, `src/compiler/ir_opt.c`
- VM bytecode emission: `src/compiler/bytecode_gen.c`
- LLVM AOT backend: `src/compiler/backend_llvm.cpp`

The usual flow is `.prox` → tokens → AST → type check → IR → optimized IR → bytecode/LLVM. LLVM is an optional material external dependency for AOT compilation; the ordinary VM path remains native C/C++ runtime code.

#### 4. Bytecode VM and Execution Semantics
Bytecode is represented, decoded, dispatched, and executed by the VM layer. It is the runtime control boundary for stack execution, function/object behavior, intent/context dispatch, and exception/recovery mechanisms.

- Bytecode representation/disassembly: `src/vm/bytecode.c`, `src/vm/disasm.c`
- VM dispatch/core implementations: `src/vm/vm_dispatch.c`, `src/vm/vm_core_opt.c`, `src/vm/vm_v2.c`
- Runtime VM integration: `src/runtime/vm.c`, `src/runtime/compiler.c`

The architecture documentation for instruction and VM contracts lives at `docs/architecture/BYTECODE_SPEC.md` and `docs/architecture/VM_ARCHITECTURE.md`.

#### 5. Managed Runtime, Native Interop, and ASR
The runtime owns object/value representation, allocation, mark-and-sweep garbage collection, scheduling/supervision, and foreign-function bridging. These are cross-cutting services consumed by VM instructions and native library functions.

- Objects, values, memory, and GC: `src/runtime/object.c`, `src/runtime/value.c`, `src/runtime/gc.c`
- Scheduling and supervision: `src/runtime/scheduler.c`, `src/runtime/supervisor.c`
- Dynamic-library FFI: `src/runtime/ffi_bridge.c`, `include/ffi_bridge.h`

Autonomic Self-Healing (ASR) has a separate C++ runtime implementation, including lock-free queues and supervision: `runtime/asr_runtime.cpp`, `runtime/asr_supervisor.cpp`, and `runtime/asr_lockfree_queue.cpp`.

#### 6. Standard Library and Package Boundary
Language-facing standard modules are implemented partly in ProX and partly as VM-registered native C functions. This boundary exposes filesystem, network, process, JSON, collections, and system capabilities to user programs.

- Native registration/core: `src/stdlib/stdlib_core.c`, `src/stdlib/core_native.c`
- Capability examples: `src/stdlib/fs_native.c`, `src/stdlib/net_native.c`, `src/stdlib/process_native.c`
- ProX module surface: `std/lib/`, `std/lib/collections.prox`

PRM manages project manifests, dependencies, and package-related commands: `src/prm/builder.c`, `src/prm/manifest.c`, and `src/prm/commands/cmd_core.c`.

#### 7. Developer Ecosystem
The VS Code extension provides syntax configuration, editor integration, and a Node/TypeScript language server; it is separate from compiler execution but depends on language syntax/contracts.

- Extension activation: `extension/src/extension.ts`
- Language server: `extension/server/src/server.ts`
- Grammar: `extension/syntaxes/proxpl.tmLanguage.json`

Cross-platform CI, releases, and security scanning run through GitHub Actions: `.github/workflows/build.yml`, `.github/workflows/release.yml`, and `.github/workflows/snyk-security.yml`.

Main entry points: [`src/vm/vm_dispatch.c`](https://github.com/programmerkr/proxpl/blob/main/src/vm/vm_dispatch.c) (Stack VM dispatch), [`std/lib/math.prox`](https://github.com/programmerkr/proxpl/blob/main/std/lib/math.prox) (ProX source modules), [`src/compiler/ir_opt.c`](https://github.com/programmerkr/proxpl/blob/main/src/compiler/ir_opt.c) (IR optimizer), [`src/compiler/parser/parser.c`](https://github.com/programmerkr/proxpl/blob/main/src/compiler/parser/parser.c) (Parser and AST)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_tooling["Developer Tooling"]
  node_cli["Node developer CLI<br/>Node.js CLI<br/>[index.js]"]
  node_native_entry["Native compiler entry<br/>C entrypoint<br/>[main.c]"]
  node_cmake["CMake build<br/>build orchestration<br/>[CMakeLists.txt]"]
  node_prm["PRM packages<br/>package manager<br/>[builder.c]"]
end

subgraph group_compiler["Compiler Pipeline"]
  node_source["ProX source modules<br/>language input<br/>[math.prox]"]
  node_lexer["Scanner<br/>lexer<br/>[scanner.c]"]
  node_parser_ast["Parser and AST<br/>syntax frontend<br/>[parser.c]"]
  node_semantic["Imports and type checker<br/>semantic analysis<br/>[type_checker.c]"]
  node_ir_generation["IR construction<br/>lowering<br/>[ir_gen.c]"]
  node_ir_optimizer["IR optimizer<br/>optimization<br/>[ir_opt.c]"]
  node_bytecode_backend["Bytecode generator<br/>VM backend<br/>[bytecode_gen.c]"]
  node_llvm_backend["LLVM AOT backend<br/>native backend<br/>[backend_llvm.cpp]"]
end

subgraph group_runtime["VM and Runtime"]
  node_bytecode["Bytecode representation<br/>bytecode format<br/>[bytecode.c]"]
  node_vm["Stack VM dispatch<br/>VM execution<br/>[vm_dispatch.c]"]
  node_managed_runtime["Managed runtime<br/>objects, GC, scheduling<br/>[gc.c]"]
  node_ffi["Native FFI bridge<br/>dynamic-library interop<br/>[ffi_bridge.c]"]
  node_asr["ASR runtime<br/>self-healing runtime<br/>[asr_runtime.cpp]"]
end

subgraph group_ecosystem["Language Ecosystem"]
  node_stdlib["Standard library<br/>ProX and native modules<br/>[stdlib_core.c]"]
  node_extension["VS Code extension<br/>editor integration<br/>[extension.ts]"]
  node_language_server["Language server<br/>Node/TypeScript LSP<br/>[server.ts]"]
  node_ci["GitHub Actions<br/>CI and releases<br/>[build.yml]"]
end

node_cmake -->|"builds"| node_native_entry
node_cli -->|"invokes"| node_native_entry
node_prm -->|"resolves packages"| node_source
node_source -->|"tokenizes"| node_lexer
node_lexer -->|"tokens"| node_parser_ast
node_parser_ast -->|"AST"| node_semantic
node_semantic -->|"validated AST"| node_ir_generation
node_ir_generation -->|"IR"| node_ir_optimizer
node_ir_optimizer -->|"optimized IR"| node_bytecode_backend
node_ir_optimizer -->|"optimized IR"| node_llvm_backend
node_bytecode_backend -->|"emits"| node_bytecode
node_bytecode -->|"decoded and executed"| node_vm
node_vm -->|"uses objects, GC, scheduling"| node_managed_runtime
node_vm -->|"native calls"| node_ffi
node_managed_runtime -->|"supervision support"| node_asr
node_stdlib -->|"registers native functions"| node_vm
node_source -.->|"imports modules"| node_stdlib
node_extension -->|"activates"| node_language_server
node_language_server -.->|"uses language contracts"| node_parser_ast
node_ci -->|"builds and validates"| node_cmake

click node_cli "https://github.com/programmerkr/proxpl/blob/main/src/cli/index.js"
click node_native_entry "https://github.com/programmerkr/proxpl/blob/main/src/main.c"
click node_cmake "https://github.com/programmerkr/proxpl/blob/main/CMakeLists.txt"
click node_prm "https://github.com/programmerkr/proxpl/blob/main/src/prm/builder.c"
click node_source "https://github.com/programmerkr/proxpl/blob/main/std/lib/math.prox"
click node_lexer "https://github.com/programmerkr/proxpl/blob/main/src/compiler/lexer/scanner.c"
click node_parser_ast "https://github.com/programmerkr/proxpl/blob/main/src/compiler/parser/parser.c"
click node_semantic "https://github.com/programmerkr/proxpl/blob/main/src/compiler/type_checker.c"
click node_ir_generation "https://github.com/programmerkr/proxpl/blob/main/src/compiler/ir_gen.c"
click node_ir_optimizer "https://github.com/programmerkr/proxpl/blob/main/src/compiler/ir_opt.c"
click node_bytecode_backend "https://github.com/programmerkr/proxpl/blob/main/src/compiler/bytecode_gen.c"
click node_llvm_backend "https://github.com/programmerkr/proxpl/blob/main/src/compiler/backend_llvm.cpp"
click node_bytecode "https://github.com/programmerkr/proxpl/blob/main/src/vm/bytecode.c"
click node_vm "https://github.com/programmerkr/proxpl/blob/main/src/vm/vm_dispatch.c"
click node_managed_runtime "https://github.com/programmerkr/proxpl/blob/main/src/runtime/gc.c"
click node_ffi "https://github.com/programmerkr/proxpl/blob/main/src/runtime/ffi_bridge.c"
click node_asr "https://github.com/programmerkr/proxpl/blob/main/runtime/asr_runtime.cpp"
click node_stdlib "https://github.com/programmerkr/proxpl/blob/main/src/stdlib/stdlib_core.c"
click node_extension "https://github.com/programmerkr/proxpl/blob/main/extension/src/extension.ts"
click node_language_server "https://github.com/programmerkr/proxpl/blob/main/extension/server/src/server.ts"
click node_ci "https://github.com/programmerkr/proxpl/blob/main/.github/workflows/build.yml"

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_native_entry,node_cmake,node_prm toneBlue
class node_source,node_lexer,node_parser_ast,node_semantic,node_ir_generation,node_ir_optimizer,node_bytecode_backend,node_llvm_backend toneAmber
class node_bytecode,node_vm,node_managed_runtime,node_ffi,node_asr toneMint
class node_stdlib,node_extension,node_language_server,node_ci toneRose
```

## Components

### Developer Tooling

- [Node developer CLI](https://github.com/programmerkr/proxpl/blob/main/src/cli/index.js): Node.js CLI · Wraps run, build, and REPL workflows. · `src/cli/index.js`
- [Native compiler entry](https://github.com/programmerkr/proxpl/blob/main/src/main.c): C entrypoint · `src/main.c`
- [CMake build](https://github.com/programmerkr/proxpl/blob/main/CMakeLists.txt): build orchestration · `CMakeLists.txt`
- [PRM packages](https://github.com/programmerkr/proxpl/blob/main/src/prm/builder.c): package manager · Manages manifests, dependencies, and package commands. · `src/prm/builder.c`

### Compiler Pipeline

- [ProX source modules](https://github.com/programmerkr/proxpl/blob/main/std/lib/math.prox): language input · `std/lib/math.prox`
- [Scanner](https://github.com/programmerkr/proxpl/blob/main/src/compiler/lexer/scanner.c): lexer · `src/compiler/lexer/scanner.c`
- [Parser and AST](https://github.com/programmerkr/proxpl/blob/main/src/compiler/parser/parser.c): syntax frontend · `src/compiler/parser/parser.c`
- [Imports and type checker](https://github.com/programmerkr/proxpl/blob/main/src/compiler/type_checker.c): semantic analysis · `src/compiler/type_checker.c`
- [IR construction](https://github.com/programmerkr/proxpl/blob/main/src/compiler/ir_gen.c): lowering · `src/compiler/ir_gen.c`
- [IR optimizer](https://github.com/programmerkr/proxpl/blob/main/src/compiler/ir_opt.c): optimization · `src/compiler/ir_opt.c`
- [Bytecode generator](https://github.com/programmerkr/proxpl/blob/main/src/compiler/bytecode_gen.c): VM backend · `src/compiler/bytecode_gen.c`
- [LLVM AOT backend](https://github.com/programmerkr/proxpl/blob/main/src/compiler/backend_llvm.cpp): native backend · Optional LLVM-backed native output. · `src/compiler/backend_llvm.cpp`

### VM and Runtime

- [Bytecode representation](https://github.com/programmerkr/proxpl/blob/main/src/vm/bytecode.c): bytecode format · `src/vm/bytecode.c`
- [Stack VM dispatch](https://github.com/programmerkr/proxpl/blob/main/src/vm/vm_dispatch.c): VM execution · Executes bytecode and implements stack control semantics. · `src/vm/vm_dispatch.c`
- [Managed runtime](https://github.com/programmerkr/proxpl/blob/main/src/runtime/gc.c): objects, GC, scheduling · Owns values, allocation, garbage collection, and supervision. · `src/runtime/gc.c`
- [Native FFI bridge](https://github.com/programmerkr/proxpl/blob/main/src/runtime/ffi_bridge.c): dynamic-library interop · `src/runtime/ffi_bridge.c`
- [ASR runtime](https://github.com/programmerkr/proxpl/blob/main/runtime/asr_runtime.cpp): self-healing runtime · Provides lock-free queues and autonomous supervision. · `runtime/asr_runtime.cpp`

### Language Ecosystem

- [Standard library](https://github.com/programmerkr/proxpl/blob/main/src/stdlib/stdlib_core.c): ProX and native modules · Registers native capabilities exposed to language modules. · `src/stdlib/stdlib_core.c`
- [VS Code extension](https://github.com/programmerkr/proxpl/blob/main/extension/src/extension.ts): editor integration · `extension/src/extension.ts`
- [Language server](https://github.com/programmerkr/proxpl/blob/main/extension/server/src/server.ts): Node/TypeScript LSP · `extension/server/src/server.ts`
- [GitHub Actions](https://github.com/programmerkr/proxpl/blob/main/.github/workflows/build.yml): CI and releases · `.github/workflows/build.yml`

## Connections

- CMake build → Native compiler entry: builds
- Node developer CLI → Native compiler entry: invokes
- PRM packages → ProX source modules: resolves packages
- ProX source modules → Scanner: tokenizes
- Scanner → Parser and AST: tokens
- Parser and AST → Imports and type checker: AST
- Imports and type checker → IR construction: validated AST
- IR construction → IR optimizer: IR
- IR optimizer → Bytecode generator: optimized IR
- IR optimizer → LLVM AOT backend: optimized IR
- Bytecode generator → Bytecode representation: emits
- Bytecode representation → Stack VM dispatch: decoded and executed
- Stack VM dispatch → Managed runtime: uses objects, GC, scheduling
- Stack VM dispatch → Native FFI bridge: native calls
- Managed runtime → ASR runtime: supervision support
- Standard library → Stack VM dispatch: registers native functions
- ProX source modules → Standard library: imports modules
- VS Code extension → Language server: activates
- Language server → Parser and AST: uses language contracts
- GitHub Actions → CMake build: builds and validates
