# letsgettoworkbro/dreamlayer architecture

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

- Interactive diagram: https://gitdiagram.com/letsgettoworkbro/dreamlayer
- Repository: https://github.com/letsgettoworkbro/dreamlayer

## Overview

#### Purpose and runtime topology
DreamLayer is a privacy-first ambient-memory stack for Halo smart glasses. It spans four primary runtimes: Lua on glasses, Python for the phone hub/Mac-or-Windows Brain, React Native on phone, and Rust for portable figment interpretation. The default processing path stays local; LAN Brain and cloud model use are optional.

#### Entry points and user surfaces
Primary executable paths are the Python package/CLI and Brain server: `host-python/src/dreamlayer/__main__.py`, `host-python/src/dreamlayer/main.py`, and `host-python/src/dreamlayer/ai_brain/server/__main__.py`. The simulator is separately runnable through `host-python/src/dreamlayer/simulator/__main__.py`. Mobile starts in Expo Router at `phone-app/app/_layout.tsx`; the on-glasses entry is `halo-lua/main.lua`. Browser-facing product surfaces are static `landing/index.html` and Vite `web/src/main.ts`.

#### Device, bridge, and HUD boundary
The glasses are a constrained display/sensor client: Lua maintains session/state, BLE protocol, capture hooks, and card rendering. Python bridges either real hardware, emulator, or Lua raster execution, isolating device transport from product logic.
- `halo-lua/app/state_machine.lua`
- `halo-lua/ble/protocol.lua`
- `halo-lua/display/renderer.lua`
- `host-python/src/dreamlayer/bridge/real_bridge.py`
- `host-python/src/dreamlayer/bridge/emulator_bridge.py`

#### Orchestration, perception, and response loop
The orchestrator coordinates capture, attention, voice, commands, confidence, budgets, provenance, and output cards. Pipelines provide camera/audio ingestion, speech, vision, and LLM adaptation. Inputs are veil-gated, interpreted into lens actions or queries, enriched with recall/context, then emitted to HUD/phone/Brain surfaces.
- `host-python/src/dreamlayer/orchestrator/orchestrator.py`
- `host-python/src/dreamlayer/orchestrator/capture.py`
- `host-python/src/dreamlayer/orchestrator/voice.py`
- `host-python/src/dreamlayer/pipelines/ingest.py`
- `host-python/src/dreamlayer/pipelines/vision.py`

#### Local memory and privacy spine
Memory persists structured, recallable meaning rather than raw recordings. The subsystem combines relational storage, embeddings/vector backends, retrieval, retention, PII handling, and proactive recall. Privacy/provenance controls are cross-cutting boundaries for capture, egress, plugins, and erase flows.
- `host-python/src/dreamlayer/memory/db.py`
- `host-python/src/dreamlayer/memory/vector_store.py`
- `host-python/src/dreamlayer/memory/retrieval.py`
- `host-python/src/dreamlayer/memory/privacy.py`
- `host-python/src/dreamlayer/orchestrator/provenance.py`

#### Brain service and intelligence tiers
The AI Brain is a local control-panel/API service with selectable local, LAN, and opt-in cloud backends. It integrates indexed desktop sources and model providers while server code owns authentication, TLS, state, and live endpoints. Cloud is an external boundary; model providers include local MLX/Gemma/Ollama-style routes and LiteLLM-backed remote providers.
- `host-python/src/dreamlayer/ai_brain/server/server.py`
- `host-python/src/dreamlayer/ai_brain/server_fastapi.py`
- `host-python/src/dreamlayer/ai_brain/router.py`
- `host-python/src/dreamlayer/ai_brain/cloud.py`
- `host-python/src/dreamlayer/ai_brain/perception.py`

#### Extensibility: plugins and Reality Compiler
Third-party Python plugins pass validation, signing/trust, egress controls, and isolation through subprocess/OS/WASM hosts. Separately, the Reality Compiler converts intent into signed declarative “figments,” constrained by capabilities and safety contracts, then deploys them to fixed interpreters. Interpreter parity spans Python, Lua, browser JS, and Rust/WASM.
- `host-python/src/dreamlayer/plugins/isolation.py`
- `host-python/src/dreamlayer/plugins/wasm_component_host.py`
- `host-python/src/dreamlayer/reality_compiler/v2/compiler.py`
- `host-python/src/dreamlayer/reality_compiler/v2/safety.py`
- `reality-core/src/lib.rs`

