# fer-hnndz/cpp-expression-evaluator architecture

> Architecture diagram of the GitHub repository fer-hnndz/cpp-expression-evaluator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fer-hnndz/cpp-expression-evaluator
- Repository: https://github.com/fer-hnndz/cpp-expression-evaluator

## Overview

##### Main Components
- CLI/Entry Point: Represented by the src/main.cpp, this is where the program starts. It handles input parsing (command-line arguments) and invokes the expression evaluation workflow.
- Tokenizer/Parser: The tokenParser module (declared in include/tokenParser.h and implemented as needed in the project via the evaluator) breaks down the input expression into tokens.
- Evaluator: This module (src/evaluator.cpp / include/evaluator.h) processes the tokens (typically converting them to postfix notation for evaluation, as hinted by the debug flag) and applies the operations.
- Operators: Defined in include/operators.h and implemented in src/operators.cpp, this module contains the definitions of the supported mathematical operations (addition, subtraction, multiplication, division, modulus, exponentiation, and the handling of parentheses).
- Configuration Parser: The config parser (include/configparser.h and src/configparser.cpp) handles any project-specific settings or input configurations, though in this educational project its role might be more limited.
- Testing component: The tests (tests/tests.cpp) verify that the expression evaluator behaves correctly under various scenarios. It is also a key part of the system’s architecture for ensuring quality.

##### Relationships and Interactions
- The CLI (main.cpp) is the entry point that receives an expression (and optionally a debug flag) from the command-line.
- The CLI forwards the expression to the Tokenizer/Parser component, which transforms the raw input into manageable tokens.
- The Evaluator component then takes these tokens and, using the rules defined by the Operators module, computes the result.
- The testing module interacts with all these components to verify correctness (perhaps by simulating requests that pass through the main components).

##### Architectural Patterns and Design Principles
- Modular design: Each component (token parsing, evaluation, operator handling, configuration parsing) is separated into its own module. This separation of concerns is a key part of the project’s architecture.
- Clear functional responsibilities: The system is structured to isolate the various stages of expression evaluation (tokenization, parsing, evaluation) which could loosely correspond to an interpreter pattern.
- Simple input/output patterns: The main function acts as an orchestrator, indicating a layered architecture in the context of a typical CLI utility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    cli["CLI/Entry Point"]  
    tokenizer["Tokenizer/Parser"]
    evaluator["Evaluator Engine"]
    operators["Operators Module"]
    config["Configuration Parser"]
    tests["Testing Framework"]

    cli -->|"ExpressionInput"| tokenizer
    tokenizer -->|"TokenStream"| evaluator
    evaluator -->|"OperationLookup"| operators
    evaluator -->|"UsesConfig"| config

    tests -->|"Validates"| cli
    tests -->|"Validates"| tokenizer
    tests -->|"Validates"| evaluator
    tests -->|"Validates"| operators
    tests -->|"Validates"| config

    click cli "https://github.com/fer-hnndz/cpp-expression-evaluator/blob/master/src/main.cpp"
    click tokenizer "https://github.com/fer-hnndz/cpp-expression-evaluator/blob/master/include/tokenParser.h"
    click evaluator "https://github.com/fer-hnndz/cpp-expression-evaluator/blob/master/include/evaluator.h"
    click evaluator "https://github.com/fer-hnndz/cpp-expression-evaluator/blob/master/src/evaluator.cpp"
    click operators "https://github.com/fer-hnndz/cpp-expression-evaluator/blob/master/include/operators.h"
    click operators "https://github.com/fer-hnndz/cpp-expression-evaluator/blob/master/src/operators.cpp"
    click config "https://github.com/fer-hnndz/cpp-expression-evaluator/blob/master/include/configparser.h"
    click config "https://github.com/fer-hnndz/cpp-expression-evaluator/blob/master/src/configparser.cpp"
    click tests "https://github.com/fer-hnndz/cpp-expression-evaluator/blob/master/tests/tests.cpp"

    classDef entry fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef core fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef test fill:#ccffff,stroke:#333,stroke-width:2px;
    
    class cli entry;
    class tokenizer,evaluator,operators,config core;
    class tests test;
```
