# afollestad/mnml architecture

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

- Interactive diagram: https://gitdiagram.com/afollestad/mnml
- Repository: https://github.com/afollestad/mnml

## Overview

##### Main Components
- UI/Presentation Layer (app module):
– Contains activities and fragments (for example, MainActivity, SettingsActivity, and various UI components in the “ui” package).
– Uses MVVM design principles with ViewModels (e.g., MainViewModel, ScopedViewModel).
– Includes dependency injection modules (di directory with MainModule.kt and ViewModelModule.kt) to wire up dependencies.

- Core Engine (engine module):
– Implements the screen capturing functionality through classes like CaptureEngine, CaptureEngineRecorder, and the OverlayManager.
– Manages related tasks such as gesture recognition (ShakeListener), permission handling (CapturePermissionActivity, OverlayPermissionActivity), and background services (BackgroundService).
– Provides essential recording and overlay functionalities that drive the actual screen capture.

- Common Utilities (common module):
– Contains shared utilities and extensions (e.g., for intents, lifecycle, live data, and miscellaneous common functions).
– Offers dependency modules such as CommonModule and PrefModule to standardize operations across the app.

- Notifications (notifications module):
– Manages notification channels and displays using components like Notifications, NotificationChannelBuilder, and related resources for foreground notifications.
– Handles interactions with the user during screen recording through interactive notifications.

- Theming (theming module):
– Manages the aesthetic and visual appearance of the application including dark mode (see DarkModeSettings, DarkModeSwitchActivity).
– Provides layout and design resources which ensure the UI remains minimal and consistent.

##### Relationships and Interactions
- UI components (in the app module) trigger recording operations and interact with user settings and feedback.
- These UI layers depend on ViewModels which are provided via dependency injection, ensuring a clear separation of concerns.
- The UI layer calls into services provided by the engine module, which handles the capture logic, overlay display, and manages permissions.
- The common module supplies utilities and shared resources that are used by both the UI and engine.
- The notifications module listens to state changes (e.g., recording start/stop) and displays appropriate notifications.
- The theming module interacts with the UI layer to apply styling changes based on user preferences (like dark mode).

##### Architectural Patterns and Design Principles
- Modular Architecture: Each module (app, engine, common, notifications, theming) encapsulates distinct responsibilities.
- MVVM Pattern: UI screens (activities/fragments) work with ViewModels to manage state and business logic.
- Dependency Injection: Modules under “di” in the app layer organize how dependencies are provided to various components.
- Separation of Concerns: Utility functions in “common” are isolated from the domain-specific logic in “engine” and “notifications”.

