# benevalterjr/nativa architecture

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

- Interactive diagram: https://gitdiagram.com/benevalterjr/nativa
- Repository: https://github.com/benevalterjr/nativa

## Overview

Nativa combines a Python-like DSL and interpreter with an AOT C99 path, tensor/model-loading facilities, and separate native local-LLM runtimes. The main user workflow is to run a Nativa program or quantize model weights and then generate text through chat or the API. The graph also preserves the documented BitNet, OpenCL, and benchmarking capabilities; several internal connections are based on README statements because the relevant implementation excerpts were not shown.

Main entry points: [`nativa.py`](https://github.com/benevalterjr/nativa/blob/main/nativa.py) (DSL Frontend), [`tools/nativa_engine.c`](https://github.com/benevalterjr/nativa/blob/main/tools/nativa_engine.c) (NATQ4 Engine), [`tools/chat_natq4.py`](https://github.com/benevalterjr/nativa/blob/main/tools/chat_natq4.py) (Interactive Chat), [`tools/nativa_sampling.h`](https://github.com/benevalterjr/nativa/blob/main/tools/nativa_sampling.h) (Token Sampling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_language["Language and Runtime"]
  node_frontend["DSL Frontend<br/>[nativa.py]"]
  node_semantic["Semantic Analyzer<br/>[nativa.py]"]
  node_interpreter["Interpreter<br/>[nativa.py]"]
  node_tensor["Tensor Runtime<br/>[nativa.py]"]
  node_safetensors["SafeTensors Loader<br/>[nativa.py]"]
  node_aot["AOT C99 Backend<br/>[nativa.py]"]
  node_native_rt["Native Runtime<br/>[nativa_rt.h]"]
  node_bitnet["BitNet Kernels<br/>[nativa.py]"]
  node_opencl["OpenCL Runtime<br/>[nativa_opencl.h]"]
end

subgraph group_model["Model Inference"]
  node_engine["NATQ4 Engine<br/>[nativa_engine.c]"]
  node_sampling["Token Sampling<br/>[nativa_sampling.h]"]
  node_qwen15["Qwen 1.5B Runner"]
  node_qwen15v1["Qwen 1.5B Runner V1"]
  node_qwen3["Qwen 3B Runner"]
  node_offsets["Model Offsets<br/>[qwen_offsets.h]"]
end

subgraph group_formats["Model Formats"]
  node_quantizer["Model Quantizer<br/>[nativa_quantize.py]"]
  node_natq4["NATQ4 Format<br/>[natq4_format.h]"]
end

subgraph group_interfaces["User Interfaces"]
  node_chat["Interactive Chat<br/>[chat_natq4.py]"]
  node_api["HTTP API Server<br/>[api_server.py]"]
  node_bundle["Model Bundler<br/>[nativa_bundle.py]"]
end

subgraph group_operations["Evaluation"]
  node_benchmark["Benchmark Suite"]
  node_experiment["Inference Evaluation"]
end

node_developer(("Developer"))
node_user(("Local User"))

node_developer -->|"writes programs"| node_frontend
node_user -->|"runs programs"| node_frontend
node_frontend -->|"analyzes syntax"| node_semantic
node_semantic -.->|"enables execution"| node_interpreter
node_interpreter -.->|"uses tensors"| node_tensor
node_user -->|"quantizes weights"| node_quantizer
node_quantizer -.->|"writes format"| node_natq4
node_user -->|"starts chat"| node_chat
node_chat -.->|"loads model"| node_natq4
node_chat -.->|"runs inference"| node_engine
node_user -->|"sends requests"| node_api
node_api -->|"imports bundler"| node_bundle
node_api -->|"imports runtime"| node_frontend
node_bundle -->|"imports runtime"| node_frontend
node_engine -->|"reads format"| node_natq4
node_engine -->|"uses sampling"| node_sampling
node_qwen15 -->|"uses sampling"| node_sampling
node_qwen15v1 -->|"uses sampling"| node_sampling
node_qwen3 -->|"uses sampling"| node_sampling
node_qwen15 -->|"imports offsets"| node_offsets
node_qwen15v1 -->|"imports offsets"| node_offsets
node_qwen3 -->|"imports offsets"| node_offsets
node_user -->|"builds program"| node_aot
node_aot -.->|"uses runtime"| node_native_rt
node_interpreter -.->|"loads weights"| node_safetensors
node_user -->|"runs benchmarks"| node_benchmark
node_benchmark -->|"imports chat tools"| node_chat
node_user -.->|"evaluates inference"| node_experiment
node_frontend -->|"supports ternary compute"| node_bitnet
node_engine -.->|"optional device path"| node_opencl

click node_frontend "https://github.com/benevalterjr/nativa/blob/main/nativa.py"
click node_semantic "https://github.com/benevalterjr/nativa/blob/main/nativa.py"
click node_interpreter "https://github.com/benevalterjr/nativa/blob/main/nativa.py"
click node_tensor "https://github.com/benevalterjr/nativa/blob/main/nativa.py"
click node_safetensors "https://github.com/benevalterjr/nativa/blob/main/nativa.py"
click node_aot "https://github.com/benevalterjr/nativa/blob/main/nativa.py"
click node_native_rt "https://github.com/benevalterjr/nativa/blob/main/nativa_rt.h"
click node_bitnet "https://github.com/benevalterjr/nativa/blob/main/nativa.py"
click node_opencl "https://github.com/benevalterjr/nativa/blob/main/tools/nativa_opencl.h"
click node_quantizer "https://github.com/benevalterjr/nativa/blob/main/tools/nativa_quantize.py"
click node_natq4 "https://github.com/benevalterjr/nativa/blob/main/tools/natq4_format.h"
click node_engine "https://github.com/benevalterjr/nativa/blob/main/tools/nativa_engine.c"
click node_sampling "https://github.com/benevalterjr/nativa/blob/main/tools/nativa_sampling.h"
click node_qwen15 "https://github.com/benevalterjr/nativa/blob/main/tools/qwen_1.5b_q4_native.c"
click node_qwen15v1 "https://github.com/benevalterjr/nativa/blob/main/tools/qwen_1.5b_q4_native_v1.c"
click node_qwen3 "https://github.com/benevalterjr/nativa/blob/main/tools/qwen_3b_q4_native.c"
click node_offsets "https://github.com/benevalterjr/nativa/blob/main/tools/qwen_offsets.h"
click node_chat "https://github.com/benevalterjr/nativa/blob/main/tools/chat_natq4.py"
click node_api "https://github.com/benevalterjr/nativa/blob/main/tools/api_server.py"
click node_bundle "https://github.com/benevalterjr/nativa/blob/main/tools/nativa_bundle.py"
click node_benchmark "https://github.com/benevalterjr/nativa/blob/main/tools/nativa_benchmark.py"
click node_experiment "https://github.com/benevalterjr/nativa/blob/main/tools/experimento_real_cortex_hipocampo.py"

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_frontend,node_semantic,node_interpreter,node_tensor,node_safetensors,node_aot,node_native_rt,node_bitnet,node_opencl,node_user toneBlue
class node_engine,node_sampling,node_qwen15,node_qwen15v1,node_qwen3,node_offsets toneAmber
class node_quantizer,node_natq4 toneMint
class node_chat,node_api,node_bundle toneRose
class node_benchmark,node_experiment,node_developer toneIndigo
```

## Components

### Language and Runtime

- [DSL Frontend](https://github.com/benevalterjr/nativa/blob/main/nativa.py): `nativa.py`
- [Semantic Analyzer](https://github.com/benevalterjr/nativa/blob/main/nativa.py): `nativa.py`
- [Interpreter](https://github.com/benevalterjr/nativa/blob/main/nativa.py): `nativa.py`
- [Tensor Runtime](https://github.com/benevalterjr/nativa/blob/main/nativa.py): `nativa.py`
- [SafeTensors Loader](https://github.com/benevalterjr/nativa/blob/main/nativa.py): `nativa.py`
- [AOT C99 Backend](https://github.com/benevalterjr/nativa/blob/main/nativa.py): `nativa.py`
- [Native Runtime](https://github.com/benevalterjr/nativa/blob/main/nativa_rt.h): `nativa_rt.h`
- [BitNet Kernels](https://github.com/benevalterjr/nativa/blob/main/nativa.py): `nativa.py`
- [OpenCL Runtime](https://github.com/benevalterjr/nativa/blob/main/tools/nativa_opencl.h): `tools/nativa_opencl.h`

### Model Inference

- [NATQ4 Engine](https://github.com/benevalterjr/nativa/blob/main/tools/nativa_engine.c): `tools/nativa_engine.c`
- [Token Sampling](https://github.com/benevalterjr/nativa/blob/main/tools/nativa_sampling.h): `tools/nativa_sampling.h`
- [Qwen 1.5B Runner](https://github.com/benevalterjr/nativa/blob/main/tools/qwen_1.5b_q4_native.c): `tools/qwen_1.5b_q4_native.c`
- [Qwen 1.5B Runner V1](https://github.com/benevalterjr/nativa/blob/main/tools/qwen_1.5b_q4_native_v1.c): `tools/qwen_1.5b_q4_native_v1.c`
- [Qwen 3B Runner](https://github.com/benevalterjr/nativa/blob/main/tools/qwen_3b_q4_native.c): `tools/qwen_3b_q4_native.c`
- [Model Offsets](https://github.com/benevalterjr/nativa/blob/main/tools/qwen_offsets.h): `tools/qwen_offsets.h`

### Model Formats

- [Model Quantizer](https://github.com/benevalterjr/nativa/blob/main/tools/nativa_quantize.py): `tools/nativa_quantize.py`
- [NATQ4 Format](https://github.com/benevalterjr/nativa/blob/main/tools/natq4_format.h): `tools/natq4_format.h`

### User Interfaces

- [Interactive Chat](https://github.com/benevalterjr/nativa/blob/main/tools/chat_natq4.py): `tools/chat_natq4.py`
- [HTTP API Server](https://github.com/benevalterjr/nativa/blob/main/tools/api_server.py): `tools/api_server.py`
- [Model Bundler](https://github.com/benevalterjr/nativa/blob/main/tools/nativa_bundle.py): `tools/nativa_bundle.py`

### Evaluation

- [Benchmark Suite](https://github.com/benevalterjr/nativa/blob/main/tools/nativa_benchmark.py): `tools/nativa_benchmark.py`
- [Inference Evaluation](https://github.com/benevalterjr/nativa/blob/main/tools/experimento_real_cortex_hipocampo.py): `tools/experimento_real_cortex_hipocampo.py`

### Other components

- **Developer**
- **Local User**

## Connections

- Developer → DSL Frontend: writes programs (evidence: `README.md`)
- Local User → DSL Frontend: runs programs (evidence: `README.md`)
- DSL Frontend → Semantic Analyzer: analyzes syntax (evidence: `README.md`)
- Semantic Analyzer → Interpreter: enables execution (evidence: `nativa.py`)
- Interpreter → Tensor Runtime: uses tensors (evidence: `nativa.py`)
- Local User → Model Quantizer: quantizes weights (evidence: `README.md`)
- Model Quantizer → NATQ4 Format: writes format
- Local User → Interactive Chat: starts chat (evidence: `README.md`)
- Interactive Chat → NATQ4 Format: loads model
- Interactive Chat → NATQ4 Engine: runs inference
- Local User → HTTP API Server: sends requests (evidence: `README.md`)
- HTTP API Server → Model Bundler: imports bundler (evidence: `tools/api_server.py`)
- HTTP API Server → DSL Frontend: imports runtime (evidence: `tools/api_server.py`)
- Model Bundler → DSL Frontend: imports runtime (evidence: `tools/nativa_bundle.py`)
- NATQ4 Engine → NATQ4 Format: reads format (evidence: `tools/nativa_engine.c`)
- NATQ4 Engine → Token Sampling: uses sampling (evidence: `tools/nativa_engine.c`)
- Qwen 1.5B Runner → Token Sampling: uses sampling (evidence: `tools/qwen_1.5b_q4_native.c`)
- Qwen 1.5B Runner V1 → Token Sampling: uses sampling (evidence: `tools/qwen_1.5b_q4_native_v1.c`)
- Qwen 3B Runner → Token Sampling: uses sampling (evidence: `tools/qwen_3b_q4_native.c`)
- Qwen 1.5B Runner → Model Offsets: imports offsets (evidence: `tools/qwen_1.5b_q4_native.c`)
- Qwen 1.5B Runner V1 → Model Offsets: imports offsets (evidence: `tools/qwen_1.5b_q4_native_v1.c`)
- Qwen 3B Runner → Model Offsets: imports offsets (evidence: `tools/qwen_3b_q4_native.c`)
- Local User → AOT C99 Backend: builds program (evidence: `README.md`)
- AOT C99 Backend → Native Runtime: uses runtime
- Interpreter → SafeTensors Loader: loads weights (evidence: `nativa.py`)
- Local User → Benchmark Suite: runs benchmarks (evidence: `README.md`)
- Benchmark Suite → Interactive Chat: imports chat tools (evidence: `tools/nativa_benchmark.py`)
- Local User → Inference Evaluation: evaluates inference
- DSL Frontend → BitNet Kernels: supports ternary compute (evidence: `README.md`)
- NATQ4 Engine → OpenCL Runtime: optional device path
