DocuSnapAI

DocuSnap AI: Bill & Rx Finder

Dual-Ecosystem Product: Native Android Production App + Cross-Platform Progressive Web App (PWA) + Firebase Cloud Sync & Auth + Production ASO & SEO Pack.


🌟 Executive Overview

DocuSnap AI is an intelligent document vault engineered to solve the everyday chaos of lost medical prescriptions, pharmacy slips, electricity/gas utility bills, and grocery receipts.

Rather than forcing users to manually open a scanner app, DocuSnap AI introduces Zero-Click Media Ingestion:


πŸ“± Ecosystem Architecture

                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                               β”‚           Android Gallery Photo / Snap       β”‚
                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                      β”‚
                                                      β–Ό
                                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                       β”‚   MediaObserverService      β”‚
                                       β”‚    (ContentObserver)        β”‚
                                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                      β”‚
                                                      β–Ό
                                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                       β”‚    MediaIngestionWorker     β”‚
                                       β”‚ (WorkManager Coroutine)     β”‚
                                       β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚              β”‚
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              └───────────────────────────┐
                   β–Ό                                                                      β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚  Google ML Kit OCR    β”‚                                              β”‚  Resolution & Hash   β”‚
        β”‚  (100% On-Device)     β”‚                                              β”‚  SHA-256 Dedupe      β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚ Gemini Flash Reasoningβ”‚ ───► Structured Entities: Doctor, Medicines, PKR Amounts, Vendor
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚  Room DB (SQLite FTS5)β”‚ ◄─────────────────────────────────────────── β”‚  Conversational UI   β”‚
        β”‚  Offline Search Index β”‚                                              β”‚  "Ask Anything" Box  β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚ Firebase Cloud Sync   β”‚ ◄───► Real-Time Firestore & Storage
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚  Cross-Platform PWA (iOS Safari / Desktop / Mac / Win) β”‚
        β”‚  - HTML5 Canvas Downscaling                            β”‚
        β”‚  - Native iOS "Add to Home Screen" Bottom Sheet Modal   β”‚
        β”‚  - Zero-Cost Static Hosting on GitHub Pages            β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Repository Structure

