# shubham0204/android-document-qa architecture

> Architecture diagram of the GitHub repository shubham0204/android-document-qa, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shubham0204/android-document-qa
- Repository: https://github.com/shubham0204/android-document-qa

## Overview

##### Project type and purpose
- This is a full-stack Android application (mobile client-only) implementing a retrieval-augmented generation (RAG) pipeline for document question-answering.
- Purpose: let users import PDF/DOCX, split text into chunks, generate on-device embeddings, store/retrieve them in a local vector DB, send top-K retrieved context + user query to a remote LLM (Gemini) for answer generation, and display results in a chat UI.

##### File structure
- Top-level “app” module (Gradle/Kotlin DSL) with:
- src/main/java/com/ml/.../docqa
– data (ObjectBox schemas, API key)
– domain (readers, splitters, embeddings provider, LLM API)
– di (AppModule)
– ui (MVVM screens + components)
- src/main/assets (ONNX embedding model, tokenizer.json)
- src/main/res (UI resources, prompt template in strings.xml)
- libs (sentence_embeddings.aar), objectbox-models (DB schema JSON)
- External config: proguard, backup rules, data extraction rules.
- Build: Gradle wrapper, versions TOML, GitHub Actions for release.

##### Extract architecture insights from README
- Clean-architecture layers: UI (Compose + ViewModels), Domain (use-cases: parse → split → embed → store → retrieve → prompt → call LLM), Data (ObjectBox vector store + tokenization + API).
- Technologies: Apache POI & iTextPDF (parsers), ONNX Runtime (embeddings), ObjectBox, Gemini Android SDK, Kotlin.

