How reagent-systems/spark works
Project Type and Purpose
• Mobile full-stack app (Android) with on-device LLM inference plus a local API server.
• Clean-architecture/MVVM layered design.
File Structure
• app/src/main/java/com/example/spark/presentation – Jetpack Compose UI + ViewModels (Presentation layer).
• app/src/main/java/com/example/spark/domain – Domain models & repository interfaces (Domain layer).
• app/src/main/java/com/example/spark/data – Repository implementations, download/persistence/file managers (Data layer).
• app/src/main/java/com/example/spark/network/server – Ktor API server.
• utils – Token/auth helpers, performance & network utilities.
• AndroidManifest, resources, Gradle scripts for build/deployment.
README for Additional Insights
• Uses MediaPipe for on-device LLM inference.
• Ktor for local HTTP API.
• Jetpack Compose for UI.
• Model downloads from HuggingFace.
Main Components & Relationships
a. Presentation Layer
– Jetpack Compose screens & UI components
– ViewModels (ChatViewModel, ModelDownloadViewModel, ServerViewModel, etc.)
b. Domain Layer
– LLMRepository, UpdateRepository interfaces
– Domain models (LLMModel, UpdateModels)
c. Data Layer
– LLMRepositoryImpl & UpdateRepositoryImpl
– ModelDownloadManager (downloads from HF), ModelFileManager + ModelPersistenceManager
– Network API models (ApiModels) for server
d. Inference Engine
– MediaPipe LLM Inference (native library)
e. Local API Server
– Ktor server (ApiServer) listening on port 8080
– Exposes endpoints (/v1/models, /v1/chat/completions)
f. External Systems
– HuggingFace model hosting (for downloads)
– HTTP clients (other apps) calling the local API
Important Patterns & Principles
• MVVM + Clean Architecture (separate Presentation / Domain / Data)
• Repository pattern for data access & abstraction
• Single-Activity Compose with modular UI components
• Local-first (no cloud) architecture emphasizing privacy
• Asynchronous, callback/flow-based data flows