# fdvmoreira/binary-calculator architecture

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

- Interactive diagram: https://gitdiagram.com/fdvmoreira/binary-calculator
- Repository: https://github.com/fdvmoreira/binary-calculator

## Overview

##### Main Components
- User Interface (UI) Layer:
- index.html – Serves as the main entry point and contains the basic structure.
- css/binary-calculator.css – Styles the calculator interface.
- js/binary-calculator.js – Contains the application logic that parses user input, performs arithmetic on binary numbers, and updates the display.
- Testing Suite:
- The tests folder includes files such as calculator.test.js, readTextFromDisplay.test.js, writeTextToDisplay.test.js, and utils.test.js, which together ensure the application’s reliability.
- Configuration & Build Infrastructure:
- package.json/package-lock.json – Manage dependencies and scripts.
- jest.setup.js – Configures the testing environment.

##### Relationships and Interactions
- The UI layer (index.html) loads the CSS for styling and the JavaScript file for functionality.
- The JS file listens to user interactions (clicking on the binary digits, operators, and equal sign) from the HTML buttons.
- Once an operation is triggered, the JavaScript processes the binary arithmetic and then updates the UI – typically by writing back the result on the display.
- The testing suite is set up to run against the JS code to validate proper operations such as reading input, writing results, and handling different arithmetic operations.
- Package management (via package.json) integrates all the dependencies needed for development and testing.

##### Architectural Patterns and Design Principles
- Separation of concerns is evident:
- UI (HTML/CSS) is separate from the business logic (JS).
- Testing is isolated in its own directory.
- The design is kept simple and modular which fits well with a small-scale, single-purpose app.
- The project follows a clear structure that is easy to maintain and extend (if needed), even if it only supports two operands and a single operator at this moment.

##### Relevant Technologies and Frameworks
- HTML/CSS/JavaScript for the web front-end.
- Jest for testing the JavaScript functionalities.
- A local development server (via python3 -m http.server or live-server) for serving the web application.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        UI1("index.html"):::ui
        UI2("CSS (binary-calculator.css)"):::ui
    end

    subgraph "Business Logic"
        BL("JavaScript (binary-calculator.js)"):::bl
    end

    subgraph "Testing Suite"
        T1("calculator.test.js"):::test
        T2("readTextFromDisplay.test.js"):::test
        T3("utils.test.js"):::test
        T4("writeTextToDisplay.test.js"):::test
    end

    subgraph "Configuration & Dependencies"
        C1("package.json"):::config
        C2("package-lock.json"):::config
        C3("jest.setup.js"):::config
    end

    %% Relationships between components
    UI1 -->|"loads" | UI2
    UI1 -->|"triggers"| BL
    BL -->|"updates"| UI1
    BL -->|"validated_by"| T1
    BL -->|"validated_by"| T2
    BL -->|"validated_by"| T3
    BL -->|"validated_by"| T4
    C1 -->|"manages"| BL
    C2 -->|"manages"| BL
    C3 -->|"configures"| T1

    %% Click Events
    click UI1 "https://github.com/fdvmoreira/binary-calculator/blob/main/index.html"
    click UI2 "https://github.com/fdvmoreira/binary-calculator/blob/main/css/binary-calculator.css"
    click BL "https://github.com/fdvmoreira/binary-calculator/blob/main/js/binary-calculator.js"
    click T1 "https://github.com/fdvmoreira/binary-calculator/blob/main/tests/calculator.test.js"
    click T2 "https://github.com/fdvmoreira/binary-calculator/blob/main/tests/readTextFromDisplay.test.js"
    click T3 "https://github.com/fdvmoreira/binary-calculator/blob/main/tests/utils.test.js"
    click T4 "https://github.com/fdvmoreira/binary-calculator/blob/main/tests/writeTextToDisplay.test.js"
    click C1 "https://github.com/fdvmoreira/binary-calculator/blob/main/package.json"
    click C2 "https://github.com/fdvmoreira/binary-calculator/blob/main/package-lock.json"
    click C3 "https://github.com/fdvmoreira/binary-calculator/blob/main/jest.setup.js"

    %% Styles
    classDef ui fill:#85C1E9,stroke:#1B4F72,stroke-width:2px,color:#1B2631;
    classDef bl fill:#82E0AA,stroke:#196F3D,stroke-width:2px,color:#145A32;
    classDef test fill:#F8C471,stroke:#CA6F1E,stroke-width:2px,color:#7D6608;
    classDef config fill:#F5B7B1,stroke:#922B21,stroke-width:2px,color:#641E16;
```
