# projectmatris/antimalwareapp architecture

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

- Interactive diagram: https://gitdiagram.com/projectmatris/antimalwareapp
- Repository: https://github.com/projectmatris/antimalwareapp

## Overview

##### Main Components
- UI Layer: Represented by a set of Android Activities (e.g., MainActivity, ScanActivity, CustomScanActivity, AppDetails, HelpActivity, SettingsActivity, etc.), layouts, and adapters (AppsAdapter, AppsListAdapter, ScanResultAdapter). These handle user interaction, display results, and allow configuration.
- Scanning Module: This includes the scanners (e.g., ApkScanner, AppScanner, ScannerTask) which are responsible for extracting features (permissions and intents) from installed applications.
- Machine Learning Inference Module: The module that loads and runs the TensorFlow Lite model (present as saved_model.tflite in the assets folder) to produce a prediction score.
- Services and Receivers: Background services (like RealTimeService) and broadcast receivers (e.g., BootCompletedReceiver, AppListener) that help in monitoring changes such as system boot or app installs and trigger scans.
- Helper and Utility Components: Supporting classes (like ThemeToggleHelper, AppConstants, Sha256HashExtractor) that manage supplementary logic and configuration.
- Data Model: Classes (like AppInfo) that represent the application data, which is used both for scanning results and UI population.
- External Integration: Although not part of the runtime architecture, note that CI/CD workflows (.github/workflows), build configurations (Gradle scripts), and external credits indicate integration with upstream machine learning model repositories and external libraries (like AboutLibraries).

##### Relationships and Interactions
- The UI Layer initiates actions (e.g., a manual scan via ScanActivity). This request is forwarded to the Scanning Module.
- The Scanning Module uses multiple scanners to extract features from each installed application. It then consolidates these into a feature vector.
- The extracted features are passed on to the ML Inference Module, which loads the TensorFlow Lite model and returns a prediction score that defines the classification (Goodware, Risky, Malware, or Unknown).
- Results are then propagated back to the UI, where they are displayed through various adapters and activities.
- Background components (RealTimeService and BroadcastReceivers) run continuously to monitor system events, triggering scans as needed (e.g., on device boot or on installation of a new app).
- Helper utilities provide cross-cutting functionalities (e.g., toggling themes, computing hashes) that assist the main modules.

##### Architectural Patterns and Design Principles
- Separation of Concerns: UI, scanning/inference logic, and background services are clearly separated.
- Event-Driven and Service-Oriented: With usage of Broadcast Receivers and background Services to trigger and handle scans reliably.
- Modular Design: Different Java packages (activities, scanners, adapters, data, services, helper, etc.) support maintainability and allow parallel development.

##### Relevant Technologies and Frameworks
- Android Framework (Activity lifecycle, layouts, services, BroadcastReceivers)
- TensorFlow Lite (on-device ML inference using saved_model.tflite)
- Gradle (build configuration and dependency management)
- External Libraries: For example, AboutLibraries for displaying open-source attributions.
- CI/CD tools (GitHub Actions configured via workflows) for automated testing/building.

- Rectangles for UI components and services.
- Oval or parallelograms for data models.

##### Capturing Essential Architectural Elements
- UI Layer (listing out primary activities and interaction flows)
- Background Processing (comprising RealTimeService and Receivers)
- Core Scanning Logic (Scanners, feature extractors)
- ML Inference Engine (model loader and predictor)
- Supporting utilities (helpers and configuration constants)
- Data flow: user action triggers scan → feature extraction → ML inference → results update the UI.

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI Layer Subgraph
    subgraph "UI Layer"
        UI_Activities["UI Activities (MainActivity, ScanActivity, CustomScanActivity, AppDetails, HelpActivity, SettingsActivity)"]:::ui
        UI_Adapters["UI Adapters (AppsAdapter, AppsListAdapter, ScanResultAdapter)"]:::ui
    end

    %% Scanning Module Subgraph
    subgraph "Scanning Module"
        Scanners["Scanning Module (ApkScanner, AppScanner, ScannerTask)"]:::scanners
    end

    %% ML Inference Subgraph
    subgraph "ML Inference"
        MLModel["ML Inference (TensorFlow Lite Model)"]:::ml
    end

    %% Data Model Subgraph
    subgraph "Data Model"
        DataModel["AppInfo (Data Model)"]:::data
    end

    %% Background Processing Subgraph
    subgraph "Background Processing"
        BackgroundService["RealTimeService"]:::bg
        BroadcastReceivers["Broadcast Receivers (e.g., BootCompletedReceiver, AppListener)"]:::bg
    end

    %% Utilities Subgraph
    subgraph "Utilities"
        Helpers["ThemeToggleHelper"]:::utility
        Utils["Utilities (AppConstants, Sha256HashExtractor)"]:::utility
    end

    %% External integration with Android OS
    Android_OS["Android OS"]:::external

    %% Connections
    UI_Activities -->|"startScan"| Scanners
    Scanners -->|"extractFeatures"| MLModel
    MLModel -->|"predictionScore"| Scanners
    Scanners -->|"updateResults"| UI_Activities
    Scanners -->|"storeData"| DataModel
    DataModel -->|"displayData"| UI_Activities
    UI_Activities -->|"render"| UI_Adapters

    Helpers -->|"support"| Scanners
    Utils -->|"support"| Scanners

    BackgroundService -->|"triggerScan"| Scanners
    BroadcastReceivers -->|"triggerScan"| Scanners
    Android_OS -->|"systemEvents"| BackgroundService
    Android_OS -->|"systemEvents"| BroadcastReceivers

    %% Click Events
    click UI_Activities "https://github.com/projectmatris/antimalwareapp/tree/development/app/src/main/java/tech/projectmatris/antimalwareapp/activities"
    click UI_Adapters "https://github.com/projectmatris/antimalwareapp/tree/development/app/src/main/java/tech/projectmatris/antimalwareapp/adapters"
    click Scanners "https://github.com/projectmatris/antimalwareapp/tree/development/app/src/main/java/tech/projectmatris/antimalwareapp/scanners"
    click MLModel "https://github.com/projectmatris/antimalwareapp/blob/development/app/src/main/assets/saved_model.tflite"
    click BackgroundService "https://github.com/projectmatris/antimalwareapp/blob/development/app/src/main/java/tech/projectmatris/antimalwareapp/services/RealTimeService.java"
    click BroadcastReceivers "https://github.com/projectmatris/antimalwareapp/tree/development/app/src/main/java/tech/projectmatris/antimalwareapp/receiver"
    click Helpers "https://github.com/projectmatris/antimalwareapp/blob/development/app/src/main/java/tech/projectmatris/antimalwareapp/helper/ThemeToggleHelper.java"
    click Utils "https://github.com/projectmatris/antimalwareapp/tree/development/app/src/main/java/tech/projectmatris/antimalwareapp/utils"
    click DataModel "https://github.com/projectmatris/antimalwareapp/blob/development/app/src/main/java/tech/projectmatris/antimalwareapp/data/AppInfo.java"

    %% Style definitions
    classDef ui fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef scanners fill:#c1f0c1,stroke:#333,stroke-width:2px;
    classDef ml fill:#fff2cc,stroke:#333,stroke-width:2px;
    classDef bg fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef utility fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef data fill:#f0a,stroke:#333,stroke-width:2px;
    classDef external fill:#e0e0e0,stroke:#333,stroke-dasharray: 5 5,stroke-width:2px;
```
