# 7zonesystems/nativelab architecture

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

- Interactive diagram: https://gitdiagram.com/7zonesystems/nativelab
- Repository: https://github.com/7zonesystems/nativelab

## Overview

#### Purpose and entry points
NativeLab is a local-first LLM workbench: desktop GUI, interactive CLI, local API server, visual multi-model pipelines, and experimental “Labs.” Its Android companion, PhonoLab, runs local models on-device and can expose them over LAN. Primary desktop entry points are `nativelab/__main__.py`, `nativelab/main.py`, and `nativelab/cli/app.py`; standalone serving is `nativelab/server.py`. Android starts through `PhonoLab/android/app/src/main/java/org/nativelab/phonolab/MainActivity.kt`.

#### Desktop shell and shared application state
The Python desktop app is PyQt6-based. The main window composes chat, models, sessions, server/runtime controls, documents, and Labs-oriented panels; Qt workers isolate background operations. Shared global configuration, hardware detection, binary resolution, and timeouts support all front ends.
Paths: `nativelab/UI/mainwindow/window.py`, `nativelab/UI/mainwindow/ui_build.py`, `nativelab/GlobalConfig/config_global.py`.

#### Model registry, acquisition, and runtime routing
Model metadata and family/template selection are separated from execution. The application supports local GGUF through llama.cpp, existing Ollama models, optional Hugging Face Transformers, and remote OpenAI-compatible/Anthropic API models. Download/auth helpers form the external-provider boundary, while engine selection and loading feed a common runtime state.
Paths: `nativelab/Model/ModelRegistry.py`, `nativelab/core/model_loaders.py`, `nativelab/core/engines/llamaengine.py`.

#### Inference and streaming control flow
Chat, CLI, pipelines, Labs, integrations, and HTTP serving converge on backend/engine abstractions. Requests are dispatched to local llama.cpp, API, or server backends; streamer workers return incremental output for the respective consumer. Runtime status and errors are centralized rather than owned by UI surfaces.
Paths: `nativelab/core/backend.py`, `nativelab/core/streamerworker/backendstreamer.py`, `nativelab/core/llm_errors.py`.

#### Workflows: documents, pipelines, and Labs
Document-reference parsing and PDF summarization prepare context for inference. The pipeline builder represents workflows as editable graphs, validates them, executes nodes in a worker/core layer, and persists example/user pipeline definitions. Labs is an extension boundary: panels receive endpoint access instead of directly controlling engines.
Paths: `nativelab/pipelinebuilder/pipebuilder.py`, `nativelab/pipelinebuilder/execution_core.py`, `nativelab/labs/endpoints.py`.

#### Local and external service boundaries
The app can host local model APIs and integration endpoints, discover PhonoLab devices on a LAN, and route requests to registered API-model endpoints. External dependencies include llama.cpp binaries, Ollama, Hugging Face downloads/auth and optional Transformers runtime, OpenAI-compatible APIs, Anthropic, MCP, Discord, WhatsApp, and the bundled SearXNG-derived search subsystem.
Paths: `nativelab/api_server/server.py`, `nativelab/api_server/device_discovery.py`, `nativelab/integrations/http_endpoint.py`.

#### PhonoLab Android architecture
PhonoLab is a separate Kotlin/Android runtime with chat/session/model storage, safe model downloads, document RAG, and a LAN-compatible API server. Kotlin controls llama.cpp lifecycle; a C++ JNI runner bridges to native execution and packaged Android runtimes. The Android app is therefore both a local client and a discoverable inference endpoint for NativeLab.
Paths: `PhonoLab/android/app/src/main/java/org/nativelab/phonolab/LlamaCppManager.kt`, `PhonoLab/android/app/src/main/java/org/nativelab/phonolab/api/PhonoLabApiServer.kt`, `PhonoLab/android/app/src/main/cpp/runner.cpp`.