#### Distribution, coordination, and external infrastructure
The phone app is the pairing/control hub, using BLE and local state stores to control glasses and Brain. The plugin registry is git-backed metadata; a Cloudflare Worker provides catalog search, ratings, and Figment Golf-like community APIs without shipping code. Releases build macOS and Windows desktop packages; phone builds target iOS/Android.
- `phone-app/src/ble/bridge.ts`
- `phone-app/src/services/pairing.ts`
- `phone-app/src/state/useConnectionStore.ts`
- `registry-api/worker.js`
- `host-python/packaging/setup_app.py`

Main entry points: [`host-python/src/dreamlayer/orchestrator/orchestrator.py`](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/orchestrator/orchestrator.py) (Orchestrator), [`host-python/src/dreamlayer/pipelines/ingest.py`](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/pipelines/ingest.py) (Capture ingestion), [`host-python/src/dreamlayer/memory/retrieval.py`](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/memory/retrieval.py) (Recall retrieval), [`halo-lua/main.lua`](https://github.com/letsgettoworkbro/dreamlayer/blob/main/halo-lua/main.lua) (Halo Lua app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_glasses["Glasses Runtime"]
  node_glasses_app{{"Halo Lua app<br/>device runtime<br/>[main.lua]"}}
  node_glasses_state["Session state machine<br/>Lua state<br/>[state_machine.lua]"]
  node_ble_protocol["BLE protocol<br/>device protocol<br/>[protocol.lua]"]
  node_hud_renderer["HUD renderer<br/>Lua renderer<br/>[renderer.lua]"]
end

subgraph group_host["Host Runtime"]
  node_host_entry{{"Host CLI<br/>Python entrypoint<br/>[main.py]"}}
  node_device_bridge["Device bridge<br/>Python transport<br/>[real_bridge.py]"]
  node_orchestrator["Orchestrator<br/>Python coordinator<br/>[orchestrator.py]"]
  node_ingestion["Capture ingestion<br/>perception pipeline<br/>[ingest.py]"]
  node_vision["Vision pipeline<br/>perception pipeline<br/>[vision.py]"]
end

subgraph group_memory["Memory &amp; Privacy"]
  node_memory_db[("Memory store<br/>relational storage<br/>[db.py]")]
  node_vector_store[("Vector store<br/>embedding storage<br/>[vector_store.py]")]
  node_retrieval["Recall retrieval<br/>memory service<br/>[retrieval.py]"]
  node_privacy["Privacy &amp; provenance<br/>policy boundary<br/>[privacy.py]"]
end

subgraph group_brain["AI Brain"]
  node_brain_server["Brain API server<br/>local service<br/>[server.py]"]
  node_brain_router["Model router<br/>intelligence router<br/>[router.py]"]
  node_cloud_models["Cloud model providers<br/>external service"]
end

subgraph group_extensions["Figments &amp; Plugins"]
  node_plugin_isolation["Plugin isolation<br/>extension host<br/>[isolation.py]"]
  node_reality_compiler["Reality Compiler<br/>figment compiler<br/>[compiler.py]"]
  node_figment_safety["Figment safety<br/>safety policy<br/>[safety.py]"]
  node_reality_core{{"Portable figment runtime<br/>Rust/WASM interpreter<br/>[lib.rs]"}}
end

subgraph group_clients["Phone &amp; Web"]
  node_phone_app["Phone pairing hub<br/>React Native app<br/>[_layout.tsx]"]
  node_registry_api["Plugin registry API<br/>Cloudflare Worker<br/>[worker.js]"]
end

node_glasses_app -->|"maintains session"| node_glasses_state
node_glasses_app -->|"communicates over"| node_ble_protocol
node_glasses_state -->|"drives cards"| node_hud_renderer
node_ble_protocol -->|"BLE transport"| node_device_bridge
node_host_entry -->|"starts"| node_orchestrator
node_device_bridge -->|"device events"| node_orchestrator
node_orchestrator -->|"requests capture"| node_ingestion
node_ingestion -->|"image inputs"| node_vision
node_ingestion -->|"veil-gated by"| node_privacy
node_vision -->|"perception results"| node_orchestrator
node_orchestrator -->|"recalls context"| node_retrieval
node_retrieval -->|"reads meaning"| node_memory_db
node_retrieval -->|"semantic search"| node_vector_store
node_orchestrator -->|"persists events"| node_memory_db
node_privacy -->|"retention policy"| node_memory_db
node_orchestrator -->|"queries intelligence"| node_brain_server
node_brain_server -->|"routes requests"| node_brain_router
node_brain_router -.->|"opt-in egress"| node_cloud_models
node_orchestrator -->|"HUD output"| node_device_bridge
node_phone_app -->|"pairs and controls"| node_ble_protocol
node_phone_app -->|"local control"| node_brain_server
node_orchestrator -->|"runs extensions"| node_plugin_isolation
node_plugin_isolation -->|"egress controls"| node_privacy
node_reality_compiler -->|"checks contracts"| node_figment_safety
node_figment_safety -->|"deploys approved figments"| node_reality_core
node_reality_core -.->|"portable interpretation"| node_glasses_app
node_registry_api -.->|"catalog metadata"| node_plugin_isolation

click node_glasses_app "https://github.com/letsgettoworkbro/dreamlayer/blob/main/halo-lua/main.lua"
click node_glasses_state "https://github.com/letsgettoworkbro/dreamlayer/blob/main/halo-lua/app/state_machine.lua"
click node_ble_protocol "https://github.com/letsgettoworkbro/dreamlayer/blob/main/halo-lua/ble/protocol.lua"
click node_hud_renderer "https://github.com/letsgettoworkbro/dreamlayer/blob/main/halo-lua/display/renderer.lua"
click node_host_entry "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/main.py"
click node_device_bridge "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/bridge/real_bridge.py"
click node_orchestrator "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/orchestrator/orchestrator.py"
click node_ingestion "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/pipelines/ingest.py"
click node_vision "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/pipelines/vision.py"
click node_memory_db "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/memory/db.py"
click node_vector_store "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/memory/vector_store.py"
click node_retrieval "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/memory/retrieval.py"
click node_privacy "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/memory/privacy.py"
click node_brain_server "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/ai_brain/server/server.py"
click node_brain_router "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/ai_brain/router.py"
click node_plugin_isolation "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/plugins/isolation.py"
click node_reality_compiler "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/reality_compiler/v2/compiler.py"
click node_figment_safety "https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/reality_compiler/v2/safety.py"
click node_reality_core "https://github.com/letsgettoworkbro/dreamlayer/blob/main/reality-core/src/lib.rs"
click node_phone_app "https://github.com/letsgettoworkbro/dreamlayer/blob/main/phone-app/app/_layout.tsx"
click node_registry_api "https://github.com/letsgettoworkbro/dreamlayer/blob/main/registry-api/worker.js"

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_glasses_app,node_glasses_state,node_ble_protocol,node_hud_renderer toneBlue
class node_host_entry,node_device_bridge,node_orchestrator,node_ingestion,node_vision toneAmber
class node_memory_db,node_vector_store,node_retrieval,node_privacy toneMint
class node_brain_server,node_brain_router,node_cloud_models toneRose
class node_plugin_isolation,node_reality_compiler,node_figment_safety,node_reality_core toneIndigo
class node_phone_app,node_registry_api toneTeal
```

## Components

### Glasses Runtime

Lua device client and HUD.

- [Halo Lua app](https://github.com/letsgettoworkbro/dreamlayer/blob/main/halo-lua/main.lua): device runtime · Runs the glasses session, capture hooks, and HUD. · `halo-lua/main.lua`
- [Session state machine](https://github.com/letsgettoworkbro/dreamlayer/blob/main/halo-lua/app/state_machine.lua): Lua state · `halo-lua/app/state_machine.lua`
- [BLE protocol](https://github.com/letsgettoworkbro/dreamlayer/blob/main/halo-lua/ble/protocol.lua): device protocol · `halo-lua/ble/protocol.lua`
- [HUD renderer](https://github.com/letsgettoworkbro/dreamlayer/blob/main/halo-lua/display/renderer.lua): Lua renderer · `halo-lua/display/renderer.lua`

### Host Runtime

Python hub, orchestration, and perception.

- [Host CLI](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/main.py): Python entrypoint · Starts the local hub runtime. · `host-python/src/dreamlayer/main.py`
- [Device bridge](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/bridge/real_bridge.py): Python transport · Isolates real hardware and emulator transports. · `host-python/src/dreamlayer/bridge/real_bridge.py`
- [Orchestrator](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/orchestrator/orchestrator.py): Python coordinator · Coordinates capture, attention, budgets, actions, and output cards. · `host-python/src/dreamlayer/orchestrator/orchestrator.py`
- [Capture ingestion](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/pipelines/ingest.py): perception pipeline · Ingests camera and audio inputs. · `host-python/src/dreamlayer/pipelines/ingest.py`
- [Vision pipeline](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/pipelines/vision.py): perception pipeline · `host-python/src/dreamlayer/pipelines/vision.py`

### Memory & Privacy

Local durable meaning and policy controls.

- [Memory store](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/memory/db.py): relational storage · Persists structured recallable meaning rather than raw recordings. · `host-python/src/dreamlayer/memory/db.py`
- [Vector store](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/memory/vector_store.py): embedding storage · `host-python/src/dreamlayer/memory/vector_store.py`
- [Recall retrieval](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/memory/retrieval.py): memory service · Enriches actions and queries with local context. · `host-python/src/dreamlayer/memory/retrieval.py`
- [Privacy & provenance](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/memory/privacy.py): policy boundary · Gates capture, egress, retention, and erase flows. · `host-python/src/dreamlayer/memory/privacy.py`

### AI Brain

Local API and selectable intelligence backends.

- [Brain API server](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/ai_brain/server/server.py): local service · Control panel and authenticated live API. · `host-python/src/dreamlayer/ai_brain/server/server.py`
- [Model router](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/ai_brain/router.py): intelligence router · Selects local, LAN, or opt-in cloud providers. · `host-python/src/dreamlayer/ai_brain/router.py`
- **Cloud model providers**: external service · Optional remote models via LiteLLM-backed providers.

### Figments & Plugins

Safe extensibility across interpreters.

- [Plugin isolation](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/plugins/isolation.py): extension host · Validates and isolates third-party plugin execution. · `host-python/src/dreamlayer/plugins/isolation.py`
- [Reality Compiler](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/reality_compiler/v2/compiler.py): figment compiler · Compiles intent into signed declarative figments. · `host-python/src/dreamlayer/reality_compiler/v2/compiler.py`
- [Figment safety](https://github.com/letsgettoworkbro/dreamlayer/blob/main/host-python/src/dreamlayer/reality_compiler/v2/safety.py): safety policy · Enforces capabilities and safety contracts. · `host-python/src/dreamlayer/reality_compiler/v2/safety.py`
- [Portable figment runtime](https://github.com/letsgettoworkbro/dreamlayer/blob/main/reality-core/src/lib.rs): Rust/WASM interpreter · Provides portable interpreter parity. · `reality-core/src/lib.rs`

### Phone & Web

Pairing hub and browser-facing surfaces.

- [Phone pairing hub](https://github.com/letsgettoworkbro/dreamlayer/blob/main/phone-app/app/_layout.tsx): React Native app · Controls glasses and Brain through BLE and local state. · `phone-app/app/_layout.tsx`
- [Plugin registry API](https://github.com/letsgettoworkbro/dreamlayer/blob/main/registry-api/worker.js): Cloudflare Worker · Serves catalog, ratings, and community APIs without shipping code. · `registry-api/worker.js`

## Connections

- Halo Lua app → Session state machine: maintains session
- Halo Lua app → BLE protocol: communicates over
- Session state machine → HUD renderer: drives cards
- BLE protocol → Device bridge: BLE transport
- Host CLI → Orchestrator: starts
- Device bridge → Orchestrator: device events
- Orchestrator → Capture ingestion: requests capture
- Capture ingestion → Vision pipeline: image inputs
- Capture ingestion → Privacy & provenance: veil-gated by
- Vision pipeline → Orchestrator: perception results
- Orchestrator → Recall retrieval: recalls context
- Recall retrieval → Memory store: reads meaning
- Recall retrieval → Vector store: semantic search
- Orchestrator → Memory store: persists events
- Privacy & provenance → Memory store: retention policy
- Orchestrator → Brain API server: queries intelligence
- Brain API server → Model router: routes requests
- Model router → Cloud model providers: opt-in egress
- Orchestrator → Device bridge: HUD output
- Phone pairing hub → BLE protocol: pairs and controls
- Phone pairing hub → Brain API server: local control
- Orchestrator → Plugin isolation: runs extensions
- Plugin isolation → Privacy & provenance: egress controls
- Reality Compiler → Figment safety: checks contracts
- Figment safety → Portable figment runtime: deploys approved figments
- Portable figment runtime → Halo Lua app: portable interpretation
- Plugin registry API → Plugin isolation: catalog metadata
