# deference3/compose-calculator architecture

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

- Interactive diagram: https://gitdiagram.com/deference3/compose-calculator
- Repository: https://github.com/deference3/compose-calculator

## Overview

##### Project type and purpose
- This is an Android mobile application (“compose-calculator”) that implements a basic calculator UI using Jetpack Compose.
- It contains a single Gradle module (`app/`), using Kotlin, AndroidX, and Compose for UI, with unit and instrumentation tests.

##### File structure
- Top-level: Gradle wrappers and settings, GitHub Actions workflow (`.github/workflows/android.yml`), project-level `build.gradle`.
- Module `app/`:
- `build.gradle`, `proguard-rules.pro`
- `src/main/java/com/diffy/calculator/`
– Domain logic: `Calculator.kt`, `CalculatorOperations.kt`
– UI state & actions: `CalculatorState.kt`, `CalculatorActions.kt`
– ViewModel: `CalculatorViewModel.kt`
– Composable UI: `CalculatorButton.kt`, `MainActivity.kt`, theme files under `ui/theme/`
- Resources (`res/`): layouts are all Compose, plus drawables, mipmaps, values, XML backup/data rules.
- Tests: unit tests under `src/test/…`, instrumentation tests under `src/androidTest/…`.

##### Extract insights from README
- Confirms it’s a simple Compose-based calculator.
- No mention of external services, databases, or network calls—purely local UI+logic.

##### Main components
a. Android OS & application host (Activity lifecycle)
b. MainActivity (entry point)
c. Jetpack Compose UI layer (Composable functions & theming)
d. ViewModel (state holder, exposes UI state & handles actions)
e. Domain logic (Calculator, CalculatorOperations)
f. UI state & actions model (CalculatorState, CalculatorActions)
g. Build system (Gradle) and test modules (unit tests, instrumentation tests)

##### Relationships and interactions
- User taps a button in the Compose UI → triggers a `CalculatorActions` event → passed to `CalculatorViewModel`.
- `CalculatorViewModel` processes the action by calling domain logic (`Calculator.calculate()` or `CalculatorOperations`) → updates `CalculatorState`.
- Updated `CalculatorState` is observed by Compose UI → UI recomposes to show new result.
- Gradle builds the app and runs tests; instrumentation tests execute on Android emulator/device against MainActivity; unit tests verify domain logic.

##### Architectural patterns and principles
- MVVM pattern: Composable UI ←→ ViewModel ←→ Domain logic
- Unidirectional data flow: actions flow down, state flows up
- Separation of concerns: UI, state management, and business logic are in distinct packages/files
- Use of Jetpack Compose for declarative UI

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "CI/CD & Build"
        GH["GitHub Actions\n(.github/workflows/android.yml)"]:::ci
        PG["Project Gradle\nbuild.gradle"]:::gradle
        MG["Module Gradle\napp/build.gradle"]:::gradle
    end

    subgraph "App Module"
        MA["MainActivity"]:::activity
        subgraph "Compose UI"
            BTN["CalculatorButton"]:::ui
            THEME_COLOR["Color"]:::ui
            THEME_TYPE["Type"]:::ui
            THEME_THEME["Theme"]:::ui
        end
        VM["CalculatorViewModel"]:::viewmodel
        subgraph "UI Model"
            STATE["CalculatorState"]:::model
            ACTIONS["CalculatorActions"]:::model
        end
        subgraph "Domain Logic"
            CALC["Calculator"]:::domain
            OPS["CalculatorOperations"]:::domain
        end
        RES["Resources"]:::resources
    end

    AndroidOS["Android OS & Lifecycle"]:::os

    subgraph "Tests"
        UT["Unit Tests"]:::test
        IT["Instrumentation Tests"]:::test
    end

    %% Relationships
    GH --> PG
    PG --> MG

    MG --> MA

    MA -->|"sets content"| BTN
    MA -->|"applies theme"| THEME_THEME

    BTN -->|"onClick"| ACTIONS
    ACTIONS -->|"dispatch"| VM

    VM -->|"calculate()"| CALC
    VM -->|"operate()"| OPS
    CALC -->|"result"| VM
    OPS -->|"result"| VM

    VM -->|"update state"| STATE
    STATE -->|"state observed"| BTN

    MA -->|"loads resources"| RES

    MA -->|"lifecycle events"| AndroidOS
    AndroidOS -.->|"invokes"| MA

    UT -.->|"tests logic"| CALC
    IT -.->|"tests UI"| MA

    %% Click Events
    click MA "https://github.com/deference3/compose-calculator/blob/master/app/src/main/java/com/diffy/calculator/MainActivity.kt"
    click BTN "https://github.com/deference3/compose-calculator/blob/master/app/src/main/java/com/diffy/calculator/CalculatorButton.kt"
    click THEME_COLOR "https://github.com/deference3/compose-calculator/blob/master/app/src/main/java/com/diffy/calculator/ui/theme/Color.kt"
    click THEME_TYPE "https://github.com/deference3/compose-calculator/blob/master/app/src/main/java/com/diffy/calculator/ui/theme/Type.kt"
    click THEME_THEME "https://github.com/deference3/compose-calculator/blob/master/app/src/main/java/com/diffy/calculator/ui/theme/Theme.kt"
    click VM "https://github.com/deference3/compose-calculator/blob/master/app/src/main/java/com/diffy/calculator/CalculatorViewModel.kt"
    click CALC "https://github.com/deference3/compose-calculator/blob/master/app/src/main/java/com/diffy/calculator/Calculator.kt"
    click OPS "https://github.com/deference3/compose-calculator/blob/master/app/src/main/java/com/diffy/calculator/CalculatorOperations.kt"
    click STATE "https://github.com/deference3/compose-calculator/blob/master/app/src/main/java/com/diffy/calculator/CalculatorState.kt"
    click ACTIONS "https://github.com/deference3/compose-calculator/blob/master/app/src/main/java/com/diffy/calculator/CalculatorActions.kt"
    click RES "https://github.com/deference3/compose-calculator/tree/master/app/src/main/res"
    click PG "https://github.com/deference3/compose-calculator/blob/master/build.gradle"
    click MG "https://github.com/deference3/compose-calculator/blob/master/app/build.gradle"
    click GH "https://github.com/deference3/compose-calculator/blob/master/.github/workflows/android.yml"
    click UT "https://github.com/deference3/compose-calculator/blob/master/app/src/test/java/com/diffy/calculator/ExampleUnitTest.kt"
    click IT "https://github.com/deference3/compose-calculator/blob/master/app/src/androidTest/java/com/diffy/calculator/ExampleInstrumentedTest.kt"

    %% Styles
    classDef activity fill:#ccffcc,stroke:#006600
    classDef ui fill:#ccf2ff,stroke:#0077aa
    classDef viewmodel fill:#cce0ff,stroke:#0044cc
    classDef domain fill:#ffe0b3,stroke:#cc6600
    classDef model fill:#e6ccff,stroke:#6611aa
    classDef resources fill:#f2f2f2,stroke:#999999
    classDef gradle fill:#fff2cc,stroke:#cc9a06
    classDef ci fill:#ffd1dc,stroke:#cc2255
    classDef test fill:#ffe6e6,stroke:#aa0000,stroke-dasharray:5 5
    classDef os fill:#d9d9d9,stroke:#666666
```
