# darkempire78/opencalc architecture

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

- Interactive diagram: https://gitdiagram.com/darkempire78/opencalc
- Repository: https://github.com/darkempire78/opencalc

## Overview

##### Main Components
- Application/Entry Point: Represent the custom Application class (OpenCalcApp) that initializes global settings.
- UI Layer: Include all Activities (MainActivity, SettingsActivity, AboutActivity) and dialogs (e.g., DonationDialog) as the primary interfaces with the user.
- Calculator Engine: Create a distinct component for the core calculator functionality (the “calculator” package), which contains the Calculator class along with the parser (Expression and NumberFormatter) responsible for evaluating and formatting expressions.
- History Module: Display the History classes (History and HistoryAdapter) as a component that manages past calculations.
- Preferences and Themes: Add a component for configuration and customization (MyPreferences, Themes, and TextSizeAdjuster) that controls user options, themes, and display adjustments.
- Services: Include components like MyTileService which exposes the quick settings tile functionality.
- Android Resources: Represent resources such as layouts, drawables, and values, as they play an important role in the presentation layer.
- Testing and Build Tools: Although not part of the runtime architecture, note the testing (androidTest and test folders) and build/deployment configurations (Gradle build scripts and Fastlane metadata) that support continuous integration and release management.

##### Component Relationships and Interactions
- Global settings and theming (Preferences, Themes, TextSizeAdjuster) are accessed by both the UI Layer and, occasionally, the Calculator Engine to modify behavior or presentation.
- Background Services (MyTileService) interact with the Android system and may trigger some UI interactions.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project smartly segments UI, business logic, and domain-specific processing (calculation and parsing).

##### Relevant Technologies and Tools
- Android SDK and Kotlin as the primary language and platform.
- Gradle as the build automation system.
- Fastlane for build/deployment to the Play Store.
- XML resources for layouts, drawables, and string resources.
- Testing frameworks (unit tests and instrumented tests) to ensure reliability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Entry Point
    A["OpenCalcApp"]:::appEntry

    %% UI Layer (Presentation)
    subgraph "UI Layer (Presentation)"
        MA["MainActivity"]:::ui
        SA["SettingsActivity"]:::ui
        AA["AboutActivity"]:::ui
        DD["DonationDialog"]:::ui
    end

    %% Core Logic (Calculator & History)
    subgraph "Core Logic (Calculator & History)"
        CALC["Calculator"]:::logic
        EXP["Expression"]:::parser
        NF["NumberFormatter"]:::parser
        HIST["History"]:::history
        HA["HistoryAdapter"]:::history
    end

    %% Preferences and Themes
    subgraph "Preferences & Themes"
        MP["MyPreferences"]:::prefs
        TH["Themes"]:::prefs
        TSA["TextSizeAdjuster"]:::prefs
    end

    %% Services
    SVC["MyTileService"]:::service

    %% Android Resources
    RES["Android Resources"]:::resource

    %% Testing & Build Tools
    subgraph "Testing & Build Tools"
        IT["Instrumented Tests"]:::devTools
        UT["Unit Tests"]:::devTools
        GS["Gradle Scripts"]:::devTools
        FM["Fastlane Metadata"]:::devTools
    end

    %% Connections / Data Flow
    A -->|"init"| MA
    A -->|"init"| CALC

    %% UI interacts with Calculator Engine
    MA -->|"sends_input"| CALC
    AA -->|"accesses_config"| MP
    SA -->|"accesses_config"| MP
    DD -->|"dialog_action"| MA

    %% Calculator Engine calls Parser components
    CALC -->|"parses"| EXP
    CALC -->|"formats"| NF

    %% Calculator Engine updates History Module
    CALC -->|"updates"| HIST
    HIST <-->|"feeds_results"| MA
    HIST --> HA

    %% UI and Calculator use Preferences
    MA -->|"reads_config"| MP
    CALC -->|"reads_config"| MP

    %% Service Interaction with UI
    SVC -->|"triggers_UI"| MA

    %% Android Resources used by UI
    RES -->|"renders_layouts"| MA

    %% Testing & Build Tools support the App
    IT -->|"CI/CD"| A
    UT -->|"CI/CD"| A
    GS -->|"builds"| A
    FM -->|"deploys"| A

    %% Class Definitions for Styling
    classDef appEntry fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef logic fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef parser fill:#98fb98,stroke:#333,stroke-width:2px;
    classDef history fill:#c1f0c1,stroke:#333,stroke-width:2px;
    classDef prefs fill:#fdfd96,stroke:#333,stroke-width:2px;
    classDef service fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef resource fill:#ffe4b5,stroke:#333,stroke-width:2px;
    classDef devTools fill:#d3d3d3,stroke:#333,stroke-width:2px;

click A "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/OpenCalcApp.kt"
click MA "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/activities/MainActivity.kt"
click SA "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/activities/SettingsActivity.kt"
click AA "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/activities/AboutActivity.kt"
click DD "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/dialogs/DonationDialog.kt"
click CALC "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/calculator/Calculator.kt"
click EXP "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/calculator/parser/Expression.kt"
click NF "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/calculator/parser/NumberFormatter.kt"
click HIST "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/history/History.kt"
click HA "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/history/HistoryAdapter.kt"
click MP "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/MyPreferences.kt"
click TH "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/Themes.kt"
click TSA "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/TextSizeAdjuster.kt"
click SVC "https://github.com/darkempire78/opencalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/services/MyTileService.kt"
click RES "https://github.com/darkempire78/opencalc/tree/main/app/src/main/res"
click IT "https://github.com/darkempire78/opencalc/tree/main/app/src/androidTest"
click UT "https://github.com/darkempire78/opencalc/tree/main/app/src/test"
click GS "https://github.com/darkempire78/opencalc/blob/main/app/build.gradle.kts"
click FM "https://github.com/darkempire78/opencalc/tree/main/fastlane/metadata"
```
