# abhishek-2006/calculator architecture

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

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

## Overview

##### Project type and purpose
- This is a small, console-based calculator application written in C.
- It is essentially an open-source CLI tool that provides basic arithmetic operations (add, subtract, multiply, divide, modulus) via a menu-driven interface.

##### File structure
- Top-level files:
- Calculator.c  → contains the entire code (main function, menu loop, operation functions).
- README.md     → describes usage, features, build instructions.
- LICENSE       → MIT license.
- No sub-directories or external dependencies: everything lives in one source file.

##### README for additional insights
- Features highlight the supported operations, error-prevention (division/modulus by zero), and a looping mechanism to repeatedly perform calculations until exit.
- Build instructions use GCC, and the program runs in a terminal.

a. Main components
1. User Interface (CLI Menu)
2. Input Handler
3. Control Flow / Loop Manager
4. Calculator Core (Operation Modules)
– add()
– subtract()
– multiply()
– divide()
– modulus()
5. Error Handler
6. Output Handler
b. Relationships and interactions
– User → (1) selects operation and enters operands.
– CLI Menu forwards choice and inputs to Control Flow.
– Control Flow invokes the appropriate function in Calculator Core.
– Within the Core, Error Handler validates inputs (e.g., non-zero divisor).
– Core returns result to Output Handler.
– Output Handler displays result back to User.
– Control Flow loops back to CLI Menu until “Exit” is chosen.
c. Architectural patterns / design principles
– Modular separation of concerns:
- Presentation layer (CLI menu & output)
- Processing layer (arithmetic functions)
- Control layer (loop management)
- Validation layer (error checks)
– Single executable, no external services.
d. Relevant technologies & libraries
– Language: C, compiled with GCC
– Standard C library (stdio.h for I/O)
– Menu implemented using loops and switch/case

##### Detailed breakdown (component list)
- User (Terminal)
- CLI Menu
- Input Parser
- Control Loop Manager
- Operation Modules
- add()
- subtract()
- multiply()
- divide()
- modulus()
- Error Validator
- Output Formatter

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    User["User (Terminal)"]:::external
    GCC["GCC Compile"]:::external
    Executable["Calculator Executable"]:::external
    README["README.md"]:::docs
    LICENSE["LICENSE"]:::docs

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        CLI_Menu["CLI Menu"]:::ui
        Input_Parser["Input Parser"]:::ui
        Output_Formatter["Output Formatter"]:::ui
    end

    %% Control Layer
    subgraph "Control Layer"
        direction TB
        Control_Loop_Manager["Control Loop Manager"]:::control
    end

    %% Processing Layer
    subgraph "Processing Layer"
        direction TB
        Add["add()"]:::core
        Subtract["subtract()"]:::core
        Multiply["multiply()"]:::core
        Divide["divide()"]:::core
        Modulus["modulus()"]:::core
    end

    %% Validation Layer
    subgraph "Validation Layer"
        direction TB
        Error_Validator["Error Validator"]:::validation
    end

    %% Flow Connections
    User -->|"enter choice & operands"| CLI_Menu
    CLI_Menu -->|"parse input"| Input_Parser
    Input_Parser -->|"dispatch"| Control_Loop_Manager
    Control_Loop_Manager -->|"invoke add()"| Add
    Control_Loop_Manager -->|"invoke subtract()"| Subtract
    Control_Loop_Manager -->|"invoke multiply()"| Multiply
    Control_Loop_Manager -->|"invoke divide()"| Divide
    Control_Loop_Manager -->|"invoke modulus()"| Modulus

    Divide -->|"validate divisor"| Error_Validator
    Modulus -->|"validate divisor"| Error_Validator

    Add -->|"return result"| Output_Formatter
    Subtract -->|"return result"| Output_Formatter
    Multiply -->|"return result"| Output_Formatter
    Divide -->|"return result"| Output_Formatter
    Modulus -->|"return result"| Output_Formatter

    Output_Formatter -->|"display result"| User
    Control_Loop_Manager -->|"loop until exit"| CLI_Menu

    %% Build Process
    GCC -->|"compile Calculator.c"| Executable

    %% Documentation
    README
    LICENSE

    %% Click Events
    click CLI_Menu "https://github.com/abhishek-2006/calculator/blob/main/Calculator.c"
    click Input_Parser "https://github.com/abhishek-2006/calculator/blob/main/Calculator.c"
    click Control_Loop_Manager "https://github.com/abhishek-2006/calculator/blob/main/Calculator.c"
    click Add "https://github.com/abhishek-2006/calculator/blob/main/Calculator.c"
    click Subtract "https://github.com/abhishek-2006/calculator/blob/main/Calculator.c"
    click Multiply "https://github.com/abhishek-2006/calculator/blob/main/Calculator.c"
    click Divide "https://github.com/abhishek-2006/calculator/blob/main/Calculator.c"
    click Modulus "https://github.com/abhishek-2006/calculator/blob/main/Calculator.c"
    click Error_Validator "https://github.com/abhishek-2006/calculator/blob/main/Calculator.c"
    click Output_Formatter "https://github.com/abhishek-2006/calculator/blob/main/Calculator.c"
    click README "https://github.com/abhishek-2006/calculator/blob/main/README.md"
    click LICENSE "https://github.com/abhishek-2006/calculator/tree/main/LICENSE"

    %% Styles
    classDef ui fill:#bbdefb,stroke:#0d47a1,stroke-width:1px;
    classDef core fill:#c8e6c9,stroke:#1b5e20,stroke-width:1px;
    classDef validation fill:#ffccbc,stroke:#e64a19,stroke-width:1px;
    classDef control fill:#ffe0b2,stroke:#ef6c00,stroke-width:1px;
    classDef external fill:#e0e0e0,stroke:#424242,stroke-width:1px,stroke-dasharray: 5 5;
    classDef docs fill:#f3e5f5,stroke:#6a1b9a,stroke-width:1px;
```
