{"slug": "build-a-100-local-family-medical-companion-on-mac-with-google-medgemma-2", "title": "Build a 100% Local Family Medical Companion on Mac with Google MedGemma 2", "summary": "A developer built KinDesk, a 100% local family medical companion for macOS that runs Google MedGemma 2 (medgemma2:26b-mlx-bf16 via local Ollama) entirely on-device, keeping per-member health vaults bound to 127.0.0.1 with 0700/0600 permissions and zero bytes sent to the cloud. The system ingests password-protected lab PDFs in memory with PyMuPDF, maps biomarkers to 88 verified LOINC codes, exports HL7 FHIR R4 bundles, and combines MedGemma 2 vision with 4 server-bound tools, a 0 ms negation-aware emergency guardrail, and a two-layer AST plus macOS Seatbelt sandbox (0 net · 0 FS). The write-up sizes the model for Apple Silicon at 12 GB for the E4B edge build, 24–32 GB for 26B Q4, or 64–128 GB for 26b-mlx-bf16, and presents chapters 2–7 as architecture guidance and skeletons of 40 lines or fewer rather than full production source.", "body_md": "## What You Will Build & Master\n\n- Size Google MedGemma 2 cleanly for Apple Silicon (12 GB E4B edge, 24–32 GB 26B Q4, or 64–128 GB 26b-mlx-bf16) bound strictly to 127.0.0.1 with 0700/0600 vault perms, .metadata_never_index Spotlight exclusion, and zero-packet scutil --nwi checks.\n- Ingest password-protected diagnostic lab PDFs strictly in memory with PyMuPDF, map biomarkers deterministically to 88 verified LOINC codes & unit conversions, detect cross-member mismatches, and export spec-valid HL7 FHIR R4 bundles.\n- Combine MedGemma 2 multimodal vision (<|think|> traces + EXIF/HEIC normalization) with 4 server-bound tools (never passing member_id to the LLM), a 0 ms negation-aware emergency guardrail, and a two-layer AST + macOS Seatbelt sandbox (0 net · 0 FS).\n- Wrap the adaptive dark/light React 19 UI (System Dark default + Light/Dark toggle, X-KinDesk-Token Blob images, fetch() SSE, and light-paper 1-Page Doctor Visit Brief PDF) inside a standalone Swift 5 WKWebView app wiring all 6 mandatory macOS delegates.\n\n## Table of Contents (7 Chapters)All UnlockedCh. 1 Free\n\n**Architecture, Safety & Agent-Build Blueprint:** Rather than dumping full production source files, Chapters 2 through 7 give you the local-first privacy architecture, hardware sizing, compact Python/TypeScript/Swift interface skeletons (\n\n`<= 40` lines each), forensic macOS & Ollama fixes, HAI-DEF licensing boundaries, and a Master Coding-Agent Prompt to build your own local family companion.\n## 1. Architecture, Privacy Guarantees & Apple Silicon Hardware Sizing\n\nKeeping track of a household's medical history usually turns into a fragmented paper chase: one partner's annual blood panel is buried in a password-protected PDF in Gmail, another's chest X-ray or 12-lead ECG strip lives in a phone gallery, prescriptions are scattered across messaging threads, and preparing a clear summary of changes before a 10-minute clinic visit takes an hour of manual spreadsheet juggling.\n\nUploading those intimate family health records into a third-party cloud chatbot is a privacy non-starter. Instead, I built **KinDesk**, a calm, high-craft **100% local Family Medical Companion for macOS** powered by **Google MedGemma 2** (`medgemma2:26b-mlx-bf16` via local Ollama). A household keeps isolated per-member vaults (`Ashutosh`, `Sharon`, plus unlimited added relatives via `+ Add`) right on the Mac, switches seamlessly between Warm Botanical-Espresso Dark Mode (System Dark default) and Warm Paper-Linen Light Mode, extracts encrypted lab PDFs into longitudinal markers and HL7 FHIR R4 bundles, inspects medical scans with MedGemma 2 vision + reasoning traces, runs peer-reviewed clinical calculators and macOS Seatbelt-sandboxed Python math (`0 net · 0 FS`), and exports a crisp light-paper **1-Page Doctor Visit Brief PDF** with Wi-Fi switched off and zero bytes sent to the cloud.\n\n**How This Blueprint Works:** Rather than dumping thousands of lines of brittle production source code, Chapters 2 through 7 give you the complete local-first architecture, Apple Silicon hardware sizing, short illustrative Python, TypeScript, and Swift skeletons (`<= 40` lines each), macOS security invariants, a 12-row forensic troubleshooting matrix, HAI-DEF licensing & clinical oversight boundaries, and a Master Coding-Agent Blueprint Prompt so you can build and tailor your own local companion.\n\n### End-to-End 6-Stage Local Family Health Pipeline\n\n### Why a 3-Layer Local Architecture (Dual-Mode Calm UI + Loopback Vault + Thin Native Shell)\n\n1. **Layer 1: Dual-Mode Botanical React 19 + TypeScript UI (Zero External CDNs):**  - Medical tools feel stressful when dressed like loud, high-alert trading terminals. KinDesk ships an adaptive dual-mode system using CSS `color-scheme: light dark` and`light-dark()` :**Warm Botanical-Espresso Dark Mode** (`#0E110F` backdrop,`#151917` canvas,`#1D221F` cards,`#63B99E` botanical sage,`#F1EDE5` warm cream ink) as the System Dark default, paired with a 1-click**Warm Paper-Linen Light Mode** (`#EFECE6` /`#FAF8F4` /`#FFFFFF` /`#2D6A5B` ), native macOS`ui-serif` editorial headings, soft biomarker range bars, and strictly three focused views:**`Overview`** ,**` Reports & Scans`** , and**` Ask KinDesk`** .\n  - Every font, icon, stylesheet, and asset ships locally inside the Vite bundle (zero Google Fonts, zero analytics pixels, zero remote CDNs), and the **1-Page Doctor Visit Brief** always locks to clean light paper on export regardless of the active UI theme.\n2. Medical tools feel stressful when dressed like loud, high-alert trading terminals. KinDesk ships an adaptive dual-mode system using CSS \n3. **Layer 2: Hardened Local Python FastAPI + SQLite FTS5 Vault (`127.0.0.1` Only):**  - Bound strictly to loopback (`127.0.0.1:<port>` ) with a per-session`X-KinDesk-Token` , strict`Content-Security-Policy: default-src 'self'; connect-src 'self'; img-src 'self' blob: data:` ,`0700` /`0600` vault permissions,`.metadata_never_index` Spotlight exclusion, and a deterministic`0 ms` emergency symptom guardrail that runs before the LLM sees a single token.\n  - Connects strictly to local Ollama (`127.0.0.1:11434` ) while enforcing strict server-side family member isolation: the LLM tool schema**never** accepts a`member_id` argument.\n4. Bound strictly to loopback (\n5. **Layer 3: Zero-Dependency Swift 5 `WKWebView` Native Mac App (`KinDesk.app`):**  - Compiled directly via `swiftc` (no Xcode project, no 300 MB Electron runtime), managing dynamic loopback port allocation, silent Ollama startup checks, native light/dark`NSWindow.appearance` synchronization,`NSOpenPanel` uploads,`file://` drag-drop protection, native`Edit` shortcuts, and offscreen`createPDF()` export on light paper for the 1-Page Doctor Visit Brief.\n6. Compiled directly via \n\n### Apple Silicon Hardware Sizing & Local MedGemma 2 Tiers\n\nPick the MedGemma 2 weight tier that matches your Mac's Unified Memory so the model stays resident (`keep_alive: \"30m\"`) without macOS memory swap thrashing:\n\n| Hardware Tier | Unified Memory | Recommended Local Model | Active Footprint ( `num_ctx: 32768` ) | Best Fit & Trade-Off | \n|---|---|---|---|---|\n| **Compact / Edge Mac** | **`12–16 GB`** (` M1–M4` ) | **MedGemma 2 `E4B`** (` medgemma2:e4b` 4B edge multimodal tier) | `~5–8 GB` | Fast local lab parsing, lightweight image walkthroughs, and visit prep on base MacBook Airs without swap pressure | \n| **Standard Apple Silicon Mac** | **`24–32 GB`** (` M2–M5 Pro` ) | **Ollama `medgemma2:26b`** (Q4 quantized MoE) | `~17–21 GB` | Strong 26B MoE clinical reasoning, multi-page lab extraction, `<\\|think\\|>` traces, and tool calling on everyday pro laptops | \n| **Studio / Max Apple Silicon** | **`64–128 GB`** (` M3/M4/M5 Max` or`Ultra` ) | **Ollama `medgemma2:26b-mlx-bf16`** (Default in KinDesk) | `~52–58 GB` | Unquantized `bf16` Apple MLX precision for nuanced vision reads, dense Indian/global lab tables, and zero quantization drift | \n\n### Local Model, Clinical Standards & Provenance Stack\n\nEvery model weight is pulled directly by you via official upstream channels (no weights are bundled or redistributed):\n\n| Component | Role in KinDesk | Local Engine / Runtime | License / Standard | \n|---|---|---|---|\n| **Google MedGemma 2 (`26b-mlx-bf16` / `26b` / `e4b`)** | Multimodal vision (CXR, ECG, derm), lab JSON extraction, `<\\|think\\|>` reasoning, tool calls | Local Ollama ( `127.0.0.1:11434` ) | Google **HAI-DEF Terms of Use***(non-diagnostic developer model)* | \n| **`PyMuPDF` (`pymupdf`) + Pillow + macOS `sips`** | In-memory encrypted PDF unlock, 160 DPI page renders, EXIF & `.HEIC` normalization | Python 3.11 + native macOS | AGPL / Commercial ( `PyMuPDF` ), HPND (`Pillow` ), macOS System | \n| **Curated LOINC + UCUM + HL7 FHIR R4 Engine** | Deterministic 88-biomarker normalization, unit math, portable `Bundle` export | Pure Python + SQLite WAL | LOINC / UCUM / HL7 FHIR R4 specifications | \n| **SQLite FTS5 + Bundled Clinical Summaries** | Instant offline BM25 reference lookup (KDIGO 2024, ADA, ACC/AHA, ATA, Endocrine) | Built-in Python `sqlite3` | Public-domain SQLite + original educational threshold notes | \n| **macOS Seatbelt (`sandbox-exec`) + AST Guard** | Two-layer isolated Python math execution ( `0 net · 0 FS` , vault denied) | Native macOS Darwin | macOS System Facility + Python `ast` | \n| **Swift 5 `AppKit` + `WKWebView`** | Standalone `/Applications/KinDesk.app` shell & native offscreen light-paper PDF Brief export | Native `swiftc`` arm64` | macOS System Frameworks | \n\n### What You Will Unlock in Chapters 2 to 7\n\n- **Chapter 2:** Exact local Ollama MLX bootstrap (`num_ctx: 32768` ,`keep_alive: \"30m\"` ), Python 3.11 + React 19 setup, macOS vault hardening (`0700` /`0600` ,`.metadata_never_index` ,`~/Documents` iCloud refusal), and zero-packet`scutil --nwi` offline detection.\n- **Chapter 3:** Real-world Lab PDF & prescription ingestion: in-memory password-protected PDF unlocking,`<untrusted_document>` prompt-injection delimiters, given-name patient-mismatch detection, curated LOINC + unit canonicalizer, inline human-in-the-loop verification, and spec-valid HL7 FHIR R4 serialization.\n- **Chapter 4:** Multimodal Medical Imaging Studio (PA Chest X-Ray, 12-Lead ECG,`.HEIC` +`<|think|>` trace), solving the Ollama`tools` +`format` collision, 4 server-bound local tools, deterministic`0 ms` negation-aware emergency triage, and the two-layer AST + macOS Seatbelt`sandbox-exec` math sandbox (`0 net · 0 FS` , replacing broken Darwin`RLIMIT_AS` ).\n- **Chapter 5:** Dual-mode Dark/Light theme tokens (`color-scheme: light dark` ,`light-dark()` , System Dark default + Light/Dark toggle), zero-URL-leak`X-KinDesk-Token` authentication (`fetch` -> Blob URLs +`ReadableStream` SSE), and the light-paper 1-Page Doctor Visit Brief.\n- **Chapter 6:** Native macOS`KinDesk.app` shell blueprint covering dynamic light/dark`NSWindow.appearance` sync and all 6 mandatory`WKWebView` delegates (`NSOpenPanel` , drag-drop`file://` guard, offscreen light-pinned`createPDF()` , native`Edit` menu, loopback port binding, and parent-PID lifecycle cleanup).\n- **Chapter 7:** Master End-to-End Coding-Agent Blueprint Prompt, 12-row forensic troubleshooting matrix of every macOS/Ollama trap we solved, and dedicated**HAI-DEF Model Licensing & Medical Oversight** guidelines.\n\n## Inside Chapters 2–7 (Included Free With Email Unlock)\n\nClick any chapter to unlock\nLoading your unlocked Chapters 2–7…\n\n## Unlock Chapters 2–7 + All Future Engineering Guides\n\nWe’ll email you a 1-click link to unlock all remaining chapters right here in your browser for 90 days, plus activate Ashutosh’s free **AI Compass daily AI news emails** (1-click unsubscribe anytime).\n\n[22 Chapters~58 min readAlready UnlockedIncluded Free With 1 Email UnlockRead Guide](https://ashutoshai.com/showcase/guides/image-to-3d-game-character)\n\n### Image-to-3D Character, Rigging & Real-Time Motion Handbook\n\nOne unified 22-chapter engineering handbook taking a single 2D concept to a 60 fps browser-native game character: Blender 5.2+ rigging & facial blink, 234 CC0 1.0 animations, analytical Hinge IK, 13-obstacle parkour, sword combat, Verlet cloth, adaptive Web Audio, and PS5 DualSense haptics.\n\n[8 Chapters~20 min readAlready UnlockedIncluded Free With 1 Email UnlockRead Guide](https://ashutoshai.com/showcase/guides/local-ai-video-editor)\n\n### Build Your Own Local AI Video Editor (SAM 3, v7.6 Metal 3D Studio, MLX & V4 4K60)\n\nArchitecture, color-science physics, clean code skeletons, and coding-agent prompts to build your own 100% local Apple Silicon AI video studio: v6.2 Fast/Fine matting, Fused Metal GPU 3D Studio (52-88 fps) with v7.6 hairline-safe universal color & Hybrid Alive Gimbal, Apple MLX fp32 eye contact, ScreenCaptureKit 4K60 capture, V4 Visual-First 2-Critic direction, and an MPS GPU dual 4K60 engine.\n\n[6 Chapters~20 min readAlready UnlockedIncluded Free With 1 Email UnlockRead Guide](https://ashutoshai.com/showcase/guides/local-mac-video-studio-app)\n\n### Build Your Own Local Mac Video Studio App (SwiftUI + OBS + AVFoundation + Whisper + Gemma 4)\n\nArchitecture, short Swift & Python interface skeletons, forensic bug fixes, and copy-paste coding-agent prompts to build your own 100% local Apple Silicon video studio app: top-flush Active Only teleprompter, Single-App OBS Cockpit + Built-in AVFoundation travel camera, Metal Whisper + 20ms MMS_FA + Gemma 4 retake editor with clickable word trimming, Tighten Pauses, Pace, single-pass 48 kHz audio, and one-click Stage 3 handoff.\n\n[6 Chapters~17 min readAlready UnlockedIncluded Free With 1 Email UnlockRead Guide](https://ashutoshai.com/showcase/guides/blender-mcp-3d-youtube-studio)\n\n### Build a Custom 3D YouTube Studio in Blender 5.2 with Blender MCP\n\nArchitecture, visual craft principles, compact Blender 5.2 LTS API patterns, and style-agnostic Blender MCP prompts to design your own photoreal 3D YouTube studio on Apple Silicon Cycles Metal GPU: 100% CC0 4K PBR assets, 5-plane architectural depth, non-destructive lighting moods, 5 calibrated cameras (including 9:16 VERTICAL), and 32-bit OpenEXR Z-depth passes.", "url": "https://wpnews.pro/news/build-a-100-local-family-medical-companion-on-mac-with-google-medgemma-2", "canonical_source": "https://ashutoshai.com/showcase/guides/local-family-medical-companion", "published_at": "2026-12-06 21:26:22+00:00", "updated_at": "2026-12-06 21:45:18.465954+00:00", "lang": "en", "topics": ["artificial-intelligence", "large-language-models", "ai-tools", "ai-safety", "ai-agents"], "entities": ["KinDesk", "Google MedGemma 2", "Ollama", "PyMuPDF", "Apple Silicon", "macOS", "HL7 FHIR R4", "LOINC"], "also_reported_by": [], "takeaway": "A fully local medical companion can run MedGemma 2 on a Mac by binding the vault to 127.0.0.1 with 0700/0600 permissions, keeping member_id out of the LLM and passing it only through server-bound tools, and sandboxing Python math with an AST plus macOS Seatbelt layer at 0 net and 0 FS access.", "recommendation": {"advice": "Keep sensitive identifiers like member_id out of the LLM context and pass them only through server-bound tools, and run local computation inside an AST plus Seatbelt sandbox with network and filesystem access disabled.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/build-a-100-local-family-medical-companion-on-mac-with-google-medgemma-2", "markdown": "https://wpnews.pro/news/build-a-100-local-family-medical-companion-on-mac-with-google-medgemma-2.md", "text": "https://wpnews.pro/news/build-a-100-local-family-medical-companion-on-mac-with-google-medgemma-2.txt", "jsonld": "https://wpnews.pro/news/build-a-100-local-family-medical-companion-on-mac-with-google-medgemma-2.jsonld"}}