# jundot/omlx architecture

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

- Interactive diagram: https://gitdiagram.com/jundot/omlx
- Repository: https://github.com/jundot/omlx

## Overview

1. **Two deployment surfaces, one inference core**
   oMLX ships as both a CLI/server product and a native macOS menu-bar app. The inference runtime is the Python package under `omlx/`; the macOS app lives under `packaging/omlx_app/` and is mainly a control plane around the same server process.

2. **Primary external entry points**
   The server exposes OpenAI-compatible APIs under `/v1`, Anthropic-compatible messages under `/v1/messages`, embeddings/rerank/audio routes, and an admin surface under `/admin`. The admin UI also provides chat, model management, benchmarking, downloads, and settings.

3. **Request routing and protocol adaptation**
   API-facing code in `omlx/api/` translates external request shapes into internal model requests. The `openai` and `anthropic` adapters, plus SSE formatting and tool/thinking/structured-output helpers, are the boundary between client protocols and the engine layer.

4. **Model discovery and configuration**
   `model_discovery.py`, `model_registry.py`, and `model_settings.py` determine what is available from the configured model directory, classify models by type, and apply per-model overrides. Settings are persisted to `~/.omlx/settings.json`, while CLI flags and admin changes feed into the same config path.

5. **Multi-model engine orchestration**
   `engine_pool.py` is the central runtime coordinator. It manages loaded models across LLM, VLM, embedding, reranker, and audio engines, handling load/unload, pinning, TTL-based eviction, and LRU pressure relief. This is the main boundary between “which model should answer” and “how inference is executed.”

6. **Inference execution layer**
   The concrete execution code sits in `omlx/engine/` and `omlx/models/`. `BatchedEngine` handles continuous batching for text LLMs, while specialized engines cover VLM, embeddings, reranking, STT/TTS/STS, and audio utilities. Model wrappers in `omlx/models/` encapsulate model-specific behavior and input/output shapes.

7. **Scheduler and process-level resource control**
   `scheduler.py` controls concurrent request admission and batch execution. `process_memory_enforcer.py`, `memory_monitor.py`, and `server_metrics.py` form the runtime guardrails that keep the process below memory limits and expose health/usage signals for the admin dashboard and menu-bar app.

8. **Tiered KV cache is a major subsystem**
   The cache stack under `omlx/cache/` is a core architectural feature. It includes a hot in-memory tier, a cold SSD tier (`paged_ssd_cache.py`), prefix sharing, copy-on-write, recovery, and type-specific handlers. Cache state can survive restarts and be restored from disk, making cache behavior a first-class part of the serving path rather than a transient optimization.

9. **VLM and vision-specific paths**
   Vision support is not bolted on; it has its own engine, adapter, and cache support. Image handling utilities, VLM model adapters, and vision-feature cache components allow multi-image inputs, OCR-style prompting, and tool calling with visual context.

10. **Tool calling, structured output, and model-specific parsing**
   `omlx/adapter/` and parts of `omlx/api/` handle model-family-specific output parsing and tool-call formatting. This includes adapters for formats such as Gemma and Harmony, plus shared parsing logic that converts raw generation into structured tool calls or validated JSON-like outputs.

11. **Admin dashboard as an operational plane**
   `omlx/admin/` contains the server-side routes, auth, downloader/uploader, benchmark tools, model-status views, and localized templates/static assets for the dashboard. It is a separate operational interface for downloads, benchmarking, chat, model tuning, and runtime monitoring, not just a UI skin over the API.

12. **Integrations and MCP**
   `omlx/integrations/` provides setup hooks for external coding agents such as OpenCode, OpenClaw, and Codex. `omlx/mcp/` adds Model Context Protocol client/manager/executor tooling so the server can expose or consume tools beyond plain chat completion.

13. **Packaging and update management**
   The `packaging/` tree wraps the server in a native app experience with server lifecycle management, preferences, welcome flow, and updater logic. The Homebrew formula and GitHub workflow support distribution and automated formula refresh, but they do not change the runtime architecture of inference itself.

