# shajeen/spreadsheet-to-cpplib architecture

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

- Interactive diagram: https://gitdiagram.com/shajeen/spreadsheet-to-cpplib
- Repository: https://github.com/shajeen/spreadsheet-to-cpplib

## Overview

##### Project Type & Purpose
- It’s a command‐line Python application (CLI tool) that reads spreadsheet files (CSV or Excel) and outputs a self‐contained C++ library (with CMake build scripts).
- It optionally embeds the ExprTk header‐only math library for formula evaluation.

##### File Structure
- Top‐level:
- setup.py, pyproject.toml → Python packaging & CLI entry point
- README.md, LICENSE, CONTRIBUTING, .github/ → project governance
- example/, sample/ → usage demos
- spreadsheet_to_cpplib/ → core implementation
- Inside spreadsheet_to_cpplib/:
- main.py / run.py / clitest.py → CLI argument parsing & user prompts
- parse.py, csvToCpp.py → spreadsheet reading & conversion to an internal representation (IR)
- template_*.py → code‐generation templates (CMake, header‐only, math support, source files)
- fileOperations.py → file system abstraction (create output dirs, write files)
- lib/exprtk.hpp → bundled third‐party header library

##### README for Insights
- The tool “promotes questions” and then “generates files in output,” so there is a user‐interaction step via CLI.
- Outputs: CMakeLists.txt, .h/.cpp files, optionally header‐only or full library.

##### Draft the Main Components
a. User & CLI Layer
– User invokes `spreadsheet-to-cpplib --file=…`
– clitest.py + main.py parse arguments and call run.py
b. Orchestrator / Controller (run.py)
– Hosts the Q&A flow, determines user options (header‐only, math support, etc.)
c. Parser / Converter
– parse.py (for Excel)
– csvToCpp.py (for CSV)
→ Both output a uniform IR (cells, formulas, types).
d. Template Engine
– template_cmake.py → Generates CMakeLists.txt
– template_headeronly.py → Emits .h files if header‐only
– template_source.py → Emits .cpp + .h for non‐header‐only
– template_math.py → Injects ExprTk-dependent code if math support selected
– asciitext.py → (optional) produces ASCII table documentation in code
e. File System Writer (fileOperations.py)
– Creates output folder structure
– Copies exprtk.hpp into the output `lib/` folder when needed
– Writes all generated code & CMake files
f. External / Third-Party
– Python stdlib csv, openpyxl (implicitly used by parse.py)
– ExprTk C++ header (bundled in lib/)

##### Relationships & Data Flow
User → CLI Parsing → Orchestrator
Orchestrator → (based on file extension) → Parser or CSV Converter → IR
IR → Template Engine (multiple modules) → Generated code artifacts
Generated artifacts + exprtk.hpp → FileOperations → Output directory

##### Architectural Patterns & Design Principles
- Separation of concerns: parsing vs templating vs I/O
- Strategy pattern: each template_*.py is a strategy for a code‐generation variant
- Modularity: each major function lives in its own module

##### Technologies & Frameworks
- Python 3 CLI (setup.py / pyproject.toml)
- CMake for generated C++ library
- ExprTk header‐only library for math formulas
- CSV / Excel reading via Python libraries

## Diagram (Mermaid)

```mermaid
flowchart TB
    User["User"]:::external

    subgraph "CLI Layer"
        clitest["clitest.py"]:::python
        main["main.py"]:::python
    end

    run["run.py (Orchestrator)"]:::python

    subgraph "Parser / IR Generator"
        parse["parse.py (Excel Parser)"]:::python
        csv["csvToCpp.py (CSV Converter)"]:::python
        IR["Internal Representation"]:::ir
    end

    subgraph "Template Engine"
        tm_cmake["template_cmake.py"]:::python
        tm_header["template_headeronly.py"]:::python
        tm_source["template_source.py"]:::python
        tm_math["template_math.py"]:::python
        asciitext["asciitext.py"]:::python
    end

    fileops["fileOperations.py"]:::python
    exprtk["exprtk.hpp"]:::external
    output["Generated C++ Library + CMake"]:::cpp

    User --> clitest
    User --> main
    clitest --> run
    main --> run
    run --> parse
    run --> csv
    parse --> IR
    csv --> IR
    IR --> tm_cmake
    IR --> tm_header
    IR --> tm_source
    IR --> tm_math
    IR --> asciitext
    tm_math --> exprtk
    tm_cmake --> fileops
    tm_header --> fileops
    tm_source --> fileops
    tm_math --> fileops
    asciitext --> fileops
    exprtk --> fileops
    fileops --> output

    click clitest "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/clitest.py"
    click main "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/main.py"
    click run "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/run.py"
    click parse "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/parse.py"
    click csv "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/csvToCpp.py"
    click tm_cmake "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/template_cmake.py"
    click tm_header "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/template_headeronly.py"
    click tm_math "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/template_math.py"
    click tm_source "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/template_source.py"
    click asciitext "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/asciitext.py"
    click fileops "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/fileOperations.py"
    click exprtk "https://github.com/shajeen/spreadsheet-to-cpplib/blob/main/spreadsheet_to_cpplib/lib/exprtk.hpp"

    classDef python fill:#2196f3,stroke:#1e88e5,color:#fff
    classDef ir fill:#ffeb3b,stroke:#fdd835,color:#000
    classDef cpp fill:#8bc34a,stroke:#7cb342,color:#000
    classDef external fill:#f44336,stroke:#e53935,color:#fff
```
