# aritra-tech/medai architecture

> Architecture diagram of the GitHub repository aritra-tech/medai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aritra-tech/medai
- Repository: https://github.com/aritra-tech/medai

## Overview

##### Project Type and Purpose
- MedAI is an Android mobile application (API 21+) built with Kotlin & Jetpack Compose.
- It leverages MVVM + repository pattern, Hilt DI, Google Gemini AI, and Firebase (Auth + Firestore + Analytics + Crashlytics + Messaging).
- Purpose: allow users to upload prescription images, validate & summarize via AI, authenticate with Google/Firebase, and persist data locally and in the cloud.

##### High-Level Architecture Overview
- Layered architecture with clear separation:
- UI Layer (Compose + ViewModels)
- Domain Layer (Models + Repository Interfaces + Use-Cases)
- Data Layer (Repository Implementations + Data Sources)
- External Services (Firebase endpoints & Google Gemini AI)
- DI Layer (Hilt modules to wire everything)

##### Main Components
a. UI Layer
- Compose Screens (Login, Onboarding, PrescriptionList, Details, Summarize, Profile, Settings, Splash)
- ViewModels (AuthViewModel, PrescriptionViewModel, PrescriptionDetailsViewModel, PrescriptionSummarizeViewModel, ProfileViewModel, SettingsViewModel, SplashViewModel)
b. Domain Layer
- Models (User, PrescriptionSummary, GeminiPrescriptionResponse, SignInResult)
- Interfaces (AuthRepository, PrescriptionRepository, BiometricAuthListener)
c. Data Layer
- DataStoreUtils (local prefs: dark mode, biometrics, auto-lock)
- AuthRepositoryImpl (uses FirebaseAuth + Google Sign-In)
- PrescriptionRepositoryImpl (uses Firestore + Google Gemini API)
d. External Services
- Firebase Authentication
- Firebase Firestore (prescriptions collection)
- Google Gemini Generative AI API
- Biometric API (AndroidX)
e. DI Layer
- AppModule (provides singletons: FirebaseAuth, Firestore, DataStore, Gemini service, Hilt bindings)

##### Relationships and Data Flows
- User taps a Compose Screen → ViewModel
- ViewModel calls Domain interfaces → Use-cases (implemented by Repo Impl)
- Repos delegate to Data Sources:
- AuthRepositoryImpl → FirebaseAuth / Google Sign-In
- PrescriptionRepositoryImpl → Google Gemini API for image analysis → Firestore to save/retrieve
- DataStoreUtils for local settings read/write
- Responses bubble back through ViewModel → UI state updates
- DI Layer injects dependencies at each level

##### Architectural Patterns & Principles
- MVVM (UI ← ViewModel ← Domain ← Data)
- Repository Pattern (abstract data sources behind interfaces)
- Single Responsibility (each package: ui, domain, data, di, utils)
- Dependency Injection with Hilt (loose coupling, testability)
- Coroutine-based async operations (off main thread)

## Diagram (Mermaid)