DocuSnapAI/
β”œβ”€β”€ android/                             # Native Android Production Application
β”‚   β”œβ”€β”€ build.gradle.kts                # Project build script
β”‚   β”œβ”€β”€ settings.gradle.kts             # Gradle settings
β”‚   β”œβ”€β”€ gradle.properties               # JVM & AndroidX properties
β”‚   └── app/
β”‚       β”œβ”€β”€ build.gradle.kts            # Compose, Room FTS5, ML Kit, Gemini, Firebase BOM
β”‚       β”œβ”€β”€ proguard-rules.pro          # ProGuard rules for Room, ML Kit & Gemini
β”‚       └── src/main/
β”‚           β”œβ”€β”€ AndroidManifest.xml     # Permissions (READ_MEDIA_IMAGES, FOREGROUND_SERVICE)
β”‚           β”œβ”€β”€ java/com/docusnap/ai/
β”‚           β”‚   β”œβ”€β”€ DocuSnapApplication.kt
β”‚           β”‚   β”œβ”€β”€ ai/
β”‚           β”‚   β”‚   └── GeminiReasoningEngine.kt     # Structured JSON & Conversational Search
β”‚           β”‚   β”œβ”€β”€ data/
β”‚           β”‚   β”‚   β”œβ”€β”€ local/
β”‚           β”‚   β”‚   β”‚   β”œβ”€β”€ AppDatabase.kt          # Room Database with FTS virtual table
β”‚           β”‚   β”‚   β”‚   └── DocumentDao.kt          # FTS5 MATCH queries & CRUD
β”‚           β”‚   β”‚   └── model/
β”‚           β”‚   β”‚       β”œβ”€β”€ DocumentEntity.kt       # Primary entity schema
β”‚           β”‚   β”‚       β”œβ”€β”€ DocumentFtsEntity.kt    # Room FTS4/5 entity
β”‚           β”‚   β”‚       └── DocumentDto.kt          # DTOs & JSON serialization
β”‚           β”‚   β”œβ”€β”€ ocr/
β”‚           β”‚   β”‚   └── OcrEngine.kt                # Bundled Google ML Kit Text Recognition
β”‚           β”‚   β”œβ”€β”€ service/
β”‚           β”‚   β”‚   β”œβ”€β”€ BootReceiver.kt             # Restarts observer service on device boot
β”‚           β”‚   β”‚   β”œβ”€β”€ MediaIngestionWorker.kt     # CoroutineWorker with aspect ratio filter
β”‚           β”‚   β”‚   └── MediaObserverService.kt     # Foreground Service + ContentObserver
β”‚           β”‚   β”œβ”€β”€ sync/
β”‚           β”‚   β”‚   └── FirebaseSyncRepository.kt   # Auth, Firestore & Storage sync
β”‚           β”‚   └── ui/
β”‚           β”‚       β”œβ”€β”€ MainActivity.kt             # Compose activity & permissions launcher
β”‚           β”‚       β”œβ”€β”€ DocuSnapNavHost.kt          # Navigation graph & bottom bar
β”‚           β”‚       β”œβ”€β”€ DocuSnapViewModel.kt        # StateFlow & conversational orchestrator
β”‚           β”‚       β”œβ”€β”€ screens/
β”‚           β”‚       β”‚   β”œβ”€β”€ ConversationalSearchScreen.kt  # "Ask Anything" (Roman Urdu/English)
β”‚           β”‚       β”‚   β”œβ”€β”€ DocumentInspectorScreen.kt     # Deep-zoomable viewer & copyable tags
β”‚           β”‚       β”‚   β”œβ”€β”€ SettingsScreen.kt              # On-Device vs Gemini & battery settings
β”‚           β”‚       β”‚   └── SmartVaultScreen.kt            # Categorized grid of documents
β”‚           β”‚       └── theme/
β”‚           β”‚           β”œβ”€β”€ Color.kt
β”‚           β”‚           β”œβ”€β”€ Theme.kt
β”‚           β”‚           └── Type.kt
β”‚           └── res/                    # Drawables, colors, strings, extraction rules
β”‚
β”œβ”€β”€ web/                                 # Cross-Platform Progressive Web App (PWA)
β”‚   β”œβ”€β”€ package.json                    # React 18, Vite, Tailwind CSS, Lucide, Firebase JS
β”‚   β”œβ”€β”€ vite.config.ts                  # Vite + VitePWA configuration
β”‚   β”œβ”€β”€ tailwind.config.js              # Theme colors matching Android Material 3
β”‚   β”œβ”€β”€ tsconfig.json                   # TypeScript bundler configuration
β”‚   β”œβ”€β”€ index.html                      # PWA meta tags & iOS Safari viewport fit
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   β”œβ”€β”€ 404.html                    # GitHub Pages SPA routing fallback script
β”‚   β”‚   β”œβ”€β”€ manifest.json               # Full PWA Web App Manifest
β”‚   β”‚   └── favicon.svg                 # DocuSnap vector brand asset
β”‚   └── src/
β”‚       β”œβ”€β”€ App.tsx                     # Main container, tabs, and real-time synchronization
β”‚       β”œβ”€β”€ firebase.ts                 # Firebase Auth, Storage, & Firestore snapshot listeners
β”‚       β”œβ”€β”€ gemini.ts                   # Gemini Flash multimodal vision & Roman Urdu reasoning
β”‚       β”œβ”€β”€ types.ts                    # TypeScript models matching Room Entity
β”‚       └── components/
β”‚           β”œβ”€β”€ ConversationalSearch.tsx # "Ask Anything" search with animated AI answer
β”‚           β”œβ”€β”€ SmartVault.tsx           # Categorized grid with filter chips & amounts
β”‚           β”œβ”€β”€ DocumentInspectorModal.tsx # Deep-zoom image inspector with one-click copy
β”‚           β”œβ”€β”€ UploadModal.tsx          # Client-side HTML5 Canvas downscaler & camera intake
β”‚           β”œβ”€β”€ IosInstallPrompt.tsx     # Native iOS Safari "Add to Home Screen" bottom sheet
β”‚           └── Navbar.tsx               # Brand header & navigation controls
β”‚
β”œβ”€β”€ firebase/                            # Cloud Backend Contracts & Rules
β”‚   β”œβ”€β”€ firebase.json                   # Hosting & Firestore configuration
β”‚   β”œβ”€β”€ firestore.rules                 # Security rules: users/{userId}/documents/{docId}
β”‚   β”œβ”€β”€ firestore.indexes.json          # Composite query indexes
β”‚   └── storage.rules                   # Rules for /images/ and /thumbs/
β”‚
β”œβ”€β”€ play_store_assets/                   # Google Play Store Production ASO
β”‚   β”œβ”€β”€ title.txt                       # Title (29/30 characters)
β”‚   β”œβ”€β”€ short_description.txt           # Short Description (79/80 characters)
β”‚   β”œβ”€β”€ full_description.txt            # Keyword-rich 4000-character description
β”‚   β”œβ”€β”€ listing_metadata.json           # Categories, ratings, contact info
β”‚   └── release_notes.txt               # Release notes for v1.0.0
β”‚
β”œβ”€β”€ web_seo/                             # Web SEO & Search Engine Optimization Pack
β”‚   β”œβ”€β”€ index.html                      # Complete OpenGraph, Twitter Card & JSON-LD
β”‚   β”œβ”€β”€ robots.txt                      # Search engine crawler directives
β”‚   └── sitemap.xml                     # XML Sitemap with daily change frequency
β”‚
└── README.md                            # Comprehensive product documentation

