# lusehair/computorv1 architecture

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

- Interactive diagram: https://gitdiagram.com/lusehair/computorv1
- Repository: https://github.com/lusehair/computorv1

## Overview

##### Main Components
- Input Module: This starts by receiving the equation (from command-line input) and sends it to the parser.
- Polynomial Parser: Reads the raw input and breaks it into its constituent parts (terms, coefficients, operators, and degrees).
- Canonical Form Builder: Reorganizes and simplifies the input equation into its standard canonical form (ax² + bx + c = 0).
- Degree Evaluator & Solver:
- Degree 0 Handler: Checks for trivial validity (e.g., 3 = 3) or inconsistency.
- Degree 1 Solver: Implements the linear formula.
- Degree 2 Solver: Calculates the discriminant and applies the quadratic formula, with branches to handle:
- Positive discriminant (two real roots)
- Zero discriminant (one repeated root)
- Negative discriminant (two complex roots)
- Error Handling Component: Captures and reports syntax errors and unsupported degree cases.
- Test Suite: Located in test.py, this component orchestrates various tests against all scenarios (subject, correction, additional).

##### Relationships and Data Flow
- The input is fed into the Polynomial Parser.
- Parsed data is sent to the Canonical Form Builder.
- Once in its canonical form, the data flows to the Degree Evaluator, which selects the appropriate solver based on the degree.
- Solvers perform the computation and return the result.
- Any exceptions or invalid input are captured by the Error Handling component.
- Additionally, a separate testing flow leverages the Test Suite (test.py) to exercise all of the above components.

##### Architectural Patterns and Principles
- Separation of Concerns: Each module has a clearly defined responsibility (parsing, simplifying, solving, and testing).
- Decision Branching: The Degree Evaluator uses conditional logic to divert to different solution methods based on the polynomial’s degree.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User Input (Input Reader)"]:::input
    B["Polynomial Parser"]:::process
    C["Canonical Form Builder"]:::process
    D["Degree Evaluator"]:::decision
    E["Degree 0 Handler"]:::process
    F["Degree 1 Solver"]:::process
    G["Degree 2 Solver"]:::process
    subgraph "Quadratic Discriminant Logic"
        G1["Positive Discriminant"]:::process
        G2["Zero Discriminant"]:::process
        G3["Negative Discriminant"]:::process
    end
    I["Result Output"]:::output
    J["Error Handler"]:::error
    K["Test Suite"]:::test

    %% Main Data Flow
    A -->|"input"| B
    B -->|"parsed"| C
    C -->|"canonicalForm"| D

    %% Branching based on polynomial degree
    D -->|"degree=0"| E
    D -->|"degree=1"| F
    D -->|"degree=2"| G

    %% Connect solvers to result
    E -->|"result"| I
    F -->|"result"| I
    G -->|"branch"| G1
    G -->|"branch"| G2
    G -->|"branch"| G3
    G1 -->|"result"| I
    G2 -->|"result"| I
    G3 -->|"result"| I

    %% Error flows from key components
    B -->|"error"| J
    C -->|"error"| J
    D -->|"error"| J

    %% Test suite simulates input into the system
    K -->|"simulate"| A

    %% Click Events
    click A "https://github.com/lusehair/computorv1/blob/main/computorv1.py"
    click B "https://github.com/lusehair/computorv1/blob/main/computorv1.py"
    click C "https://github.com/lusehair/computorv1/blob/main/computorv1.py"
    click D "https://github.com/lusehair/computorv1/blob/main/computorv1.py"
    click E "https://github.com/lusehair/computorv1/blob/main/computorv1.py"
    click F "https://github.com/lusehair/computorv1/blob/main/computorv1.py"
    click G "https://github.com/lusehair/computorv1/blob/main/computorv1.py"
    click J "https://github.com/lusehair/computorv1/blob/main/computorv1.py"
    click K "https://github.com/lusehair/computorv1/blob/main/test.py"

    %% Styling
    classDef input fill:#cce5ff,stroke:#1f78b4,stroke-width:2px;
    classDef process fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef decision fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef error fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef test fill:#ffeeba,stroke:#fd7e14,stroke-width:2px;
    classDef output fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
