# bananaapache/itv architecture

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

- Interactive diagram: https://gitdiagram.com/bananaapache/itv
- Repository: https://github.com/bananaapache/itv

## Overview

##### Project type and purpose
- ITV is a **converter/visualization tool** that reads derivation files (TPTP‐style `.s` input), classifies and augments each formula (tcf, fof, thf; adds name, role, inference info, level, parents), emits an output derivation file, and produces a GraphViz‐based layout via a small web UI.
- Key indicators:
- `converter.py` (Python CLI that drives the conversion)
- GraphViz mention in README
- A static web bundle (`BuildBundleWithNode/…`) + `ITV.html`

##### File structure
Top‐level:
- converter.py, run_IDV, *.s input/output files
- ITV.html — the web front end
- BuildBundleWithNode/ — a Node + Webpack project producing static assets:
– `static/js/*.js` (ANTLR4‐generated TPTP parser + helpers)
– `static/css` (styling for the UI)
– `webpack.config.js` + `package.json`

##### README for additional insights
- Conversion requirements: classify formulas, augment them with metadata.
- Use GraphViz to “show correct orientation” with nextTo(...).

##### Main components & interactions
a. Components:
1. **File I/O** (Python layer)
2. **Parser & Classifier** (inside converter.py; may use ANTLR grammar in Python or delegate parsing to JS)
3. **Data Model** (intermediate representation: name, role, formula, inference_rule, level, parents)
4. **Serializer** (writes `new_output.s` or `output.s`)
5. **GraphViz Dot Generator** (emits `.dot` file or invokes `dot` command)
6. **Static Web UI** (ITV.html + bundled JS/CSS from BuildBundleWithNode)
7. **Bundler** (Node + Webpack compiles ANTLR4 JS, helpers into bundle.js)
8. **Graph Rendering** (GraphViz in browser or server‐side)

b. Relationships & Data Flow:
- User invokes `converter.py` with `input.s` → Python reads and parses.
- Converter builds in‐memory data model → classifies each formula.
- Converter outputs an annotated `.s` file and either:
- Generates a GraphViz dot file → runs `dot` → produces PNG/SVG
- OR passes dot string to the web UI.
- The web UI (`ITV.html`) loads `bundle.js` (built by Webpack) → parses dot / JSON → renders interactive graph.

c. Architectural patterns / design principles:
- **Separation of Concerns**: CLI conversion vs. UI rendering.
- **Modularity**: Python modules vs. JS modules (ANTLR4, helpers).
- **External Tool Integration**: GraphViz.

d. Key technologies:
- Python (converter.py)
- ANTLR4 (grammar → generates TPTPParser.js / Listener, used in browser)
- Node + Webpack (bundles JS/CSS)
- GraphViz (`dot`)
- HTML/CSS/JS front end

##### Detail vs. simplicity
- Every essential architectural element (parser, classifier, serializer, visualizer) is represented.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and CLI
    User["User"]:::external
    User -->|CLI Invocation| run_IDV["run_IDV"]:::backend
    User -->|CLI Invocation| Converter["Python Converter"]:::backend

    %% Python Converter Pipeline
    subgraph "Backend (Python)" 
        direction TB
        Converter -->|reads .s files| Inputs["Input (.s files)"]:::backend
        Converter -->|classify & annotate| DataModel["Data Model"]:::backend
        DataModel -->|serialize| OutputFiles["output.s / new_output.s"]:::backend
        Converter -->|emit .dot file| DotFile[".dot file"]:::external
        Converter -->|pass dot/JSON| UI["Static Web UI"]:::frontend
    end

    %% GraphViz External Tool
    DotFile -->|dot CLI| GraphViz["GraphViz (dot)"]:::external
    GraphViz -->|SVG/PNG| SVG["SVG / PNG"]:::external

    %% Bundler and Static Assets
    subgraph "Build (Node + Webpack)"
        direction TB
        Bundler["Bundler (Webpack)"]:::build
        Bundler -->|builds| BundleJS["bundle.js"]:::frontend
        Bundler -->|uses| ANTLR4["antlr4.js"]:::build
        Bundler -->|uses| TPTPLexer["TPTPLexer.js"]:::build
        Bundler -->|uses| TPTPParser["TPTPParser.js"]:::build
        Bundler -->|uses| TPTPListener["TPTPListener.js"]:::build
        Bundler -->|uses| Helpers["helpers.js"]:::build
        Bundler -->|uses| ParserJS["parser.js"]:::build
        Bundler -->|uses| StyleCSS["style.css"]:::build
        Bundler -->|uses| DotsCSS["three-dots.css"]:::build
        Bundler -->|config| WPConfig["webpack.config.js"]:::build
        Bundler -->|config| PackageJSON["package.json"]:::build
        Bundler -->|config| PackageLock["package-lock.json"]:::build
    end

    %% Static Web UI
    subgraph "Frontend (Static UI)"
        direction TB
        ITV["ITV.html"]:::frontend
        ITV -->|loads| BundleJS
        ITV -->|renders graph| SVG
    end

    %% Data flow to UI
    DotFile -->|dot/JSON| ITV

    %% Click Events
    click Converter "https://github.com/bananaapache/itv/blob/main/converter.py"
    click Inputs "https://github.com/bananaapache/itv/blob/main/derivation_input.s"
    click Inputs "https://github.com/bananaapache/itv/blob/main/input.s"
    click OutputFiles "https://github.com/bananaapache/itv/blob/main/new_output.s"
    click OutputFiles "https://github.com/bananaapache/itv/blob/main/output.s"
    click run_IDV "https://github.com/bananaapache/itv/tree/main/run_IDV"
    click Bundler "https://github.com/bananaapache/itv/tree/main/BuildBundleWithNode/"
    click WPConfig "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/webpack.config.js"
    click PackageJSON "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/package.json"
    click PackageLock "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/package-lock.json"
    click StyleCSS "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/static/css/style.css"
    click DotsCSS "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/static/css/three-dots.css"
    click ANTLR4 "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/static/js/antlr4.js"
    click TPTPLexer "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/static/js/TPTPLexer.js"
    click TPTPParser "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/static/js/TPTPParser.js"
    click TPTPListener "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/static/js/TPTPListener.js"
    click Helpers "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/static/js/helpers.js"
    click ParserJS "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/static/js/parser.js"
    click BundleJS "https://github.com/bananaapache/itv/blob/main/BuildBundleWithNode/static/js/bundle.js"
    click ITV "https://github.com/bananaapache/itv/blob/main/ITV.html"
    click tmp "https://github.com/bananaapache/itv/blob/main/tmp.py"

    %% Styles
    classDef backend fill:#E3F2FD,stroke:#0288D1,stroke-width:1px
    classDef frontend fill:#E8F5E9,stroke:#388E3C,stroke-width:1px
    classDef build fill:#FFF3E0,stroke:#F57C00,stroke-width:1px
    classDef external fill:#FFEBEE,stroke:#C62828,stroke-width:1px
```
