How software-mansion-labs/private-mind works
Purpose and runtime
Private Mind is an offline-first mobile AI assistant for on-device LLM chat, local model management, and device benchmarks. It is a React Native/Expo application targeting iOS and Android, with native projects checked in at ios/PrivateMind/AppDelegate.swift and android/app/src/main/java/com/swmansion/privatemind/MainApplication.kt. Local inference is backed by React Native ExecuTorch integration and bundled/downloaded model assets (android/executorch_models, scripts/download-models.js).
Application entry and navigation
Expo Router file routes are the UI entry surface. The root layout establishes app-wide providers and navigation at app/_layout.tsx; the primary drawer contains chat, model hub, and benchmark views under app/(drawer)/_layout.tsx, app/(drawer)/chat/[id].tsx, and app/(drawer)/model-hub.tsx. Modal routes cover onboarding and model editing/import workflows, including app/(modals)/onboarding.tsx and app/(modals)/add-local-model.tsx.
Chat and inference pipeline
Chat presentation is centered on components/chat-screen/ChatScreen.tsx, with message rendering and generation-state UI in components/chat-screen/Messages.tsx and components/chat-screen/ThinkingBlock.tsx. store/chatStore.ts owns active conversations/messages, while store/llmStore.ts manages model/inference state. Prompt construction, model configuration, and compatibility gating form the boundary before native inference: utils/promptUtils.ts, utils/modelConfig.ts, and utils/modelCompatibility.ts. Attachments and extracted content feed chat context through hooks/useAttachment.ts and utils/fileReaders.ts.
Persistent local data boundary
Repository modules isolate local persistence from UI and stores. database/db.ts provides database setup; database/chatRepository.ts persists conversations; database/modelRepository.ts persists installed/custom model definitions; and database/sourcesRepository.ts persists document/source metadata. Store modules coordinate application state over these repositories: store/chatStore.ts, store/modelStore.ts, and store/sourceStore.ts. This supports the product’s device-local data model rather than a cloud backend.
Model lifecycle and management
The model hub exposes catalog, family, selection, and management workflows via app/(drawer)/model-hub.tsx, components/model-hub/ModelCard.tsx, and components/bottomSheets/ModelManagementSheet.tsx. Default model metadata is defined in constants/default-models.ts; model family classification and compatibility rules reside in utils/modelFamily.ts and utils/modelCompatibility.ts. Users can add local or remote model records through app/(modals)/add-local-model.tsx and app/(modals)/add-remote-model.tsx; model fetching/native resource handling is represented by the ExecuTorch resource-fetcher mock dependency boundary.
Benchmarking and speech
Benchmark execution is initiated from app/(drawer)/benchmark.tsx, orchestrated by hooks/useBenchmarkRunner.tsx, and persisted through database/benchmarkRepository.ts. Results are surfaced in components/benchmark/BenchmarkHistory.tsx and related result UI. Speech-to-text state is separated in store/sttStore.ts, with input integration in hooks/useSpeechInput.tsx and components/chat-screen/ChatSpeechInput.tsx; this is an external native audio/STT capability boundary.
Platform delivery
Android Gradle configuration and packaged assets are rooted at android/app/build.gradle and android/executorch_models/build.gradle; iOS dependencies use ios/Podfile. Release automation is defined in .github/workflows/android-release.yml, while app metadata is in app.json. The app has no indicated server-side runtime; external services are limited to platform distribution (App Store/Google Play) and optional model acquisition before offline use.
Main entry points: ChatScreen.tsx Chat presentation · chatStore.ts Chat state · db.ts Local database · model-hub.tsx Model hub
Components 20
Expo UI
File-routed mobile screens and presentation.
- Root navigation
app/_layout.tsx - Main drawer
app/(drawer)/_layout.tsx - Chat route
app/(drawer)/chat/[id].tsx - Chat presentation · Renders messages and generation state.
components/chat-screen/ChatScreen.tsx - Model hub · Catalog and installed-model management.
app/(drawer)/model-hub.tsx - Model import
app/(modals)/add-local-model.tsx - Benchmark flow · Runs local model benchmarks.
app/(drawer)/benchmark.tsx
App State & Data
Local state, persistence, and model preparation.
- Chat state · Owns conversations and messages.
store/chatStore.ts - Model & inference state · Tracks selected model and inference state.
store/llmStore.ts - Prompt & compatibility · Builds prompts and gates compatible models.
utils/promptUtils.ts - Attachment context
hooks/useAttachment.ts - Local database · Device-local chat, model, source, and benchmark records.
database/db.ts - Default model catalog
constants/default-models.ts - Benchmark history
database/benchmarkRepository.ts
Native Runtime & Delivery
On-device inference, platform projects, and release packaging.
- Speech input · Captures speech for chat input.
hooks/useSpeechInput.tsx - ExecuTorch inference · Runs local models on device.
- Model assets · Local model files supplied with or acquired by the app.
android/executorch_models - iOS & Android hosts
ios/PrivateMind/AppDelegate.swift - Android packaging · Packages app and ExecuTorch assets.
android/app/build.gradle - Android release automation
.github/workflows/android-release.yml
Connections 19
- Root navigation → Main drawer: hosts
- Main drawer → Chat route: navigates to
- Chat route → Chat presentation: renders
- Chat presentation → Chat state: reads and updates
- Chat presentation → Model & inference state: shows generation
- Attachment context → Chat state: adds context
- Chat state → Local database: persists chats
- Model hub → Default model catalog: lists defaults
- Model hub → Local database: manages models
- Model import → Local database: stores model record
- Model & inference state → Prompt & compatibility: prepares request
- Prompt & compatibility → ExecuTorch inference: invokes inference
- Model assets → ExecuTorch inference: supplies models
- Benchmark flow → ExecuTorch inference: measures runtime
- Benchmark flow → Benchmark history: persists results
- Speech input → Chat presentation: provides input
- iOS & Android hosts → ExecuTorch inference: embeds native runtime
- Android packaging → Model assets: packages
- Android release automation → Android packaging: builds releases