How 7zonesystems/nativelab works
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: backend.py Backend abstraction · model_loaders.py Model loaders · window.py PyQt main window · server.py Local API server
Components 20
Desktop Front Ends
- Desktop entry points · GUI and CLI startup paths.
nativelab/__main__.py - PyQt main window · Composes primary workbench panels and workers.
nativelab/UI/mainwindow/window.py - Shared app state · Global settings, hardware detection, binaries, and timeouts.
nativelab/GlobalConfig/config_global.py
Model Runtime
- Model registry · Selects model families and prompt templates.
nativelab/Model/ModelRegistry.py - Model loaders · Loads local, Ollama, Transformers, and remote models.
nativelab/core/model_loaders.py - llama.cpp engine
nativelab/core/engines/llamaengine.py - Backend abstraction · Routes requests across local, API, and server backends.
nativelab/core/backend.py - Streaming worker · Returns generated tokens to each consumer.
nativelab/core/streamerworker/backendstreamer.py - Runtime errors · Centralized inference status and errors.
nativelab/core/llm_errors.py
Workflows
- Pipeline builder · Edits and validates multi-model graphs.
nativelab/pipelinebuilder/pipebuilder.py - Pipeline execution core · Executes validated pipeline nodes in workers.
nativelab/pipelinebuilder/execution_core.py - Labs endpoints · Provides endpoint access without engine ownership.
nativelab/labs/endpoints.py
Service Boundaries
- Local API server · Hosts local model APIs and integration endpoints.
nativelab/api_server/server.py - LAN device discovery
nativelab/api_server/device_discovery.py - Integration HTTP endpoint · Connects HTTP-facing integrations to inference.
nativelab/integrations/http_endpoint.py - External providers · Ollama, Hugging Face, OpenAI-compatible, Anthropic, MCP, messaging, and search.
PhonoLab Android
- PhonoLab app · Owns on-device chat, sessions, models, downloads, and RAG.
PhonoLab/android/app/src/main/java/org/nativelab/phonolab/MainActivity.kt - llama.cpp lifecycle · Kotlin controls the native model runtime.
PhonoLab/android/app/src/main/java/org/nativelab/phonolab/LlamaCppManager.kt - PhonoLab LAN API · Exposes device inference over the local network.
PhonoLab/android/app/src/main/java/org/nativelab/phonolab/api/PhonoLabApiServer.kt - JNI native runner · Bridges Android Kotlin runtime to packaged native execution.
PhonoLab/android/app/src/main/cpp/runner.cpp
Connections 21
- 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