# tephsav/calculator architecture

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

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

## Overview

##### Project type and purpose
- This is a standalone console‐based calculator tool written in Java.
- Its sole responsibility is to read a single arithmetic expression from the command line, validate it (Arabic or Roman numerals between 1 and 10), perform one of four operations (+, –, *, /), and print the integer result (in the same numeral system as the input).

##### File structure
- Top-level files:
- README.md – describes requirements and usage
- .gitignore, .idea/, Calculator.iml – project metadata
- src/ directory holds four Java classes:
- Main.java      – CLI entry point, reads input and prints output
- Expression.java– parses the raw string into operands and operator, enforces grammar rules
- Converter.java – handles Roman↔Arabic conversions
- Calculator.java– performs the four arithmetic operations

##### README for additional insights
- No external dependencies or frameworks are used—just pure Java SE.
- The requirements emphasize single‐operation expressions, strict input ranges, throw errors on invalid input, and mirror the numeral system in the output.

##### Detail
- Notes on input constraints (1–10, single operator).
- Exception paths for invalid input (non‐integer, mixed numeral systems, out‐of‐range).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Nodes
    User["Console User"]:::external
    CLI["Main (CLI Layer)"]:::cli
    Parser["Expression (Parsing Layer)"]:::parser
    ConverterSvc["Converter (Conversion Service)"]:::service
    CalculatorSvc["Calculator (Calculation Service)"]:::service

    %% Data Flows
    User -->|"inputExpression"| CLI
    CLI -->|"parse(rawExpression)"| Parser
    Parser -->|"romanToInt() (if Roman)"| ConverterSvc
    Parser -->|"compute(a, b, op)"| CalculatorSvc
    CalculatorSvc -->|"resultInt"| Parser
    Parser -->|"intToRoman(result) (if Roman)"| ConverterSvc
    Parser -->|"formattedResult"| CLI
    CLI -->|"print(result)"| User

    %% Error Flows
    Parser -.-|"throws Exception (invalid input)"| CLI
    CLI -.-|"print(error)"| User

    %% Click Events
    click CLI "https://github.com/tephsav/calculator/blob/master/src/Main.java"
    click Parser "https://github.com/tephsav/calculator/blob/master/src/Expression.java"
    click ConverterSvc "https://github.com/tephsav/calculator/blob/master/src/Converter.java"
    click CalculatorSvc "https://github.com/tephsav/calculator/blob/master/src/Calculator.java"

    %% Styles
    classDef external fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef cli fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef parser fill:#87CEFA,stroke:#333,stroke-width:2px;
    classDef service fill:#90EE90,stroke:#333,stroke-width:2px;
```