##### Relevant Technologies
- Android Framework: The application harnesses Android’s UI components, services, and permissions model.
- Gradle Build System: Separate Gradle build files across modules indicate a well-organized build system.
- Kotlin: The source files (with “.kt” extension) show that Kotlin drives the implementation.
- Unit Testing: Presence of “src/test”, testutil, and theming tests indicates that there is a testing layer for robust functionality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer (UI Module)
    subgraph "Presentation Layer (UI Module)"
        direction TB
        A1["MainActivity"]:::ui
        A2["SettingsActivity"]:::ui
        A3["UI Fragments & Components"]:::ui
        VM["ViewModels (MainViewModel, ScopedViewModel)"]:::viewmodel
        DI_Main["MainModule"]:::di
        DI_VM["ViewModelModule"]:::di
    end

    %% Core Engine
    subgraph "Core Engine"
        direction TB
        CE["CaptureEngine, CaptureEngineRecorder"]:::engine
        OM["OverlayManager"]:::engine
        GL["GestureRecognition (ShakeListener)"]:::engine
        PERM["PermissionHandling (CapturePermissionActivity, OverlayPermissionActivity)"]:::engine
        BG["BackgroundService"]:::engine
    end

    %% Common Utilities
    subgraph "Common Utilities"
        direction TB
        CU["CommonUtilities & Extensions"]:::common
        CM["CommonModule & PrefModule"]:::common
    end

    %% Notifications Module
    subgraph "Notifications Module"
        direction TB
        NOTIF["Notifications & NotificationChannel"]:::notif
        NB["NotificationChannelBuilder"]:::notif
    end

    %% Theming Module
    subgraph "Theming Module"
        direction TB
        THEM["Theming & DarkMode (DarkModeSettings, DarkModeSwitchActivity)"]:::theming
        RES["StyleResources"]:::theming
    end

    %% Relationships for Presentation Layer
    A1 -->|"triggers"| VM
    A2 -->|"triggers"| VM
    A3 -->|"triggers"| VM
    DI_Main -->|"injects"| VM
    DI_VM -->|"injects"| VM

    %% Relationships from UI to Core Engine
    VM -->|"calls"| CE
    VM -->|"calls"| OM
    VM -->|"calls"| PERM
    VM -->|"calls"| BG

    %% Internal Core Engine Relation
    CE -->|"uses"| GL

    %% Core Engine to Notifications
    BG -->|"triggers"| NOTIF
    NOTIF -->|"builds"| NB

    %% Common Utilities supports both UI and Engine
    CU -->|"supports"| VM
    CU -->|"supports"| BG
    CM -->|"supports"| CE

    %% Theming effects on UI
    THEM -->|"styles"| A1
    THEM -->|"styles"| A2
    THEM -->|"styles"| A3

    %% Click Events for UI Module
    click A3 "https://github.com/afollestad/mnml/tree/master/app/src/main/java/com/afollestad/mnmlscreenrecord/ui"
    click DI_Main "https://github.com/afollestad/mnml/blob/master/app/src/main/java/com/afollestad/mnmlscreenrecord/di/MainModule.kt"
    click DI_VM "https://github.com/afollestad/mnml/blob/master/app/src/main/java/com/afollestad/mnmlscreenrecord/di/ViewModelModule.kt"

    %% Click Events for Core Engine
    click CE "https://github.com/afollestad/mnml/tree/master/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/capture"
    click OM "https://github.com/afollestad/mnml/tree/master/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/overlay"
    click GL "https://github.com/afollestad/mnml/tree/master/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/gesture"
    click PERM "https://github.com/afollestad/mnml/tree/master/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/permission"
    click BG "https://github.com/afollestad/mnml/tree/master/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/service"

    %% Click Events for Common Utilities
    click CU "https://github.com/afollestad/mnml/tree/master/common/src/main/java/com/afollestad/mnmlscreenrecord/common"
    click CM "https://github.com/afollestad/mnml/tree/master/common/src/main/java/com/afollestad/mnmlscreenrecord/common"

    %% Click Events for Notifications Module
    click NOTIF "https://github.com/afollestad/mnml/tree/master/notifications/src/main/java/com/afollestad/mnmlscreenrecord/notifications"
    click NB "https://github.com/afollestad/mnml/blob/master/notifications/src/main/java/com/afollestad/mnmlscreenrecord/notifications/providers/NotificationChannelBuilder.kt"

    %% Click Events for Theming Module
    click THEM "https://github.com/afollestad/mnml/tree/master/theming/src/main/java/com/afollestad/mnmlscreenrecord/theming"
    click RES "https://github.com/afollestad/mnml/tree/master/theming/src/main/res"

    %% Class Definitions for styling
    classDef ui fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef viewmodel fill:#b0e0e6,stroke:#333,stroke-width:2px;
    classDef di fill:#f5deb3,stroke:#333,stroke-width:2px;
    classDef engine fill:#d3ffce,stroke:#333,stroke-width:2px;
    classDef common fill:#e6e6fa,stroke:#333,stroke-width:2px;
    classDef notif fill:#ffe4e1,stroke:#333,stroke-width:2px;
    classDef theming fill:#fafad2,stroke:#333,stroke-width:2px;
```
