# sapoclay/calculaydora-cientrifica architecture

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

- Interactive diagram: https://gitdiagram.com/sapoclay/calculaydora-cientrifica
- Repository: https://github.com/sapoclay/calculaydora-cientrifica

## Overview

##### Project Type and Purpose
- This is a standalone desktop application implemented in Java (version 17+) using Swing for its GUI.
- Purpose: A scientific calculator that supports basic arithmetic, advanced functions (trigonometry, powers, square roots), and uses the Shunting-yard algorithm for expression evaluation.

##### High-Level Architectural Pattern
- We’ll map it to an MVC-inspired, layered monolith:
- View: Swing GUI components
- Controller: Event listeners / input handlers
- Model: Expression engine (tokenizer, parser, evaluator)
- Utility modules: error handler, history tracker (in-memory)

##### Main Components
a. GUI Layer (View)
- JFrame / JPanel with GridBagLayout
- Buttons, display field, history panel
- Tooltips, keyboard listeners
b. Input Controller
- ActionListeners and KeyListeners that capture button presses / keystrokes
- Build an infix expression string
c. Tokenizer
- Scans the infix string into tokens: numbers, operators, parentheses, functions
d. Parser / Shunting-yard Engine
- Converts infix tokens → postfix queue
- Manages operator precedence & associativity
e. Evaluator
- Uses a stack to compute the postfix expression
- Implements function calls (sin, cos, sqrt, etc.)
f. Error Handling Module
- Validates parentheses balance, division by zero, malformed input
- Populates GUI error dialogs or messages
g. In-Memory History Tracker
- Stores last N expressions & results for display (optional)

##### Relationships & Data Flows
1. User → (click/keypress) → GUI Layer
2. GUI Layer → Input Controller → Expression String
3. Controller → Tokenizer → Token List
4. Token List → Shunting-yard Parser → Postfix Queue
5. Postfix Queue → Evaluator → Numeric Result or Error
6. Result → GUI Layer (update display & history)

##### Architectural Patterns & Design Principles
- Layering: GUI | Controller | Model
- Single Responsibility: each module (tokenizer, parser, evaluator) has a clear role
- In-memory state: no external DB, state lives in application memory
- Algorithmic core: Shunting-yard for conversion + stack-based evaluation

##### Key Technologies & Frameworks
- Java 17+
- Swing (javax.swing) for desktop UI
- Java Collections (Stack, List, Queue)
- Maven for build (pom.xml implied in README)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User interaction
    User(("User")):::external

    %% Layers and Components
    subgraph "GUI Layer"
        View["View\n(Swing)"]:::ui
        Controller["Input Controller\n(ActionListener, KeyListener)"]:::ui
    end

    subgraph "Core Engine"
        Tokenizer["Tokenizer\n(infix→tokens)"]:::core
        Parser["Parser\n(Shunting-yard)"]:::core
        Evaluator["Evaluator\n(postfix→result)"]:::core
    end

    subgraph "Utilities"
        ErrorHandler["Error Handler\n(validation & GUI errors)"]:::util
        History["History Tracker\n(in-memory)"]:::util
    end

    %% Data Flows
    User -->|click/keypress| View
    View --> Controller
    Controller -->|"infix expression"| Tokenizer
    Tokenizer -->|"tokens"| Parser
    Parser -->|"postfix queue"| Evaluator
    Evaluator -->|"result"| View

    Parser -->|"syntax errors"| ErrorHandler
    Evaluator -->|"runtime errors"| ErrorHandler

    View -->|"update history"| History
    History -->|"history data"| View

    %% Click Events
    click View "https://github.com/sapoclay/calculaydora-cientrifica/blob/main/ScientificCalculator.java"
    click Controller "https://github.com/sapoclay/calculaydora-cientrifica/blob/main/ScientificCalculator.java"
    click Tokenizer "https://github.com/sapoclay/calculaydora-cientrifica/blob/main/ScientificCalculator.java"
    click Parser "https://github.com/sapoclay/calculaydora-cientrifica/blob/main/ScientificCalculator.java"
    click Evaluator "https://github.com/sapoclay/calculaydora-cientrifica/blob/main/ScientificCalculator.java"
    click ErrorHandler "https://github.com/sapoclay/calculaydora-cientrifica/blob/main/ScientificCalculator.java"
    click History "https://github.com/sapoclay/calculaydora-cientrifica/blob/main/ScientificCalculator.java"
    click README "https://github.com/sapoclay/calculaydora-cientrifica/blob/main/README.md"
    click LICENSE "https://github.com/sapoclay/calculaydora-cientrifica/tree/main/LICENSE"

    %% Legend
    subgraph "Legend"
        L1["Rounded Rectangle: Component"]:::legend
        L2["Blue: GUI Layer"]:::ui
        L3["Green: Core Engine"]:::core
        L4["Orange: Utilities"]:::util
    end

    %% Styles
    classDef ui fill:#a8d8ea,stroke:#000,stroke-width:1px;
    classDef core fill:#b1e693,stroke:#000,stroke-width:1px;
    classDef util fill:#ffcc80,stroke:#000,stroke-width:1px;
    classDef external fill:#e0e0e0,stroke-dasharray: 2 2;
    classDef legend fill:#f0f0f0,stroke:#000,stroke-width:1px,stroke-dasharray: 2 2;
```
