# software-mansion-labs/private-mind architecture

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

- Interactive diagram: https://gitdiagram.com/software-mansion-labs/private-mind
- Repository: https://github.com/software-mansion-labs/private-mind

## Overview

#### 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: [`components/chat-screen/ChatScreen.tsx`](https://github.com/software-mansion-labs/private-mind/blob/main/components/chat-screen/ChatScreen.tsx) (Chat presentation), [`store/chatStore.ts`](https://github.com/software-mansion-labs/private-mind/blob/main/store/chatStore.ts) (Chat state), [`database/db.ts`](https://github.com/software-mansion-labs/private-mind/blob/main/database/db.ts) (Local database), [`app/(drawer)/model-hub.tsx`](https://github.com/software-mansion-labs/private-mind/blob/main/app/(drawer)/model-hub.tsx) (Model hub)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Expo UI"]
  node_router["Root navigation<br/>Expo Router<br/>[_layout.tsx]"]
  node_drawer["Main drawer<br/>route layout<br/>[_layout.tsx]"]
  node_chat_route["Chat route<br/>screen<br/>[&#91;id&#93;.tsx]"]
  node_chat_screen["Chat presentation<br/>[ChatScreen.tsx]"]
  node_model_hub["Model hub<br/>screen<br/>[model-hub.tsx]"]
  node_model_import["Model import<br/>modal route"]
  node_benchmark["Benchmark flow<br/>screen + runner<br/>[benchmark.tsx]"]
end

subgraph group_state["App State &amp; Data"]
  node_chat_state["Chat state<br/>Zustand store<br/>[chatStore.ts]"]
  node_model_state["Model &amp; inference state<br/>Zustand store<br/>[llmStore.ts]"]
  node_prompt_boundary["Prompt &amp; compatibility<br/>inference preparation<br/>[promptUtils.ts]"]
  node_attachments["Attachment context<br/>content extraction<br/>[useAttachment.ts]"]
  node_local_database[("Local database<br/>persistence boundary<br/>[db.ts]")]
  node_model_catalog["Default model catalog<br/>metadata<br/>[default-models.ts]"]
  node_benchmark_data[("Benchmark history")]
end

subgraph group_native["Native Runtime &amp; Delivery"]
  node_speech["Speech input<br/>native STT integration<br/>[useSpeechInput.tsx]"]
  node_executorch{{"ExecuTorch inference<br/>native LLM runtime"}}
  node_model_assets["Model assets<br/>packaged/downloaded models"]
  node_platform_apps["iOS &amp; Android hosts<br/>native application<br/>[AppDelegate.swift]"]
  node_android_build["Android packaging<br/>Gradle build<br/>[build.gradle]"]
  node_release["Android release automation<br/>GitHub Actions"]
end

node_router -->|"hosts"| node_drawer
node_drawer -->|"navigates to"| node_chat_route
node_chat_route -->|"renders"| node_chat_screen
node_chat_screen -->|"reads and updates"| node_chat_state
node_chat_screen -->|"shows generation"| node_model_state
node_attachments -->|"adds context"| node_chat_state
node_chat_state -->|"persists chats"| node_local_database
node_model_hub -->|"lists defaults"| node_model_catalog
node_model_hub -->|"manages models"| node_local_database
node_model_import -->|"stores model record"| node_local_database
node_model_state -->|"prepares request"| node_prompt_boundary
node_prompt_boundary -->|"invokes inference"| node_executorch
node_model_assets -->|"supplies models"| node_executorch
node_benchmark -->|"measures runtime"| node_executorch
node_benchmark -->|"persists results"| node_benchmark_data
node_speech -->|"provides input"| node_chat_screen
node_platform_apps -->|"embeds native runtime"| node_executorch
node_android_build -->|"packages"| node_model_assets
node_release -->|"builds releases"| node_android_build