```mermaid
graph TB
    %% App Title
    AppTitle["MedAI Android App"]:::title

    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        subgraph "Compose Screens" 
            direction TB
            LoginScreen["LoginScreen"]:::ui
            SignUpScreen["SignUpScreen"]:::ui
            ForgotPasswordScreen["ForgotPasswordScreen"]:::ui
            WelcomeScreen["WelcomeScreen"]:::ui
            PrescriptionScreen["PrescriptionScreen"]:::ui
            PrescriptionDetailsScreen["PrescriptionDetailsScreen"]:::ui
            PrescriptionSummarizeScreen["PrescriptionSummarizeScreen"]:::ui
            ProfileScreen["ProfileScreen"]:::ui
            HelpScreen["HelpScreen"]:::ui
            SettingsScreen["SettingsScreen"]:::ui
            SplashView["SplashView"]:::ui
        end
        subgraph "ViewModels"
            direction TB
            AuthViewModel["AuthViewModel"]:::ui
            PrescriptionViewModel["PrescriptionViewModel"]:::ui
            PrescriptionDetailsViewModel["PrescriptionDetailsViewModel"]:::ui
            PrescriptionSummarizeViewModel["PrescriptionSummarizeViewModel"]:::ui
            ProfileViewModel["ProfileViewModel"]:::ui
            SettingsViewModel["SettingsViewModel"]:::ui
            SplashViewModel["SplashViewModel"]:::ui
        end
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        subgraph "Models"
            direction TB
            User["User"]:::domain
            PrescriptionSummary["PrescriptionSummary"]:::domain
            GeminiPrescriptionResponse["GeminiPrescriptionResponse"]:::domain
            SignInResult["SignInResult"]:::domain
        end
        subgraph "Interfaces"
            direction TB
            AuthRepository["AuthRepository"]:::domain
            PrescriptionRepository["PrescriptionRepository"]:::domain
            BiometricAuthListener["BiometricAuthListener"]:::domain
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DataStoreUtils["DataStoreUtils"]:::data
        AuthRepositoryImpl["AuthRepositoryImpl"]:::data
        PrescriptionRepositoryImpl["PrescriptionRepositoryImpl"]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        FirebaseAuthSvc["Firebase Authentication"]:::external
        FirestoreSvc["Firebase Firestore"]:::external
        GeminiAPI["Google Gemini AI API"]:::external
        BiometricAPI["Biometric API (AndroidX)"]:::external
    end

    %% DI Layer
    subgraph "DI Layer"
        direction TB
        AppModule["AppModule"]:::di
    end

    %% Relationships
    AppTitle --> UI
    UI --> AuthViewModel
    LoginScreen -->|"interacts"| AuthViewModel
    SignUpScreen -->|"interacts"| AuthViewModel
    ForgotPasswordScreen -->|"interacts"| AuthViewModel
    SplashView -->|"interacts"| SplashViewModel
    PrescriptionScreen -->|"interacts"| PrescriptionViewModel
    PrescriptionDetailsScreen -->|"interacts"| PrescriptionDetailsViewModel
    PrescriptionSummarizeScreen -->|"interacts"| PrescriptionSummarizeViewModel
    ProfileScreen -->|"interacts"| ProfileViewModel
    SettingsScreen -->|"interacts"| SettingsViewModel
    HelpScreen -->|"interacts"| ProfileViewModel

    AuthViewModel -->|"calls"| AuthRepository
    PrescriptionViewModel -->|"calls"| PrescriptionRepository
    PrescriptionDetailsViewModel -->|"calls"| PrescriptionRepository
    PrescriptionSummarizeViewModel -->|"calls"| PrescriptionRepository
    ProfileViewModel -->|"calls"| AuthRepository
    SettingsViewModel -->|"uses"| DataStoreUtils
    SplashViewModel -->|"uses"| AuthRepository

    AuthRepository --> AuthRepositoryImpl
    PrescriptionRepository --> PrescriptionRepositoryImpl
    BiometricAuthListener -.->|"callback"| AuthRepositoryImpl

    AuthRepositoryImpl -->|"sync"| FirebaseAuthSvc
    AuthRepositoryImpl -->|"sync"| FirestoreSvc
    PrescriptionRepositoryImpl -->|"async Image→AnalysisResult"| GeminiAPI
    PrescriptionRepositoryImpl -->|"async save/retrieve"| FirestoreSvc
    DataStoreUtils -->|"sync"| BiometricAPI

    %% DI injections
    AppModule --> AuthRepositoryImpl
    AppModule --> PrescriptionRepositoryImpl
    AppModule --> DataStoreUtils
    AppModule --> FirebaseAuthSvc
    AppModule --> FirestoreSvc
    AppModule --> GeminiAPI

    %% Click Events
    click LoginScreen "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/auth/LoginScreen.kt"
    click SignUpScreen "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/auth/SignUpScreen.kt"
    click ForgotPasswordScreen "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/auth/ForgotPasswordScreen.kt"
    click WelcomeScreen "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/onboarding/WelcomeScreen.kt"
    click PrescriptionScreen "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/prescription/PrescriptionScreen.kt"
    click PrescriptionDetailsScreen "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/prescriptionDetails/PrescriptionDetailsScreen.kt"
    click PrescriptionSummarizeScreen "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/prescriptionSummarize/PrescriptionSummarizeScreen.kt"
    click ProfileScreen "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/profile/ProfileScreen.kt"
    click HelpScreen "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/profile/HelpScreen.kt"
    click SettingsScreen "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/settings/SettingsScreen.kt"
    click SplashView "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/splash/SplashView.kt"

    click AuthViewModel "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/auth/AuthViewModel.kt"
    click PrescriptionViewModel "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/prescription/PrescriptionViewModel.kt"
    click PrescriptionDetailsViewModel "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/prescriptionDetails/PrescriptionDetailsViewModel.kt"
    click PrescriptionSummarizeViewModel "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/prescriptionSummarize/PrescriptionSummarizeViewModel.kt"
    click ProfileViewModel "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/profile/ProfileViewModel.kt"
    click SettingsViewModel "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/settings/SettingsViewModel.kt"
    click SplashViewModel "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/ui/presentation/splash/SplashViewModel.kt"

    click User "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/domain/model/User.kt"
    click PrescriptionSummary "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/domain/model/PrescriptionSummary.kt"
    click GeminiPrescriptionResponse "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/domain/model/GeminiPrescriptionResponse.kt"
    click SignInResult "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/domain/model/SignInResult.kt"

    click AuthRepository "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/domain/repository/AuthRepository.kt"
    click PrescriptionRepository "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/domain/repository/PrescriptionRepository.kt"
    click BiometricAuthListener "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/domain/repository/BiometricAuthListener.kt"

    click AuthRepositoryImpl "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/data/repository/AuthRepositoryImpl.kt"
    click PrescriptionRepositoryImpl "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/data/repository/PrescriptionRepositoryImpl.kt"
    click DataStoreUtils "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/data/datastore/DataStoreUtils.kt"

    click AppModule "https://github.com/aritra-tech/medai/blob/master/app/src/main/java/com/aritradas/medai/di/AppModule.kt"

    classDef title fill:#ffffff,stroke:#000000,stroke-width:2px,font-weight:bold
    classDef ui fill:#ADD8E6,stroke:#0000FF,color:#000
    classDef domain fill:#90EE90,stroke:#008000,color:#000
    classDef data fill:#FFA500,stroke:#FF8C00,color:#000
    classDef external fill:#D3D3D3,stroke:#A9A9A9,color:#000
    classDef di fill:#D8BFD8,stroke:#800080,color:#000
```
