# rakesh-codex/simple-calculator architecture

> Architecture diagram of the GitHub repository rakesh-codex/simple-calculator, 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/rakesh-codex/simple-calculator
- Repository: https://github.com/rakesh-codex/simple-calculator

## Overview

##### Project type and its purpose
- This is a CLI tool that takes user input from the command line, processes arithmetic operations (addition, subtraction, multiplication, division), and prints the result.
- The project focuses on argument parsing, error checking, numeric conversion, and executing arithmetic logic.

##### Main components
a. CLI Interface / Input Module:
- Represents the entry point where command-line arguments (os.Args) are received.

b. Input Validation & Parsing:
- How the program checks the number of arguments and parses numbers (using strconv.ParseFloat).

c. Operation Determination:

d. Arithmetic Computation:
- Execution of the arithmetic calculation.
- This can be a subcomponent within or tightly coupled to the “Operation Selector” since it directly computes the result.
- Branch for handling division by zero and other invalid operations.

e. Error Handling:
- Error exit points where invalid arguments, non-numeric input, or division by zero triggers an error message.
- This can be depicted as an adjacent "Error Handler" component that connects to the input validation and operation execution steps.

f. Output Formatter:
- Component that formats and prints the result (using fmt.Printf).

##### Relationships and data flows
- Once validated, data flows to “Operation Selector”, which then performs the arithmetic computation.
- If errors are detected at any stage, show a branch from “Error Handling” that outputs error messages and halts execution.
- Finally, valid calculation results are passed to “Output Formatter”, which displays the final result.

##### Design principles
- Keep components loosely coupled: each unit (parsing, validation, operation, error handling, output) functions independently.
- This modular representation can help when extending or maintaining the calculator (i.e., adding more operations).
- The simplicity reinforces best practices for building small CLI tools.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["CLI Input"]:::input_output
    B["Argument Parsing & Validation"]:::processing
    C["Operation Selector / Executor"]:::processing
    D["Arithmetic Computation"]:::processing
    E["Output Formatter/Printer"]:::input_output
    F["Error Handling"]:::error

    A -->|"provides_input"| B
    B -->|"valid_input"| C
    B -->|"invalid_input"| F
    C -->|"selects_operation"| D
    C -->|"operation_error"| F
    D -->|"computed_result"| E
    D -->|"computation_error"| F

    click A "https://github.com/rakesh-codex/simple-calculator/blob/main/main.go"
    click B "https://github.com/rakesh-codex/simple-calculator/blob/main/main.go"
    click C "https://github.com/rakesh-codex/simple-calculator/blob/main/main.go"
    click D "https://github.com/rakesh-codex/simple-calculator/blob/main/main.go"
    click E "https://github.com/rakesh-codex/simple-calculator/blob/main/main.go"
    click F "https://github.com/rakesh-codex/simple-calculator/blob/main/main.go"

    classDef input_output fill:#cce5ff,stroke:#0056b3,stroke-width:2px;
    classDef processing fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef error fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
