# danielrajchristeen/py-calculator architecture

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

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

## Overview

##### Project type and purpose
- This is a standalone, command-line Python calculator application (“Py Calculator”).
- It lives entirely in a single script (main.py), with no frontend/backend split, no external services, and no persistent database. Its purpose is to read user input, compute results (basic and advanced arithmetic), maintain in-session history and memory, then print output.

##### File structure
- Top‐level files:
- .gitignore, LICENSE, README.md – metadata
- main.py – the entire application
- No subdirectories or modules; all logic is in main.py.
- This implies a monolithic, in-process architecture.

##### README for additional insights
- Features list reveals five logical capabilities:
- Basic arithmetic
- Advanced operations (exponent, modulus, sqrt)
- Memory storage (last result)
- Calculation history (session log)
- Continuous operation (loop)
- No external dependencies or services are described beyond Python’s standard library.

a. Main Components
1. CLI Interface (Input/Output)
2. Input Handler (reads/parses user commands)
3. Expression Parser (validates and tokenizes input)
4. Calculation Engine (performs arithmetic, advanced ops via math module)
5. Memory Store (holds last result for “M+”/“MR” operations)
6. History Manager (appends each calculation and result to session log)

b. Relationships & Interactions
- User types expression → CLI Interface
- CLI Interface forwards raw text → Input Handler
- Input Handler calls Expression Parser → produces AST or tokens
- Parser passes tokens → Calculation Engine → returns numeric result
- Calculation Engine updates Memory Store (if requested)
- Calculation Engine notifies History Manager to log expression+result
- CLI Interface retrieves result (and optional memory/history output) → prints to screen
- Loop back to CLI Interface for next input

c. Architectural Patterns/Design Principles
- Monolithic, single-process design
- Clear separation of concerns (parsing vs. computing vs. state management)
- Stateless engine logic with small mutable stores (memory/history)
- Synchronous, sequential flow in a REPL-style loop

d. Technologies/Frameworks
- Python 3.x runtime
- Standard library (math module for sqrt, exponent, modulus)
- No external services or frameworks

##### Detail without over-splitting
- This will make future refactoring (into modules/packages) or the addition of features (e.g., persistent history, GUI frontend) easier to overlay on the same architecture.

## Diagram (Mermaid)

```mermaid
flowchart TB
    User["User"]:::external
    CLI["CLI Interface"]:::io
    InputHandler["Input Handler"]:::process
    Parser["Expression Parser"]:::process
    Engine["Calculation Engine"]:::process
    MemoryStore["Memory Store"]:::state
    HistoryManager["History Manager"]:::state

    User -->|types expression| CLI
    CLI -->|forwards raw input| InputHandler
    InputHandler -->|parses commands| Parser
    Parser -->|tokens/AST| Engine
    Engine -->|returns result| CLI
    Engine -->|updates memory| MemoryStore
    Engine -.->|logs history| HistoryManager
    MemoryStore -->|retrieves memory| Engine
    CLI -->|"next input (REPL)"| CLI

    click CLI "https://github.com/danielrajchristeen/py-calculator/blob/main/main.py"
    click InputHandler "https://github.com/danielrajchristeen/py-calculator/blob/main/main.py"
    click Parser "https://github.com/danielrajchristeen/py-calculator/blob/main/main.py"
    click Engine "https://github.com/danielrajchristeen/py-calculator/blob/main/main.py"
    click MemoryStore "https://github.com/danielrajchristeen/py-calculator/blob/main/main.py"
    click HistoryManager "https://github.com/danielrajchristeen/py-calculator/blob/main/main.py"

    classDef io fill:#D0E6FF,stroke:#007ACC,stroke-width:2px
    classDef process fill:#E6FFEA,stroke:#039E0D,stroke-width:2px
    classDef state fill:#FFF7D6,stroke:#D4A200,stroke-width:2px
    classDef external fill:#F0F0F0,stroke:#888888,stroke-width:1px,stroke-dasharray: 2 2
```
