Developer Documentation

Architecture and internals.

How NativeLab is built, how to contribute, and how the pieces fit together.

Architecture

Layered design.

NativeLab is a layered application. Each layer talks only to the one beneath it, keeping GUI, CLI, and Labs frontends interchangeable.

┌─────────────────────────────────────────────────────────┐ Frontends MainWindow (PyQt6) | CLI ChatREPL | Lab Panels ├─────────────────────────────────────────────────────────┤ LabEndpoints - shared single surface call_llm() | request_load_model() | ensure_server() ├─────────────────────────────────────────────────────────┤ Centralized Backend (core/backend.py) NativeLabBackend | NativeLabHttpClient ├─────────────────────────────────────────────────────────┤ Engine Layer LlamaEngine (server/cli/ollama/hf) | ApiEngine ├─────────────────────────────────────────────────────────┤ Persistence Session | ModelRegistry | ApiRegistry | AppConfig └─────────────────────────────────────────────────────────┘

Reference

Key files and modules.

Where things live and what they do.

Core Modules

  • core/backend.py - unified facade
  • core/http_client.py - HTTP client
  • core/engine_status.py - engine state
  • core/llm_errors.py - error handling
  • Model/APImodels.py - API registry
  • Model/ModelRegistry.py - model registry

Backend

Centralized API layer.

All network operations go through NativeLabHttpClient. All backend operations go through NativeLabBackend. No raw urllib calls in new code.

NativeLabBackend

from nativelab.core.backend import get_backend backend = get_backend() # Model operations result = backend.load_model("/path/to/model.gguf") result = backend.generate(messages=[...]) # Device operations devices = backend.scan_network() result = backend.register_device_as_model(device)

NativeLabHttpClient

from nativelab.core.http_client import get_http_client http = get_http_client() # Basic requests resp = http.get("http://localhost:8080/health") resp = http.post("http://...", body={...}) # Streaming text = http.post_openai_stream( url="http://...", messages=[...], on_token=lambda t: print(t), )

Android

PhonoLab developer docs.

Architecture, file index, constants, and contributing guide for the Android client.

Architecture

17-layer error handling, singleton pattern, lifecycle protection.

File Index

Every file - purpose, classes, functions, constants.

Constants

All limits, defaults, colors, URLs, regex patterns.

API Endpoints

Complete reference for LAN API server.

Server

Standalone local server.

Turn any GGUF model into an OpenAI-compatible API server with one command.

$ python -m nativelab.server --model models/llama-7b.gguf
# Hardware: 8 cores, 8192 MB RAM
# Recommended: threads=4, ctx=2048, n_predict=512
# Server running on 127.0.0.1:8787
# Endpoints:
#   /v1/chat/completions  (OpenAI)
#   /v1/messages          (Anthropic)
#   /health               (status)

Features

  • Interactive model picker
  • Hardware-aware auto-config
  • OpenAI + Anthropic compatible
  • API key authentication
  • Graceful shutdown on Ctrl+C
  • No dependencies beyond nativelab