πŸš€ Key Architectural Details

1. Zero-Click Background Ingestion & Filtering

In android/.../service/MediaObserverService.kt:

2. Gemini Flash Deep Semantic Reasoning Schema

When Gemini Deep Reasoning is active, extracted text is analyzed using the following structured schema:

{
  "document_type": "Medical Prescription | Expense Receipt | Utility Bill | Bank Slip | General Document",
  "title": "Short descriptive title (e.g., Blood Test Report - Chughtai Lab)",
  "summary": "1-2 sentence conversational summary",
  "key_entities": {
    "doctor_name": "string or null",
    "medicines": ["string"],
    "total_amount": 1250.00,
    "vendor_or_hospital": "string or null",
    "date": "YYYY-MM-DD"
  },
  "searchable_tags": ["tag1", "tag2"]
}

3. β€œAsk Anything” Conversational Search Flow

  1. User enters natural language queries:
    • β€œDoctor ne pet dard k liay konsi goli likhi thi?”
    • β€œPichle month ka bijli ka bill kitna tha?”
  2. Search query is tokenized and executed against Room’s SQLite FTS5 virtual table (documents_fts MATCH :query).
  3. Matching candidate documents are passed to Gemini Flash.
  4. The model responds directly with the answer (e.g., β€œDoctor Tariq Mahmood ne pet dard k liay Tab Risek 40mg nashte se pehle likhi thi.”), followed by clickable document cards.

4. iOS Safari Native-Feel Integration & Client-Side Canvas Downscaling


πŸ› οΈ Build & Deployment Instructions

1. Android Application Build

  1. Open the android/ directory in Android Studio.
  2. Ensure you have Android SDK 34 and JDK 17 configured.
  3. Configure your GEMINI_API_KEY in android/app/build.gradle.kts or local.properties.
  4. Place your google-services.json from the Firebase console in android/app/.
  5. Run:
    ./gradlew assembleDebug
    

2. Web PWA Build & GitHub Pages Deployment

  1. Navigate to the web/ directory:
    cd web
    npm install
    npm run build
    
  2. The production bundle is output to web/dist/.
  3. To deploy to GitHub Pages:
    # Push dist directory to gh-pages branch
    git subtree push --prefix web/dist origin gh-pages
    

    Note: public/404.html ensures all deep SPA routes redirect seamlessly without 404 errors on GitHub Pages.

3. Firebase Deployment

From the project root:

firebase deploy --only firestore:rules,storage:rules

πŸ“„ License

DocuSnap AI is released under the MIT License.