##### Elements
- Clear labels for each component/block (e.g., PDFReader, WhiteSpaceSplitter)
- Blue rectangles for UI components
- Green for domain services

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        A1["MainActivity"]:::ui
        A2["DocQAApplication"]:::ui
        subgraph "UI & ViewModels"
            ChatScreen["ChatScreen"]:::ui
            ChatViewModel["ChatViewModel"]:::ui
            DocsScreen["DocsScreen"]:::ui
            DocsViewModel["DocsViewModel"]:::ui
            EditAPIKeyScreen["EditAPIKeyScreen"]:::ui
            EditAPIKeyViewModel["EditAPIKeyViewModel"]:::ui
            AppAlertDialog["AppAlertDialog"]:::ui
            AppProgressDialog["AppProgressDialog"]:::ui
            Color["Color.kt"]:::ui
            Theme["Theme.kt"]:::ui
            Type["Type.kt"]:::ui
        end
        subgraph "DI Container"
            AppModule["AppModule"]:::ui
        end
        A1 --> ChatScreen
        ChatScreen --> ChatViewModel
        A1 --> DocsScreen
        DocsScreen --> DocsViewModel
        A1 --> EditAPIKeyScreen
        EditAPIKeyScreen --> EditAPIKeyViewModel
        A2 --> AppModule
        AppModule --> ChatViewModel
        AppModule --> DocsViewModel
        AppModule --> EditAPIKeyViewModel
    end

    subgraph "Domain Layer"
        PDFReader["PDFReader"]:::domain
        DOCXReader["DOCXReader"]:::domain
        WhiteSpaceSplitter["WhiteSpaceSplitter"]:::domain
        SentenceEmbeddingProvider["SentenceEmbeddingProvider"]:::domain
        RetrievalEngine["RetrievalEngine"]:::domain
        PromptBuilder["PromptBuilder"]:::domain
        GeminiRemoteAPI["GeminiRemoteAPI"]:::domain
    end

    subgraph "Data Layer"
        ObjectBoxStore["ObjectBoxStore"]:::data
        ChunksDB["ChunksDB"]:::data
        DocumentsDB["DocumentsDB"]:::data
        DataModels["DataModels"]:::data
        APIKey["GeminiAPIKey"]:::data
        assetsModel["all-MiniLM-L6-V2.onnx"]:::data
        assetsTokenizer["tokenizer.json"]:::data
        backupRules["backup_rules.xml"]:::data
        dataExtraction["data_extraction_rules.xml"]:::data
        strings["strings.xml"]:::data
    end

    Cloud["Gemini Cloud API"]:::external

    ChatViewModel -->|"import PDF/DOCX request"| PDFReader
    ChatViewModel -->|"import PDF/DOCX request"| DOCXReader
    PDFReader -->|"raw text"| WhiteSpaceSplitter
    DOCXReader -->|"raw text"| WhiteSpaceSplitter
    WhiteSpaceSplitter -->|"chunks"| SentenceEmbeddingProvider
    SentenceEmbeddingProvider -->|"embeddings"| ObjectBoxStore
    SentenceEmbeddingProvider --> assetsModel
    SentenceEmbeddingProvider --> assetsTokenizer
    ObjectBoxStore --> ChunksDB
    ObjectBoxStore --> DocumentsDB
    ObjectBoxStore --> DataModels
    DocsViewModel --> RetrievalEngine
    ChatViewModel --> RetrievalEngine
    RetrievalEngine --> ObjectBoxStore
    RetrievalEngine -->|"top-K chunks"| PromptBuilder
    PromptBuilder --> strings
    PromptBuilder -->|"prompt"| GeminiRemoteAPI
    GeminiRemoteAPI --> APIKey
    GeminiRemoteAPI --> Cloud
    Cloud -->|"answer"| ChatViewModel
    ChatViewModel --> ChatScreen
    DocsViewModel --> DocsScreen
    EditAPIKeyViewModel --> APIKey

    click ChatScreen "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/ui/screens/chat/ChatScreen.kt"
    click ChatViewModel "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/ui/screens/chat/ChatViewModel.kt"
    click DocsScreen "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/ui/screens/docs/DocsScreen.kt"
    click DocsViewModel "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/ui/screens/docs/DocsViewModel.kt"
    click EditAPIKeyScreen "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/ui/screens/edit_api_key/EditAPIKeyScreen.kt"
    click EditAPIKeyViewModel "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/ui/screens/edit_api_key/EditAPIKeyViewModel.kt"
    click AppAlertDialog "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/ui/components/AppAlertDialog.kt"
    click AppProgressDialog "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/ui/components/AppProgressDialog.kt"
    click Color "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/ui/theme/Color.kt"
    click Theme "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/ui/theme/Theme.kt"
    click Type "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/ui/theme/Type.kt"
    click DocQAApplication "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/DocQAApplication.kt"
    click MainActivity "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/MainActivity.kt"
    click AppModule "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/di/AppModule.kt"
    click PDFReader "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/domain/readers/PDFReader.kt"
    click DOCXReader "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/domain/readers/DOCXReader.kt"
    click WhiteSpaceSplitter "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/domain/splitters/WhiteSpaceSplitter.kt"
    click SentenceEmbeddingProvider "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/domain/embeddings/SentenceEmbeddingProvider.kt"
    click assetsModel "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/assets/all-MiniLM-L6-V2.onnx"
    click assetsTokenizer "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/assets/tokenizer.json"
    click ChunksDB "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/data/ChunksDB.kt"
    click DocumentsDB "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/data/DocumentsDB.kt"
    click DataModels "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/data/DataModels.kt"
    click ObjectBoxStore "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/data/ObjectBoxStore.kt"
    click APIKey "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/data/GeminiAPIKey.kt"
    click GeminiRemoteAPI "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/java/com/ml/shubham0204/docqa/domain/llm/GeminiRemoteAPI.kt"
    click strings "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/res/values/strings.xml"
    click backupRules "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/res/xml/backup_rules.xml"
    click dataExtraction "https://github.com/shubham0204/android-document-qa/blob/main/app/src/main/res/xml/data_extraction_rules.xml"

    classDef ui fill:#D0E8FF,stroke:#004CAC,color:#000
    classDef domain fill:#D0FFD6,stroke:#027A3F,color:#000
    classDef data fill:#FFF5B1,stroke:#8A6D1E,color:#000
    classDef external fill:#E0E0E0,stroke:#888,color:#000
```
