# yunuseeeeeeee/yunze-spark architecture

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

- Interactive diagram: https://gitdiagram.com/yunuseeeeeeee/yunze-spark
- Repository: https://github.com/yunuseeeeeeee/yunze-spark

## Overview

Yunze Spark is an Android app for downloading language models and chatting with them entirely on-device. The main workflow is: browse the model catalog, download a model, open its chat, and stream an answer from native inference; conversations are saved per model. Users can also add custom model links and change language or theme settings. The graph includes the documented llama.cpp/JNI layer and settings capabilities. Several connections come from the README or SOURCE INDEX; unsampled implementation details are not inferred.

Main entry points: [`SparkNavHost.kt`](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/SparkNavHost.kt) (Navigation host), [`SparkApplication.kt`](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/SparkApplication.kt) (Application services), [`ModelRepository.kt`](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelRepository.kt) (Model repository), [`ChatViewModel.kt`](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ChatViewModel.kt) (Chat orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["App entry and navigation"]
  node_activity["Main activity<br/>[MainActivity.kt]"]
  node_navigation["Navigation host<br/>[SparkNavHost.kt]"]
  node_application["Application services"]
end

subgraph group_models["Model catalog and downloads"]
  node_model_screen["Model browser<br/>[ModelListScreen.kt]"]
  node_model_vm["Model list state"]
  node_custom_screen["Custom model form"]
  node_catalog["Model catalog<br/>[ModelCatalog.kt]"]
  node_catalog_asset["Bundled catalog data"]
  node_repository["Model repository<br/>[ModelRepository.kt]"]
  node_download["Model downloader"]
  node_model_files[("Local model files")]
  node_model_data["Model metadata and state<br/>[ModelInfo.kt]"]
end

subgraph group_chat["Chat and inference"]
  node_chat_screen["Chat interface<br/>[ChatScreen.kt]"]
  node_chat_vm["Chat orchestration<br/>[ChatViewModel.kt]"]
  node_messages["Chat messages<br/>[ChatMessage.kt]"]
  node_inference["Inference engine<br/>[InferenceEngine.kt]"]
  node_jni["JNI bridge<br/>[LlamaBridge.kt]"]
  node_native["Native inference bridge<br/>[llama-bridge.cpp]"]
end

subgraph group_preferences["Settings and persistence"]
  node_history[("Chat history store")]
  node_settings_screen["Settings interface<br/>[SettingsScreen.kt]"]
  node_settings_vm["Settings state"]
  node_settings[("App settings<br/>[AppSettings.kt]")]
end

node_user(("App user"))
node_download_service(("Model hosting service"))

node_user -->|"opens app"| node_activity
node_activity -->|"starts"| node_navigation
node_navigation -->|"routes to"| node_model_screen
node_navigation -->|"routes to"| node_chat_screen
node_navigation -->|"routes to"| node_settings_screen
node_navigation -->|"routes to"| node_custom_screen
node_navigation -->|"uses services"| node_application
node_navigation -->|"creates"| node_model_vm
node_navigation -->|"creates"| node_chat_vm
node_navigation -->|"creates"| node_settings_vm
node_model_screen -->|"observes state"| node_model_vm
node_model_screen -->|"opens chat or settings"| node_navigation
node_custom_screen -->|"adds model"| node_model_vm
node_model_vm -->|"requests model actions"| node_repository
node_repository -->|"loads bundled entries"| node_catalog
node_catalog -->|"reads"| node_catalog_asset
node_repository -->|"reads custom models"| node_settings
node_repository -->|"manages downloads"| node_download
node_download -->|"fetches model"| node_download_service
node_download -->|"writes model files"| node_model_files
node_chat_screen -->|"sends chat actions"| node_chat_vm
node_chat_vm -->|"gets model path"| node_repository
node_chat_vm -->|"loads and saves"| node_history
node_history -->|"serializes"| node_messages
node_chat_vm -->|"formats and generates"| node_inference
node_inference -->|"calls native API"| node_jni
node_jni -->|"bridges JNI calls"| node_native
node_settings_screen -->|"observes settings"| node_settings_vm
node_settings_vm -->|"updates preferences"| node_settings
node_application -->|"creates"| node_settings
node_application -->|"creates"| node_history
node_application -->|"creates"| node_download
node_application -->|"creates"| node_repository
node_application -->|"creates"| node_inference
node_application -->|"initializes backend"| node_jni

click node_activity "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/MainActivity.kt"
click node_navigation "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/SparkNavHost.kt"
click node_model_screen "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelListScreen.kt"
click node_model_vm "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelListViewModel.kt"
click node_custom_screen "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/AddCustomModelScreen.kt"
click node_catalog "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelCatalog.kt"
click node_catalog_asset "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/models_catalog.json"
click node_repository "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelRepository.kt"
click node_download "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelDownloadManager.kt"
click node_model_files "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelDownloadManager.kt"
click node_model_data "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelInfo.kt"
click node_chat_screen "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ChatScreen.kt"
click node_chat_vm "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ChatViewModel.kt"
click node_history "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ChatHistoryStore.kt"
click node_messages "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ChatMessage.kt"
click node_inference "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/InferenceEngine.kt"
click node_jni "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/LlamaBridge.kt"
click node_native "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/llama-bridge.cpp"
click node_settings_screen "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/SettingsScreen.kt"
click node_settings_vm "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/SettingsViewModel.kt"
click node_settings "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/AppSettings.kt"
click node_application "https://github.com/yunuseeeeeeee/yunze-spark/blob/main/SparkApplication.kt"

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_activity,node_navigation,node_application,node_user toneBlue
class node_model_screen,node_model_vm,node_custom_screen,node_catalog,node_catalog_asset,node_repository,node_download,node_model_files,node_model_data toneAmber
class node_chat_screen,node_chat_vm,node_messages,node_inference,node_jni,node_native toneMint
class node_history,node_settings_screen,node_settings_vm,node_settings toneRose
class node_download_service toneIndigo
```

## Components

### App entry and navigation

- [Main activity](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/MainActivity.kt): `MainActivity.kt`
- [Navigation host](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/SparkNavHost.kt): `SparkNavHost.kt`
- [Application services](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/SparkApplication.kt): `SparkApplication.kt`

### Model catalog and downloads

- [Model browser](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelListScreen.kt): `ModelListScreen.kt`
- [Model list state](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelListViewModel.kt): `ModelListViewModel.kt`
- [Custom model form](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/AddCustomModelScreen.kt): `AddCustomModelScreen.kt`
- [Model catalog](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelCatalog.kt): `ModelCatalog.kt`
- [Bundled catalog data](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/models_catalog.json): `models_catalog.json`
- [Model repository](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelRepository.kt): `ModelRepository.kt`
- [Model downloader](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelDownloadManager.kt): `ModelDownloadManager.kt`
- [Local model files](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelDownloadManager.kt): `ModelDownloadManager.kt`
- [Model metadata and state](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ModelInfo.kt): `ModelInfo.kt`

### Chat and inference

- [Chat interface](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ChatScreen.kt): `ChatScreen.kt`
- [Chat orchestration](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ChatViewModel.kt): `ChatViewModel.kt`
- [Chat messages](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ChatMessage.kt): `ChatMessage.kt`
- [Inference engine](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/InferenceEngine.kt): `InferenceEngine.kt`
- [JNI bridge](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/LlamaBridge.kt): `LlamaBridge.kt`
- [Native inference bridge](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/llama-bridge.cpp): `llama-bridge.cpp`

### Settings and persistence

- [Chat history store](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/ChatHistoryStore.kt): `ChatHistoryStore.kt`
- [Settings interface](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/SettingsScreen.kt): `SettingsScreen.kt`
- [Settings state](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/SettingsViewModel.kt): `SettingsViewModel.kt`
- [App settings](https://github.com/yunuseeeeeeee/yunze-spark/blob/main/AppSettings.kt): `AppSettings.kt`

### Other components

- **App user**
- **Model hosting service**

## Connections

- App user → Main activity: opens app (evidence: `MainActivity.kt`)
- Main activity → Navigation host: starts (evidence: `MainActivity.kt`)
- Navigation host → Model browser: routes to (evidence: `SparkNavHost.kt`)
- Navigation host → Chat interface: routes to (evidence: `SparkNavHost.kt`)
- Navigation host → Settings interface: routes to (evidence: `SparkNavHost.kt`)
- Navigation host → Custom model form: routes to (evidence: `SparkNavHost.kt`)
- Navigation host → Application services: uses services (evidence: `SparkNavHost.kt`)
- Navigation host → Model list state: creates (evidence: `SparkNavHost.kt`)
- Navigation host → Chat orchestration: creates (evidence: `SparkNavHost.kt`)
- Navigation host → Settings state: creates (evidence: `SparkNavHost.kt`)
- Model browser → Model list state: observes state (evidence: `ModelListScreen.kt`)
- Model browser → Navigation host: opens chat or settings (evidence: `SparkNavHost.kt`)
- Custom model form → Model list state: adds model (evidence: `SparkNavHost.kt`)
- Model list state → Model repository: requests model actions (evidence: `ModelListViewModel.kt`)
- Model repository → Model catalog: loads bundled entries (evidence: `ModelRepository.kt`)
- Model catalog → Bundled catalog data: reads (evidence: `ModelCatalog.kt`)
- Model repository → App settings: reads custom models (evidence: `ModelRepository.kt`)
- Model repository → Model downloader: manages downloads (evidence: `ModelRepository.kt`)
- Model downloader → Model hosting service: fetches model (evidence: `ModelDownloadManager.kt`)
- Model downloader → Local model files: writes model files (evidence: `ModelDownloadManager.kt`)
- Chat interface → Chat orchestration: sends chat actions (evidence: `ChatScreen.kt`)
- Chat orchestration → Model repository: gets model path (evidence: `ChatViewModel.kt`)
- Chat orchestration → Chat history store: loads and saves (evidence: `ChatViewModel.kt`)
- Chat history store → Chat messages: serializes (evidence: `ChatHistoryStore.kt`)
- Chat orchestration → Inference engine: formats and generates (evidence: `ChatViewModel.kt`)
- Inference engine → JNI bridge: calls native API (evidence: `InferenceEngine.kt`)
- JNI bridge → Native inference bridge: bridges JNI calls (evidence: `README.md`)
- Settings interface → Settings state: observes settings (evidence: `SettingsScreen.kt`)
- Settings state → App settings: updates preferences (evidence: `SettingsViewModel.kt`)
- Application services → App settings: creates (evidence: `SparkApplication.kt`)
- Application services → Chat history store: creates (evidence: `SparkApplication.kt`)
- Application services → Model downloader: creates (evidence: `SparkApplication.kt`)
- Application services → Model repository: creates (evidence: `SparkApplication.kt`)
- Application services → Inference engine: creates (evidence: `SparkApplication.kt`)
- Application services → JNI bridge: initializes backend (evidence: `SparkApplication.kt`)