click node_router "https://github.com/software-mansion-labs/private-mind/blob/main/app/_layout.tsx"
click node_drawer "https://github.com/software-mansion-labs/private-mind/blob/main/app/(drawer)/_layout.tsx"
click node_chat_route "https://github.com/software-mansion-labs/private-mind/blob/main/app/(drawer)/chat/%5Bid%5D.tsx"
click node_chat_screen "https://github.com/software-mansion-labs/private-mind/blob/main/components/chat-screen/ChatScreen.tsx"
click node_model_hub "https://github.com/software-mansion-labs/private-mind/blob/main/app/(drawer)/model-hub.tsx"
click node_model_import "https://github.com/software-mansion-labs/private-mind/blob/main/app/(modals)/add-local-model.tsx"
click node_benchmark "https://github.com/software-mansion-labs/private-mind/blob/main/app/(drawer)/benchmark.tsx"
click node_chat_state "https://github.com/software-mansion-labs/private-mind/blob/main/store/chatStore.ts"
click node_model_state "https://github.com/software-mansion-labs/private-mind/blob/main/store/llmStore.ts"
click node_prompt_boundary "https://github.com/software-mansion-labs/private-mind/blob/main/utils/promptUtils.ts"
click node_attachments "https://github.com/software-mansion-labs/private-mind/blob/main/hooks/useAttachment.ts"
click node_local_database "https://github.com/software-mansion-labs/private-mind/blob/main/database/db.ts"
click node_model_catalog "https://github.com/software-mansion-labs/private-mind/blob/main/constants/default-models.ts"
click node_benchmark_data "https://github.com/software-mansion-labs/private-mind/blob/main/database/benchmarkRepository.ts"
click node_speech "https://github.com/software-mansion-labs/private-mind/blob/main/hooks/useSpeechInput.tsx"
click node_model_assets "https://github.com/software-mansion-labs/private-mind/tree/main/android/executorch_models"
click node_platform_apps "https://github.com/software-mansion-labs/private-mind/blob/main/ios/PrivateMind/AppDelegate.swift"
click node_android_build "https://github.com/software-mansion-labs/private-mind/blob/main/android/app/build.gradle"
click node_release "https://github.com/software-mansion-labs/private-mind/blob/main/.github/workflows/android-release.yml"

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_router,node_drawer,node_chat_route,node_chat_screen,node_model_hub,node_model_import,node_benchmark toneBlue
class node_chat_state,node_model_state,node_prompt_boundary,node_attachments,node_local_database,node_model_catalog,node_benchmark_data toneAmber
class node_speech,node_executorch,node_model_assets,node_platform_apps,node_android_build,node_release toneMint
```

## Components

### Expo UI

File-routed mobile screens and presentation.

- [Root navigation](https://github.com/software-mansion-labs/private-mind/blob/main/app/_layout.tsx): Expo Router · `app/_layout.tsx`
- [Main drawer](https://github.com/software-mansion-labs/private-mind/blob/main/app/(drawer)/_layout.tsx): route layout · `app/(drawer)/_layout.tsx`
- [Chat route](https://github.com/software-mansion-labs/private-mind/blob/main/app/(drawer)/chat/%5Bid%5D.tsx): screen · `app/(drawer)/chat/[id].tsx`
- [Chat presentation](https://github.com/software-mansion-labs/private-mind/blob/main/components/chat-screen/ChatScreen.tsx): Renders messages and generation state. · `components/chat-screen/ChatScreen.tsx`
- [Model hub](https://github.com/software-mansion-labs/private-mind/blob/main/app/(drawer)/model-hub.tsx): screen · Catalog and installed-model management. · `app/(drawer)/model-hub.tsx`
- [Model import](https://github.com/software-mansion-labs/private-mind/blob/main/app/(modals)/add-local-model.tsx): modal route · `app/(modals)/add-local-model.tsx`
- [Benchmark flow](https://github.com/software-mansion-labs/private-mind/blob/main/app/(drawer)/benchmark.tsx): screen + runner · Runs local model benchmarks. · `app/(drawer)/benchmark.tsx`

### App State & Data

Local state, persistence, and model preparation.

- [Chat state](https://github.com/software-mansion-labs/private-mind/blob/main/store/chatStore.ts): Zustand store · Owns conversations and messages. · `store/chatStore.ts`
- [Model & inference state](https://github.com/software-mansion-labs/private-mind/blob/main/store/llmStore.ts): Zustand store · Tracks selected model and inference state. · `store/llmStore.ts`
- [Prompt & compatibility](https://github.com/software-mansion-labs/private-mind/blob/main/utils/promptUtils.ts): inference preparation · Builds prompts and gates compatible models. · `utils/promptUtils.ts`
- [Attachment context](https://github.com/software-mansion-labs/private-mind/blob/main/hooks/useAttachment.ts): content extraction · `hooks/useAttachment.ts`
- [Local database](https://github.com/software-mansion-labs/private-mind/blob/main/database/db.ts): persistence boundary · Device-local chat, model, source, and benchmark records. · `database/db.ts`
- [Default model catalog](https://github.com/software-mansion-labs/private-mind/blob/main/constants/default-models.ts): metadata · `constants/default-models.ts`
- [Benchmark history](https://github.com/software-mansion-labs/private-mind/blob/main/database/benchmarkRepository.ts): repository · `database/benchmarkRepository.ts`

### Native Runtime & Delivery

On-device inference, platform projects, and release packaging.

- [Speech input](https://github.com/software-mansion-labs/private-mind/blob/main/hooks/useSpeechInput.tsx): native STT integration · Captures speech for chat input. · `hooks/useSpeechInput.tsx`
- **ExecuTorch inference**: native LLM runtime · Runs local models on device.
- [Model assets](https://github.com/software-mansion-labs/private-mind/tree/main/android/executorch_models): packaged/downloaded models · Local model files supplied with or acquired by the app. · `android/executorch_models`
- [iOS & Android hosts](https://github.com/software-mansion-labs/private-mind/blob/main/ios/PrivateMind/AppDelegate.swift): native application · `ios/PrivateMind/AppDelegate.swift`
- [Android packaging](https://github.com/software-mansion-labs/private-mind/blob/main/android/app/build.gradle): Gradle build · Packages app and ExecuTorch assets. · `android/app/build.gradle`
- [Android release automation](https://github.com/software-mansion-labs/private-mind/blob/main/.github/workflows/android-release.yml): GitHub Actions · `.github/workflows/android-release.yml`

## Connections

- 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
