# yuva-raj444/mobllm architecture

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

- Interactive diagram: https://gitdiagram.com/yuva-raj444/mobllm
- Repository: https://github.com/yuva-raj444/mobllm

## Overview

OfflineLlamaChat is an Android app for running llama.cpp language models locally. The user provides a GGUF model path, loads the model, sends chat messages, and receives streamed tokens. The README describes the Compose UI and Kotlin chat components, while the sampled native source confirms JNI model loading, prompt processing, token streaming, abort, and cleanup. Kotlin source excerpts were not provided, so links among the app layers are shown as unverified; the native-to-llama.cpp calls are visible in the excerpt.

Main entry points: [`lib/src/main/cpp/ai_chat.cpp`](https://github.com/yuva-raj444/mobllm/blob/main/lib/src/main/cpp/ai_chat.cpp) (JNI inference), [`app/src/main/java/com/example/llama/ChatScreen.kt`](https://github.com/yuva-raj444/mobllm/blob/main/app/src/main/java/com/example/llama/ChatScreen.kt) (Chat screen), [`lib/src/main/java/com/example/llama/InferenceEngine.kt`](https://github.com/yuva-raj444/mobllm/blob/main/lib/src/main/java/com/example/llama/InferenceEngine.kt) (Inference API), [`app/src/main/java/com/example/llama/ChatViewModel.kt`](https://github.com/yuva-raj444/mobllm/blob/main/app/src/main/java/com/example/llama/ChatViewModel.kt) (Chat state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_android["Android app"]
  node_chat_screen["Chat screen<br/>[ChatScreen.kt]"]
  node_chat_vm["Chat state<br/>[ChatViewModel.kt]"]
  node_activity["App entry<br/>[MainActivity.kt]"]
end

subgraph group_inference["On-device inference"]
  node_engine["Inference API<br/>[InferenceEngine.kt]"]
  node_jni["JNI inference<br/>[ai_chat.cpp]"]
end

node_user(("User"))
node_model["GGUF model file"]
node_llama["llama.cpp runtime"]

node_user -->|"chats in"| node_chat_screen
node_activity -.->|"hosts UI"| node_chat_screen
node_chat_screen -.->|"forwards input"| node_chat_vm
node_chat_vm -.->|"requests inference"| node_engine
node_user -->|"provides path"| node_model
node_engine -->|"calls JNI"| node_jni
node_jni -->|"loads model"| node_model
node_jni -->|"runs inference"| node_llama
node_jni -->|"streams tokens"| node_engine

click node_chat_screen "https://github.com/yuva-raj444/mobllm/blob/main/app/src/main/java/com/example/llama/ChatScreen.kt"
click node_chat_vm "https://github.com/yuva-raj444/mobllm/blob/main/app/src/main/java/com/example/llama/ChatViewModel.kt"
click node_activity "https://github.com/yuva-raj444/mobllm/blob/main/app/src/main/java/com/example/llama/MainActivity.kt"
click node_engine "https://github.com/yuva-raj444/mobllm/blob/main/lib/src/main/java/com/example/llama/InferenceEngine.kt"
click node_jni "https://github.com/yuva-raj444/mobllm/blob/main/lib/src/main/cpp/ai_chat.cpp"

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_chat_screen,node_chat_vm,node_activity,node_user toneBlue
class node_engine,node_jni toneAmber
class node_model,node_llama toneIndigo
```

## Components

### Android app

- [Chat screen](https://github.com/yuva-raj444/mobllm/blob/main/app/src/main/java/com/example/llama/ChatScreen.kt): `app/src/main/java/com/example/llama/ChatScreen.kt`
- [Chat state](https://github.com/yuva-raj444/mobllm/blob/main/app/src/main/java/com/example/llama/ChatViewModel.kt): `app/src/main/java/com/example/llama/ChatViewModel.kt`
- [App entry](https://github.com/yuva-raj444/mobllm/blob/main/app/src/main/java/com/example/llama/MainActivity.kt): `app/src/main/java/com/example/llama/MainActivity.kt`

### On-device inference

- [Inference API](https://github.com/yuva-raj444/mobllm/blob/main/lib/src/main/java/com/example/llama/InferenceEngine.kt): `lib/src/main/java/com/example/llama/InferenceEngine.kt`
- [JNI inference](https://github.com/yuva-raj444/mobllm/blob/main/lib/src/main/cpp/ai_chat.cpp): `lib/src/main/cpp/ai_chat.cpp`

### Other components

- **User**
- **GGUF model file**
- **llama.cpp runtime**

## Connections

- User → Chat screen: chats in (evidence: `README.md`)
- App entry → Chat screen: hosts UI
- Chat screen → Chat state: forwards input
- Chat state → Inference API: requests inference
- User → GGUF model file: provides path (evidence: `README.md`)
- Inference API → JNI inference: calls JNI (evidence: `lib/src/main/cpp/ai_chat.cpp`)
- JNI inference → GGUF model file: loads model (evidence: `lib/src/main/cpp/ai_chat.cpp`)
- JNI inference → llama.cpp runtime: runs inference (evidence: `lib/src/main/cpp/ai_chat.cpp`)
- JNI inference → Inference API: streams tokens (evidence: `lib/src/main/cpp/ai_chat.cpp`)