Main entry points: [`nativelab/core/backend.py`](https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/backend.py) (Backend abstraction), [`nativelab/core/model_loaders.py`](https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/model_loaders.py) (Model loaders), [`nativelab/UI/mainwindow/window.py`](https://github.com/7zonesystems/nativelab/blob/main/nativelab/UI/mainwindow/window.py) (PyQt main window), [`nativelab/api_server/server.py`](https://github.com/7zonesystems/nativelab/blob/main/nativelab/api_server/server.py) (Local API server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop Front Ends"]
  node_desktop_entry["Desktop entry points<br/>Python launchers<br/>[__main__.py]"]
  node_main_window["PyQt main window<br/>desktop shell<br/>[window.py]"]
  node_global_config["Shared app state<br/>configuration runtime<br/>[config_global.py]"]
end

subgraph group_runtime["Model Runtime"]
  node_model_registry[("Model registry<br/>model metadata<br/>[ModelRegistry.py]")]
  node_model_loaders["Model loaders<br/>engine routing<br/>[model_loaders.py]"]
  node_llama_engine["llama.cpp engine<br/>local inference engine<br/>[llamaengine.py]"]
  node_backend["Backend abstraction<br/>inference dispatcher<br/>[backend.py]"]
  node_streamer["Streaming worker<br/>incremental output<br/>[backendstreamer.py]"]
  node_errors["Runtime errors<br/>error state<br/>[llm_errors.py]"]
end

subgraph group_workflows["Workflows"]
  node_pipeline_builder["Pipeline builder<br/>visual workflow editor<br/>[pipebuilder.py]"]
  node_pipeline_executor["Pipeline execution core<br/>workflow executor<br/>[execution_core.py]"]
  node_labs_endpoints["Labs endpoints<br/>extension boundary<br/>[endpoints.py]"]
end

subgraph group_services["Service Boundaries"]
  node_api_server["Local API server<br/>HTTP serving<br/>[server.py]"]
  node_device_discovery["LAN device discovery<br/>PhonoLab discovery"]
  node_integration_endpoint["Integration HTTP endpoint<br/>external integration<br/>[http_endpoint.py]"]
  node_external_providers{{"External providers<br/>model and integration services"}}
end

subgraph group_android["PhonoLab Android"]
  node_phonolab_app["PhonoLab app<br/>Android local client<br/>[MainActivity.kt]"]
  node_phonolab_manager["llama.cpp lifecycle<br/>Android runtime manager<br/>[LlamaCppManager.kt]"]
  node_phonolab_api["PhonoLab LAN API<br/>Android API server"]
  node_jni_runner["JNI native runner<br/>C++ bridge<br/>[runner.cpp]"]
end

node_desktop_entry -->|"launches GUI"| node_main_window
node_main_window -->|"uses"| node_global_config
node_main_window -->|"submits inference"| node_backend
node_global_config -->|"supplies runtime settings"| node_model_loaders
node_model_registry -->|"selects model family"| node_model_loaders
node_model_loaders -->|"loads GGUF"| node_llama_engine
node_model_loaders -->|"uses remote and optional runtimes"| node_external_providers
node_backend -->|"dispatches local requests"| node_llama_engine
node_backend -->|"dispatches API requests"| node_external_providers
node_backend -->|"streams responses"| node_streamer
node_backend -->|"reports status"| node_errors
node_pipeline_builder -->|"validates and runs graph"| node_pipeline_executor
node_pipeline_executor -->|"executes inference nodes"| node_backend
node_labs_endpoints -->|"consumes endpoint access"| node_backend
node_api_server -->|"serves inference"| node_backend
node_integration_endpoint -->|"connects integrations"| node_api_server
node_device_discovery -.->|"discovers on LAN"| node_phonolab_api
node_phonolab_app -->|"controls runtime"| node_phonolab_manager
node_phonolab_manager -->|"invokes native execution"| node_jni_runner
node_phonolab_api -->|"serves on-device inference"| node_phonolab_manager
node_api_server -.->|"routes registered device requests"| node_phonolab_api

click node_desktop_entry "https://github.com/7zonesystems/nativelab/blob/main/nativelab/__main__.py"
click node_main_window "https://github.com/7zonesystems/nativelab/blob/main/nativelab/UI/mainwindow/window.py"
click node_global_config "https://github.com/7zonesystems/nativelab/blob/main/nativelab/GlobalConfig/config_global.py"
click node_model_registry "https://github.com/7zonesystems/nativelab/blob/main/nativelab/Model/ModelRegistry.py"
click node_model_loaders "https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/model_loaders.py"
click node_llama_engine "https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/engines/llamaengine.py"
click node_backend "https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/backend.py"
click node_streamer "https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/streamerworker/backendstreamer.py"
click node_errors "https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/llm_errors.py"
click node_pipeline_builder "https://github.com/7zonesystems/nativelab/blob/main/nativelab/pipelinebuilder/pipebuilder.py"
click node_pipeline_executor "https://github.com/7zonesystems/nativelab/blob/main/nativelab/pipelinebuilder/execution_core.py"
click node_labs_endpoints "https://github.com/7zonesystems/nativelab/blob/main/nativelab/labs/endpoints.py"
click node_api_server "https://github.com/7zonesystems/nativelab/blob/main/nativelab/api_server/server.py"
click node_device_discovery "https://github.com/7zonesystems/nativelab/blob/main/nativelab/api_server/device_discovery.py"
click node_integration_endpoint "https://github.com/7zonesystems/nativelab/blob/main/nativelab/integrations/http_endpoint.py"
click node_phonolab_app "https://github.com/7zonesystems/nativelab/blob/main/PhonoLab/android/app/src/main/java/org/nativelab/phonolab/MainActivity.kt"
click node_phonolab_manager "https://github.com/7zonesystems/nativelab/blob/main/PhonoLab/android/app/src/main/java/org/nativelab/phonolab/LlamaCppManager.kt"
click node_phonolab_api "https://github.com/7zonesystems/nativelab/blob/main/PhonoLab/android/app/src/main/java/org/nativelab/phonolab/api/PhonoLabApiServer.kt"
click node_jni_runner "https://github.com/7zonesystems/nativelab/blob/main/PhonoLab/android/app/src/main/cpp/runner.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_desktop_entry,node_main_window,node_global_config toneBlue
class node_model_registry,node_model_loaders,node_llama_engine,node_backend,node_streamer,node_errors toneAmber
class node_pipeline_builder,node_pipeline_executor,node_labs_endpoints toneMint
class node_api_server,node_device_discovery,node_integration_endpoint,node_external_providers toneRose
class node_phonolab_app,node_phonolab_manager,node_phonolab_api,node_jni_runner toneIndigo
```

## Components

### Desktop Front Ends

- [Desktop entry points](https://github.com/7zonesystems/nativelab/blob/main/nativelab/__main__.py): Python launchers · GUI and CLI startup paths. · `nativelab/__main__.py`
- [PyQt main window](https://github.com/7zonesystems/nativelab/blob/main/nativelab/UI/mainwindow/window.py): desktop shell · Composes primary workbench panels and workers. · `nativelab/UI/mainwindow/window.py`
- [Shared app state](https://github.com/7zonesystems/nativelab/blob/main/nativelab/GlobalConfig/config_global.py): configuration runtime · Global settings, hardware detection, binaries, and timeouts. · `nativelab/GlobalConfig/config_global.py`

### Model Runtime

- [Model registry](https://github.com/7zonesystems/nativelab/blob/main/nativelab/Model/ModelRegistry.py): model metadata · Selects model families and prompt templates. · `nativelab/Model/ModelRegistry.py`
- [Model loaders](https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/model_loaders.py): engine routing · Loads local, Ollama, Transformers, and remote models. · `nativelab/core/model_loaders.py`
- [llama.cpp engine](https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/engines/llamaengine.py): local inference engine · `nativelab/core/engines/llamaengine.py`
- [Backend abstraction](https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/backend.py): inference dispatcher · Routes requests across local, API, and server backends. · `nativelab/core/backend.py`
- [Streaming worker](https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/streamerworker/backendstreamer.py): incremental output · Returns generated tokens to each consumer. · `nativelab/core/streamerworker/backendstreamer.py`
- [Runtime errors](https://github.com/7zonesystems/nativelab/blob/main/nativelab/core/llm_errors.py): error state · Centralized inference status and errors. · `nativelab/core/llm_errors.py`

### Workflows

- [Pipeline builder](https://github.com/7zonesystems/nativelab/blob/main/nativelab/pipelinebuilder/pipebuilder.py): visual workflow editor · Edits and validates multi-model graphs. · `nativelab/pipelinebuilder/pipebuilder.py`
- [Pipeline execution core](https://github.com/7zonesystems/nativelab/blob/main/nativelab/pipelinebuilder/execution_core.py): workflow executor · Executes validated pipeline nodes in workers. · `nativelab/pipelinebuilder/execution_core.py`
- [Labs endpoints](https://github.com/7zonesystems/nativelab/blob/main/nativelab/labs/endpoints.py): extension boundary · Provides endpoint access without engine ownership. · `nativelab/labs/endpoints.py`

### Service Boundaries

- [Local API server](https://github.com/7zonesystems/nativelab/blob/main/nativelab/api_server/server.py): HTTP serving · Hosts local model APIs and integration endpoints. · `nativelab/api_server/server.py`
- [LAN device discovery](https://github.com/7zonesystems/nativelab/blob/main/nativelab/api_server/device_discovery.py): PhonoLab discovery · `nativelab/api_server/device_discovery.py`
- [Integration HTTP endpoint](https://github.com/7zonesystems/nativelab/blob/main/nativelab/integrations/http_endpoint.py): external integration · Connects HTTP-facing integrations to inference. · `nativelab/integrations/http_endpoint.py`
- **External providers**: model and integration services · Ollama, Hugging Face, OpenAI-compatible, Anthropic, MCP, messaging, and search.

### PhonoLab Android

- [PhonoLab app](https://github.com/7zonesystems/nativelab/blob/main/PhonoLab/android/app/src/main/java/org/nativelab/phonolab/MainActivity.kt): Android local client · Owns on-device chat, sessions, models, downloads, and RAG. · `PhonoLab/android/app/src/main/java/org/nativelab/phonolab/MainActivity.kt`
- [llama.cpp lifecycle](https://github.com/7zonesystems/nativelab/blob/main/PhonoLab/android/app/src/main/java/org/nativelab/phonolab/LlamaCppManager.kt): Android runtime manager · Kotlin controls the native model runtime. · `PhonoLab/android/app/src/main/java/org/nativelab/phonolab/LlamaCppManager.kt`
- [PhonoLab LAN API](https://github.com/7zonesystems/nativelab/blob/main/PhonoLab/android/app/src/main/java/org/nativelab/phonolab/api/PhonoLabApiServer.kt): Android API server · Exposes device inference over the local network. · `PhonoLab/android/app/src/main/java/org/nativelab/phonolab/api/PhonoLabApiServer.kt`
- [JNI native runner](https://github.com/7zonesystems/nativelab/blob/main/PhonoLab/android/app/src/main/cpp/runner.cpp): C++ bridge · Bridges Android Kotlin runtime to packaged native execution. · `PhonoLab/android/app/src/main/cpp/runner.cpp`

## Connections

- Desktop entry points → PyQt main window: launches GUI
- PyQt main window → Shared app state: uses
- PyQt main window → Backend abstraction: submits inference
- Shared app state → Model loaders: supplies runtime settings
- Model registry → Model loaders: selects model family
- Model loaders → llama.cpp engine: loads GGUF
- Model loaders → External providers: uses remote and optional runtimes
- Backend abstraction → llama.cpp engine: dispatches local requests
- Backend abstraction → External providers: dispatches API requests
- Backend abstraction → Streaming worker: streams responses
- Backend abstraction → Runtime errors: reports status
- Pipeline builder → Pipeline execution core: validates and runs graph
- Pipeline execution core → Backend abstraction: executes inference nodes
- Labs endpoints → Backend abstraction: consumes endpoint access
- Local API server → Backend abstraction: serves inference
- Integration HTTP endpoint → Local API server: connects integrations
- LAN device discovery → PhonoLab LAN API: discovers on LAN
- PhonoLab app → llama.cpp lifecycle: controls runtime
- llama.cpp lifecycle → JNI native runner: invokes native execution
- PhonoLab LAN API → llama.cpp lifecycle: serves on-device inference
- Local API server → PhonoLab LAN API: routes registered device requests
