# compro-prasad/advcalc architecture

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

- Interactive diagram: https://gitdiagram.com/compro-prasad/advcalc
- Repository: https://github.com/compro-prasad/advcalc

## Overview

##### Project Type and Purpose
- This is a reimplementation of a calculator (“calc”) built from scratch.
- It produces both a command-line interface (CLI) version and a Qt-based graphical user interface (GUI) version.
- The core functionality is encapsulated in a static library (libadvCalc.a) with separate executables for the CLI (src/calc) and the Qt GUI (src/calc_ui_qt/calc_qt).
- The build system uses CMake, and external dependencies include Qt (for GUI) and GNU Readline (for CLI input).

##### Analyzing the File Structure
- Top-level files (e.g., CMakeLists.txt, README.md, LICENSE) indicate that the project is well-organized with clear build instructions.
- The "src" directory holds the core source code. Within it, you see:
- Core modules like calcError, calcOptr, calcParser, calcStack, and string handling (str.cpp/hpp) that likely manage the calculation logic.
- A distinct subdirectory "calc_ui_qt" holding the Qt-specific version, with its own CMakeLists.txt and Qt project file (calc_ui_qt.pro).
- The existence of "calcServer.cpp" and "input_bindings.cpp" suggests some modular separation for potentially server/client or input handling functionalities.
- The "tests" directory includes sample test files (simpleTests and bugTests), indicating a testing strategy for the calculation logic.
- Additional directories like cmake and cmake/modules provide build configuration assistance, including custom find scripts for libraries like Readline.

##### Key Components
a. Core Calculator Engine:
- This is implemented in libadvCalc.a and consists of modules for parsing (calcParser), error handling (calcError), operator management (calcOptr), stack management (calcStack), and debugging (calcDebug).
- This as a central component labeled “Calc Core Library.”
b. CLI Application:
- Represented by src/calc and linked with the core library.
- It likely uses GNU Readline for input.
c. Qt GUI Application:
- Represented by src/calc_ui_qt/calc_qt.
- This component interfaces with the core calculator library to present a graphical user interface.
- It is built on top of the Qt framework.
d. Supporting Components:
- The testing suite included in the tests/ directory should be included to show how the core engine is verified.
- Optionally, note “Input Bindings” and “Server” if they have a role in runtime interactions.

##### Relationships and Interactions
- The build system (CMake) orchestrates the entire build process, linking both front ends with the core library and handling tests. Represent it as a control node interacting with all buildable targets.

##### Architectural Patterns
- This project demonstrates a layered architecture, separating the concerns of the core logic from the user interface.
- The design encourages code reuse, as both front ends share the same calculation backend.
- There is a clear separation of concerns:
– The CALC CORE layer handles computation, error management, and parsing.
– The interface layers (CLI and GUI) focus solely on interacting with the user.
- Mention that such separation makes it easier to test the core engine independently (as evidenced by the tests folder).

##### Additional Advice
- Don’t hesitate to break down the Calc Core into its submodules if they are significant (for example, separating error handling, parsing, and operator management can help clarify internal dependencies).
- Make use of annotations if certain components have special initialization sequences or interactions (e.g., if input bindings involve specific callback mechanisms).

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Build/System Configuration"
        BuildSys("CMake Build System"):::build
    end

    subgraph "CLI Application"
        CLI_Main("Main (CLI)"):::ui
        CLI_Input("Input Bindings"):::ui
        CLI_Server("Server"):::ui
    end

    subgraph "Qt GUI Application"
        GUIMain("Main (GUI)"):::ui
        GUICalc("Calc Module"):::ui
        GUIProj("Qt Project File"):::ui
    end

    subgraph "Calc Core Library"
        CoreParser("Parser (calcParser.hpp)"):::core
        CoreError("Error Handling (calcError)"):::core
        CoreOperator("Operator Management (calcOptr)"):::core
        CoreStack("Stack Management (calcStack.hpp)"):::core
        CoreString("String Handling (str.cpp/str.hpp)"):::core
        CoreDebug("Debug Module (calcDebug.hpp)"):::core
    end

    subgraph "Testing Suite"
        SimpleTest("Simple Tests"):::test
        BugTest("Bug Tests"):::test
        TestRunner("Test Runner (runTests.sh)"):::test
    end

    GNUReadline("GNU Readline"):::external
    QtFramework("Qt Framework"):::external

    %% Relationships
    BuildSys -->|"builds"| CLI_Main
    BuildSys -->|"builds"| GUIMain
    BuildSys -->|"builds"| CoreParser

    CLI_Main -->|"calls"| CoreParser
    GUIMain -->|"calls"| CoreParser

    CLI_Main -->|"uses"| GNUReadline
    GUIMain -->|"uses"| QtFramework

    SimpleTest -->|"tests"| CoreParser

    %% Click Events
    click BuildSys "https://github.com/compro-prasad/advcalc/blob/master/CMakeLists.txt"
    click CLI_Main "https://github.com/compro-prasad/advcalc/blob/master/src/main.cpp"
    click CLI_Input "https://github.com/compro-prasad/advcalc/blob/master/src/input_bindings.cpp"
    click CLI_Server "https://github.com/compro-prasad/advcalc/blob/master/src/calcServer.cpp"
    click GUIMain "https://github.com/compro-prasad/advcalc/blob/master/src/calc_ui_qt/main.cpp"
    click GUICalc "https://github.com/compro-prasad/advcalc/blob/master/src/calc_ui_qt/calc.cpp"
    click GUIProj "https://github.com/compro-prasad/advcalc/blob/master/src/calc_ui_qt/calc_ui_qt.pro"
    click CoreParser "https://github.com/compro-prasad/advcalc/tree/master/src/"
    click SimpleTest "https://github.com/compro-prasad/advcalc/tree/master/tests/"

    %% Styling
    classDef build fill:#cfc,stroke:#333,stroke-width:2px;
    classDef ui fill:#ccf,stroke:#333,stroke-width:2px;
    classDef core fill:#f9f,stroke:#333,stroke-width:2px;
    classDef test fill:#fcf,stroke:#333,stroke-width:2px;
    classDef external fill:#ffc,stroke:#333,stroke-width:2px;
```
