# startyr/calculatorx architecture

> Architecture diagram of the GitHub repository startyr/calculatorx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/startyr/calculatorx
- Repository: https://github.com/startyr/calculatorx

## Overview

CalculatorX is a HarmonyOS calculator whose main workflow turns formula input into a structured MathJSON expression, computes it through native math engines, presents a formatted result, and can retain the calculation in local history. The graph also preserves the documented graphing, exchange, programmer, and settings capabilities as separate product branches. The README documents the overall pipeline; sampled native sources confirm AST parsing, matrix routing, equation solving, and graph sampling. Several UI and exchange links use README descriptions and tree paths, since their implementation sources were not sampled.

Main entry points: [`entry/src/main/ets/pages/Index.ets`](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/pages/Index.ets) (Calculator workspace), [`entry/src/main/ets/utils/EngineService.ets`](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/utils/EngineService.ets) (Engine service), [`entry/src/main/cpp/engine.cpp`](https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/engine.cpp) (Native router), [`entry/src/main/ets/components/graphing/GraphingCalc.ets`](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/graphing/GraphingCalc.ets) (Graphing workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["App interaction"]
  node_app["Calculator workspace<br/>[Index.ets]"]
  node_math_input["Formula input<br/>[calculator.html]"]
  node_translate["Input translation"]
  node_calc_modes["Calc modes<br/>[ScientificCalc.ets]"]
  node_matrix_ui["Matrix tools<br/>[MatrixCalc.ets]"]
  node_equation_ui["Equation solver<br/>[EquationSolver.ets]"]
end

subgraph group_compute["Compute engines"]
  node_native_service["Engine service<br/>[EngineService.ets]"]
  node_native_engine["Native router<br/>[engine.cpp]"]
  node_ast_parser["MathJSON parser<br/>[parser.cpp]"]
  node_matrix_parser["Matrix operations<br/>[MatrixParser.cpp]"]
  node_symengine["SymEngine<br/>[parser.cpp]"]
  node_giac["Giac CAS<br/>[giac_bridge.cpp]"]
  node_formatter["Result formatting<br/>[FormatUtils.cpp]"]
end

subgraph group_special["Specialized tools"]
  node_graph_ui["Graphing workspace<br/>[GraphingCalc.ets]"]
  node_graph_engine["Graph sampler<br/>[GraphingEngine.cpp]"]
  node_exchange_ui["Currency converter<br/>[ExchangeRate.ets]"]
  node_exchange_data["Rates and cache<br/>[CurrencyData.ets]"]
  node_programmer_ui["Programmer mode<br/>[EquationSolver.ets]"]
  node_programmer_core["Programmer engine"]
end

subgraph group_state["Local state"]
  node_history_ui["History views<br/>[HistoryManager.ets]"]
  node_history_store[("Calculation history")]
  node_settings_ui["Preferences UI<br/>[Settings.ets]"]
  node_preferences[("User preferences")]
end

node_user(("Calculator user"))
node_rates_service["Exchange rate source"]

node_user -->|"uses"| node_app
node_app -->|"opens"| node_math_input
node_user -->|"enters formula"| node_math_input
node_math_input -->|"produces input"| node_translate
node_translate -->|"submits AST"| node_native_service
node_app -->|"selects mode"| node_calc_modes
node_app -->|"opens"| node_matrix_ui
node_app -->|"opens"| node_equation_ui
node_calc_modes -->|"requests calculation"| node_native_service
node_matrix_ui -->|"requests calculation"| node_native_service
node_equation_ui -->|"requests solving"| node_native_service
node_native_service -->|"invokes N-API"| node_native_engine
node_native_engine -->|"parses AST"| node_ast_parser
node_ast_parser -->|"routes matrix AST"| node_matrix_parser
node_native_engine -->|"solves equations"| node_giac
node_native_engine -->|"evaluates expressions"| node_symengine
node_native_engine -->|"formats result"| node_formatter
node_native_engine -->|"samples graph data"| node_graph_engine
node_graph_ui -->|"requests graph data"| node_native_service
node_graph_ui -->|"configures graph"| node_graph_engine
node_app -->|"opens"| node_graph_ui
node_app -->|"opens"| node_exchange_ui
node_exchange_ui -->|"reads rates"| node_exchange_data
node_exchange_data -.->|"refreshes rates"| node_rates_service
node_app -->|"opens"| node_programmer_ui
node_programmer_ui -->|"evaluates operations"| node_programmer_core
node_app -->|"opens"| node_history_ui
node_history_ui -->|"reads and manages"| node_history_store
node_app -->|"records calculations"| node_history_store
node_app -->|"opens"| node_settings_ui
node_settings_ui -->|"saves settings"| node_preferences
node_native_service -->|"reads calculation options"| node_preferences

click node_app "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/pages/Index.ets"
click node_math_input "https://github.com/startyr/calculatorx/blob/main/entry/src/main/resources/rawfile/calculator.html"
click node_translate "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/utils/InputTranslator.ets"
click node_calc_modes "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/ScientificCalc.ets"
click node_matrix_ui "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/MatrixCalc.ets"
click node_equation_ui "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/EquationSolver.ets"
click node_native_service "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/utils/EngineService.ets"
click node_native_engine "https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/engine.cpp"
click node_ast_parser "https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/core/parser.cpp"
click node_matrix_parser "https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/core/MatrixParser.cpp"
click node_symengine "https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/core/parser.cpp"
click node_giac "https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/core/giac_bridge.cpp"
click node_formatter "https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/utils/FormatUtils.cpp"
click node_graph_ui "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/graphing/GraphingCalc.ets"
click node_graph_engine "https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/core/GraphingEngine.cpp"
click node_exchange_ui "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/exchange/rates/ExchangeRate.ets"
click node_exchange_data "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/exchange/rates/CurrencyData.ets"
click node_programmer_ui "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/EquationSolver.ets"
click node_programmer_core "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/utils/base/ProgrammerEngine.ets"
click node_history_ui "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/pages/history/HistoryManager.ets"
click node_history_store "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/database/HistoryRepository.ets"
click node_settings_ui "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/pages/settings/Settings.ets"
click node_preferences "https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/utils/PreferenceManager.ets"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_math_input,node_translate,node_calc_modes,node_matrix_ui,node_equation_ui,node_user toneBlue
class node_native_service,node_native_engine,node_ast_parser,node_matrix_parser,node_symengine,node_giac,node_formatter toneAmber
class node_graph_ui,node_graph_engine,node_exchange_ui,node_exchange_data,node_programmer_ui,node_programmer_core toneMint
class node_history_ui,node_history_store,node_settings_ui,node_preferences toneRose
class node_rates_service toneIndigo
```

## Components

### App interaction

- [Calculator workspace](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/pages/Index.ets): `entry/src/main/ets/pages/Index.ets`
- [Formula input](https://github.com/startyr/calculatorx/blob/main/entry/src/main/resources/rawfile/calculator.html): `entry/src/main/resources/rawfile/calculator.html`
- [Input translation](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/utils/InputTranslator.ets): `entry/src/main/ets/utils/InputTranslator.ets`
- [Calc modes](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/ScientificCalc.ets): `entry/src/main/ets/components/ScientificCalc.ets`
- [Matrix tools](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/MatrixCalc.ets): `entry/src/main/ets/components/MatrixCalc.ets`
- [Equation solver](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/EquationSolver.ets): `entry/src/main/ets/components/EquationSolver.ets`

### Compute engines

- [Engine service](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/utils/EngineService.ets): `entry/src/main/ets/utils/EngineService.ets`
- [Native router](https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/engine.cpp): `entry/src/main/cpp/engine.cpp`
- [MathJSON parser](https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/core/parser.cpp): `entry/src/main/cpp/core/parser.cpp`
- [Matrix operations](https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/core/MatrixParser.cpp): `entry/src/main/cpp/core/MatrixParser.cpp`
- [SymEngine](https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/core/parser.cpp): `entry/src/main/cpp/core/parser.cpp`
- [Giac CAS](https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/core/giac_bridge.cpp): `entry/src/main/cpp/core/giac_bridge.cpp`
- [Result formatting](https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/utils/FormatUtils.cpp): `entry/src/main/cpp/utils/FormatUtils.cpp`

### Specialized tools

- [Graphing workspace](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/graphing/GraphingCalc.ets): `entry/src/main/ets/components/graphing/GraphingCalc.ets`
- [Graph sampler](https://github.com/startyr/calculatorx/blob/main/entry/src/main/cpp/core/GraphingEngine.cpp): `entry/src/main/cpp/core/GraphingEngine.cpp`
- [Currency converter](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/exchange/rates/ExchangeRate.ets): `entry/src/main/ets/components/exchange/rates/ExchangeRate.ets`
- [Rates and cache](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/exchange/rates/CurrencyData.ets): `entry/src/main/ets/components/exchange/rates/CurrencyData.ets`
- [Programmer mode](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/components/EquationSolver.ets): `entry/src/main/ets/components/EquationSolver.ets`
- [Programmer engine](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/utils/base/ProgrammerEngine.ets): `entry/src/main/ets/utils/base/ProgrammerEngine.ets`

### Local state

- [History views](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/pages/history/HistoryManager.ets): `entry/src/main/ets/pages/history/HistoryManager.ets`
- [Calculation history](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/database/HistoryRepository.ets): `entry/src/main/ets/database/HistoryRepository.ets`
- [Preferences UI](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/pages/settings/Settings.ets): `entry/src/main/ets/pages/settings/Settings.ets`
- [User preferences](https://github.com/startyr/calculatorx/blob/main/entry/src/main/ets/utils/PreferenceManager.ets): `entry/src/main/ets/utils/PreferenceManager.ets`

### Other components

- **Calculator user**
- **Exchange rate source**

## Connections

- Calculator user → Calculator workspace: uses
- Calculator workspace → Formula input: opens
- Calculator user → Formula input: enters formula
- Formula input → Input translation: produces input
- Input translation → Engine service: submits AST
- Calculator workspace → Calc modes: selects mode
- Calculator workspace → Matrix tools: opens
- Calculator workspace → Equation solver: opens
- Calc modes → Engine service: requests calculation
- Matrix tools → Engine service: requests calculation
- Equation solver → Engine service: requests solving
- Engine service → Native router: invokes N-API
- Native router → MathJSON parser: parses AST
- MathJSON parser → Matrix operations: routes matrix AST
- Native router → Giac CAS: solves equations
- Native router → SymEngine: evaluates expressions
- Native router → Result formatting: formats result
- Native router → Graph sampler: samples graph data
- Graphing workspace → Engine service: requests graph data
- Graphing workspace → Graph sampler: configures graph
- Calculator workspace → Graphing workspace: opens
- Calculator workspace → Currency converter: opens
- Currency converter → Rates and cache: reads rates
- Rates and cache → Exchange rate source: refreshes rates
- Calculator workspace → Programmer mode: opens
- Programmer mode → Programmer engine: evaluates operations
- Calculator workspace → History views: opens
- History views → Calculation history: reads and manages
- Calculator workspace → Calculation history: records calculations
- Calculator workspace → Preferences UI: opens
- Preferences UI → User preferences: saves settings
- Engine service → User preferences: reads calculation options
