# piyush1105/string-calculator-tdd architecture

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

- Interactive diagram: https://gitdiagram.com/piyush1105/string-calculator-tdd
- Repository: https://github.com/piyush1105/string-calculator-tdd

## Overview

##### Main Components
- Calculator Logic: Located in src/calculator.js, this is where the core function (add) is implemented. It handles parsing the string input (using commas, newlines, and custom delimiters), converting values to numbers, error-checking negative numbers, and computing the sum.
- CLI Interface: Represented by index.js. This component acts as an entry point for users running the calculator from the terminal. It parses command-line arguments and delegates to the calculator logic.
- Testing Framework: The tests directory (tests/calculator.test.js) paired with Jest ensures that the calculator function conforms to the defined requirements. This component validates correctness via TDD practices.
- Configuration & Package Files: package.json, package-lock.json, and .gitignore provide essential configuration, dependency management, and version control settings. While not active runtime components, they define and support the system's structure.

##### Establish Relationships and Interactions
- Testing Integration: Illustrate that the Testing Framework (using Jest) invokes functions in the Calculator Logic to ensure expected outputs (e.g., summing numbers or throwing errors for negatives).

##### Architectural Patterns and Design Principles
- Modular Design: The separation of calculator logic (src) from the user interface (index.js) demonstrates a modular approach. This enables easy testing and future enhancements.
- Test-Driven Development (TDD): Emphasize that the tests (under tests/) drive the development cycle (Red-Green-Refactor), ensuring robust, maintainable code.
- Single Responsibility Principle: Each component (CLI, core logic, testing) is responsible for a distinct part of the system, making it easy to maintain and extend.

##### Incorporate Relevant Technologies and Frameworks
- JavaScript (Node.js): Represent this as the runtime environment.
- Jest: Highlight its role in the testing component.
- Git: You might note version control support via .gitignore and repository setup instructions (although this is more about process than runtime architecture).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Components
    CLI["CLI Interface (index.js)"]:::cli
    CALC["Calculator Logic (src/calculator.js)"]:::core
    TEST["Test Suite (tests/calculator.test.js)"]:::test

    %% Configuration Files Subgraph
    subgraph "Configuration Files"
        PKG["package.json"]:::config
        PKGLOCK["package-lock.json"]:::config
        GIT[".gitignore"]:::config
    end

    %% Relationships
    CLI -->|"calls"| CALC
    TEST -->|"tests"| CALC

    %% Configuration Support (dashed arrows)
    PKG -.->|"supports"| CLI
    PKGLOCK -.->|"supports"| CALC
    GIT -.->|"supports"| TEST

    %% Click Events
    click CALC "https://github.com/piyush1105/string-calculator-tdd/blob/master/src/calculator.js"
    click CLI "https://github.com/piyush1105/string-calculator-tdd/blob/master/index.js"
    click TEST "https://github.com/piyush1105/string-calculator-tdd/blob/master/tests/calculator.test.js"
    click PKG "https://github.com/piyush1105/string-calculator-tdd/blob/master/package.json"
    click PKGLOCK "https://github.com/piyush1105/string-calculator-tdd/blob/master/package-lock.json"
    click GIT "https://github.com/piyush1105/string-calculator-tdd/blob/master/.gitignore"

    %% Styles
    classDef cli fill:#ffecd1,stroke:#333,stroke-width:2px;
    classDef core fill:#d1e8ff,stroke:#333,stroke-width:2px;
    classDef test fill:#d1ffd8,stroke:#333,stroke-width:2px;
    classDef config fill:#e8d1ff,stroke:#333,stroke-width:2px;
```