14. **Evaluation and benchmarking are first-class**
   `omlx/eval/` holds benchmark datasets and scoring logic, while admin benchmarking and accuracy tools reuse similar concepts for live model evaluation. This makes performance and quality measurement part of the repository’s architecture, not a separate tooling repo.

Main entry points: [`omlx/admin/routes.py`](https://github.com/jundot/omlx/blob/main/omlx/admin/routes.py) (Admin API), [`omlx/server.py`](https://github.com/jundot/omlx/blob/main/omlx/server.py) (Server), [`omlx/engine_pool.py`](https://github.com/jundot/omlx/blob/main/omlx/engine_pool.py) (Engine pool), [`omlx/api/__init__.py`](https://github.com/jundot/omlx/blob/main/omlx/api/__init__.py) (API routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime core"]
  node_server["Server<br/>http app<br/>[server.py]"]
  node_api_routes["API routes<br/>http routes<br/>[__init__.py]"]
  node_api_adapters["API adapters<br/>protocol layer<br/>[openai.py]"]
  node_engine_pool{{"Engine pool<br/>orchestrator<br/>[engine_pool.py]"}}
  node_scheduler["Scheduler<br/>admission control<br/>[scheduler.py]"]
  node_batched_engine["Batched engine<br/>llm executor<br/>[batched.py]"]
  node_specialized_engines["Specialized engines<br/>execution layer<br/>[embedding.py]"]
  node_model_wrappers["Model wrappers<br/>model layer<br/>[base_model.py]"]
  node_guardrails["Guardrails<br/>runtime safety"]
end

subgraph group_control["Control surfaces"]
  node_cli["CLI/server<br/>entrypoint<br/>[cli.py]"]
  node_admin_routes["Admin API<br/>dashboard backend<br/>[routes.py]"]
  node_admin_ui["Dashboard UI<br/>web UI<br/>[dashboard.html]"]
  node_app["Mac app<br/>native wrapper<br/>[app.py]"]
  node_server_manager["Server manager<br/>app lifecycle<br/>[server_manager.py]"]
end

subgraph group_support["Supporting subsystems"]
  node_model_mgmt["Model mgmt<br/>discovery/config<br/>[model_registry.py]"]
  node_cache[("KV cache<br/>tiered cache<br/>[hybrid_cache.py]")]
  node_eval["Evaluation<br/>benchmarks<br/>[base.py]"]
  node_integrations["Integrations<br/>agent setup<br/>[base.py]"]
  node_mcp["MCP<br/>tooling<br/>[manager.py]"]
  node_utils["Utilities<br/>shared helpers<br/>[model_loading.py]"]
end

node_cli -->|"starts"| node_server
node_app -->|"controls"| node_server_manager
node_server_manager -->|"runs"| node_server
node_server -->|"exposes"| node_api_routes
node_server -->|"exposes"| node_admin_routes
node_admin_routes -->|"renders"| node_admin_ui
node_api_routes -->|"adapts"| node_api_adapters
node_api_adapters -->|"dispatches"| node_engine_pool
node_engine_pool -->|"coordinates"| node_scheduler
node_scheduler -->|"runs"| node_batched_engine
node_scheduler -->|"runs"| node_specialized_engines
node_batched_engine -->|"wraps"| node_model_wrappers
node_specialized_engines -->|"wraps"| node_model_wrappers
node_engine_pool -->|"selects"| node_model_mgmt
node_model_mgmt -->|"uses"| node_utils
node_engine_pool -->|"uses"| node_cache
node_server -->|"monitors"| node_guardrails
node_admin_routes -->|"reports"| node_guardrails
node_admin_routes -->|"edits"| node_model_mgmt
node_admin_routes -->|"benchmarks"| node_eval
node_api_routes -->|"integrates"| node_mcp
node_integrations -->|"extends"| node_mcp
node_app -->|"opens"| node_admin_routes

click node_cli "https://github.com/jundot/omlx/blob/main/omlx/cli.py"
click node_server "https://github.com/jundot/omlx/blob/main/omlx/server.py"
click node_admin_routes "https://github.com/jundot/omlx/blob/main/omlx/admin/routes.py"
click node_admin_ui "https://github.com/jundot/omlx/blob/main/omlx/admin/templates/dashboard.html"
click node_app "https://github.com/jundot/omlx/blob/main/packaging/omlx_app/app.py"
click node_server_manager "https://github.com/jundot/omlx/blob/main/packaging/omlx_app/server_manager.py"
click node_api_routes "https://github.com/jundot/omlx/blob/main/omlx/api/__init__.py"
click node_api_adapters "https://github.com/jundot/omlx/blob/main/omlx/api/adapters/openai.py"
click node_engine_pool "https://github.com/jundot/omlx/blob/main/omlx/engine_pool.py"
click node_scheduler "https://github.com/jundot/omlx/blob/main/omlx/scheduler.py"
click node_batched_engine "https://github.com/jundot/omlx/blob/main/omlx/engine/batched.py"
click node_specialized_engines "https://github.com/jundot/omlx/blob/main/omlx/engine/embedding.py"
click node_model_wrappers "https://github.com/jundot/omlx/blob/main/omlx/models/base_model.py"
click node_model_mgmt "https://github.com/jundot/omlx/blob/main/omlx/model_registry.py"
click node_cache "https://github.com/jundot/omlx/blob/main/omlx/cache/hybrid_cache.py"
click node_guardrails "https://github.com/jundot/omlx/blob/main/omlx/process_memory_enforcer.py"
click node_eval "https://github.com/jundot/omlx/blob/main/omlx/eval/base.py"
click node_integrations "https://github.com/jundot/omlx/blob/main/omlx/integrations/base.py"
click node_mcp "https://github.com/jundot/omlx/blob/main/omlx/mcp/manager.py"
click node_utils "https://github.com/jundot/omlx/blob/main/omlx/utils/model_loading.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_server,node_api_routes,node_api_adapters,node_engine_pool,node_scheduler,node_batched_engine,node_specialized_engines,node_model_wrappers,node_guardrails toneBlue
class node_cli,node_admin_routes,node_admin_ui,node_app,node_server_manager toneAmber
class node_model_mgmt,node_cache,node_eval,node_integrations,node_mcp,node_utils toneMint
```

## Components

### Runtime core

Server-side inference and serving path.

- [Server](https://github.com/jundot/omlx/blob/main/omlx/server.py): http app · Main serving process and route assembly. · `omlx/server.py`
- [API routes](https://github.com/jundot/omlx/blob/main/omlx/api/__init__.py): http routes · OpenAI-compatible, Anthropic-compatible, audio, embedding, rerank, MCP, and responses endpoints. · `omlx/api/__init__.py`
- [API adapters](https://github.com/jundot/omlx/blob/main/omlx/api/adapters/openai.py): protocol layer · OpenAI and Anthropic request adaptation plus SSE and tool/output helpers. · `omlx/api/adapters/openai.py`
- [Engine pool](https://github.com/jundot/omlx/blob/main/omlx/engine_pool.py): orchestrator · Coordinates loaded models, eviction, pinning, and engine selection. · `omlx/engine_pool.py`
- [Scheduler](https://github.com/jundot/omlx/blob/main/omlx/scheduler.py): admission control · Controls concurrent request admission and batch execution. · `omlx/scheduler.py`
- [Batched engine](https://github.com/jundot/omlx/blob/main/omlx/engine/batched.py): llm executor · Continuous batching runtime for text generation workloads. · `omlx/engine/batched.py`
- [Specialized engines](https://github.com/jundot/omlx/blob/main/omlx/engine/embedding.py): execution layer · Embedding, reranker, VLM, STT, TTS, and STS execution paths. · `omlx/engine/embedding.py`
- [Model wrappers](https://github.com/jundot/omlx/blob/main/omlx/models/base_model.py): model layer · Model-specific wrappers and input/output shaping. · `omlx/models/base_model.py`
- [Guardrails](https://github.com/jundot/omlx/blob/main/omlx/process_memory_enforcer.py): runtime safety · Memory monitoring, process enforcement, and server metrics. · `omlx/process_memory_enforcer.py`

### Control surfaces

CLI, admin dashboard, and macOS app controls.

- [CLI/server](https://github.com/jundot/omlx/blob/main/omlx/cli.py): entrypoint · Command-line entry and server startup. · `omlx/cli.py`
- [Admin API](https://github.com/jundot/omlx/blob/main/omlx/admin/routes.py): dashboard backend · Operational routes for chat, models, benchmark, settings, and downloads. · `omlx/admin/routes.py`
- [Dashboard UI](https://github.com/jundot/omlx/blob/main/omlx/admin/templates/dashboard.html): web UI · Templates, static assets, and localized admin interface. · `omlx/admin/templates/dashboard.html`
- [Mac app](https://github.com/jundot/omlx/blob/main/packaging/omlx_app/app.py): native wrapper · macOS menu-bar control plane around the server. · `packaging/omlx_app/app.py`
- [Server manager](https://github.com/jundot/omlx/blob/main/packaging/omlx_app/server_manager.py): app lifecycle · Starts, stops, and monitors the bundled server process. · `packaging/omlx_app/server_manager.py`

### Supporting subsystems

Model discovery, cache, evaluation, and integrations.

- [Model mgmt](https://github.com/jundot/omlx/blob/main/omlx/model_registry.py): discovery/config · Discovery, registry, and per-model settings persisted in the shared config path. · `omlx/model_registry.py`
- [KV cache](https://github.com/jundot/omlx/blob/main/omlx/cache/hybrid_cache.py): tiered cache · Hot/cold cache stack with recovery, prefix sharing, and vision feature caching. · `omlx/cache/hybrid_cache.py`
- [Evaluation](https://github.com/jundot/omlx/blob/main/omlx/eval/base.py): benchmarks · Benchmark datasets and scoring for model evaluation. · `omlx/eval/base.py`
- [Integrations](https://github.com/jundot/omlx/blob/main/omlx/integrations/base.py): agent setup · Hooks for external coding agents and related setup flows. · `omlx/integrations/base.py`
- [MCP](https://github.com/jundot/omlx/blob/main/omlx/mcp/manager.py): tooling · Model Context Protocol client, manager, executor, and tool types. · `omlx/mcp/manager.py`
- [Utilities](https://github.com/jundot/omlx/blob/main/omlx/utils/model_loading.py): shared helpers · Hardware, tokenizer, image, install, and model-loading helpers used across the stack. · `omlx/utils/model_loading.py`

## Connections

- CLI/server → Server: starts · CLI launches the server process.
- Mac app → Server manager: controls · Native app manages server lifecycle.
- Server manager → Server: runs · App wrapper starts and stops the shared server.
- Server → API routes: exposes · Server mounts public API surfaces.
- Server → Admin API: exposes · Server mounts operational dashboard routes.
- Admin API → Dashboard UI: renders · Dashboard backend serves templates and static assets.
- API routes → API adapters: adapts · Routes delegate protocol translation and response shaping.
- API adapters → Engine pool: dispatches · Protocol layer converts requests into engine calls.
- Engine pool → Scheduler: coordinates · Pool hands execution to the scheduler.
- Scheduler → Batched engine: runs · Scheduler executes work on the batched text engine.
- Scheduler → Specialized engines: runs · Scheduler executes work on specialized modality engines.
- Batched engine → Model wrappers: wraps · Text execution relies on model-specific wrappers.
- Specialized engines → Model wrappers: wraps · Specialized execution relies on model-specific wrappers.
- Engine pool → Model mgmt: selects · Pool uses discovery and settings to choose models.
- Model mgmt → Utilities: uses · Discovery and loading rely on shared helpers.
- Engine pool → KV cache: uses · Serving path relies on tiered KV and vision caches.
- Server → Guardrails: monitors · Server exposes health and resource controls.
- Admin API → Guardrails: reports · Dashboard reads metrics and memory state.
- Admin API → Model mgmt: edits · Admin changes feed back into shared model settings.
- Admin API → Evaluation: benchmarks · Dashboard runs model evaluation workflows.
- API routes → MCP: integrates · API surface includes MCP-related tooling.
- Integrations → MCP: extends · External agent setup hooks connect to MCP/tooling.
- Mac app → Admin API: opens · App presents the operational dashboard surface.
