# kornysietsma/polyglot-code-scanner architecture

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

- Interactive diagram: https://gitdiagram.com/kornysietsma/polyglot-code-scanner
- Repository: https://github.com/kornysietsma/polyglot-code-scanner

## Overview

##### Project Type and Purpose
- This is a stand-alone, command-line application written in Rust.
- It scans a source-code directory (and optional Git history) to compute code metrics and emits a JSON report for downstream visualization in the Polyglot Code Explorer.

##### High-Level Components
Based on your file tree and README, the main components are:
a. Input Sources
- File system (source code files, `.polyglot_code_scanner_ignore`, `.gitignore`)
- Git repositories (optional, controlled by `--no-git` / `--years` flags)
b. CLI & Configuration
- `main.rs` – argument parsing, entry point
- Global config (.gitignore logic, custom ignore files, flags)
c. Core Library (in `src/lib.rs` + submodules)
- FileWalker (`file_walker.rs`): enumerates files, applies ignore rules
- FileStats (`file_stats.rs`), CodeLineData (`code_line_data.rs`), LOC (`loc.rs`), Indentation (`indentation.rs`): per-file metrics
- Coupling (`coupling.rs`) and Toxicity (`toxicity_indicator_calculator.rs`): cross-file and indicator analysis
- Git integration (`git.rs`, `git_file_history.rs`, etc.): harvests commit data, renames, merges
- Flare exporter (`flare.rs` / `postprocessing.rs`): transforms raw metrics into the “flare” JSON format
d. Output
- JSON file (or stdout) conforming to the Explorer’s schema
e. Testing & CI
- `test_shared` crate + `tests/` folder: unit + integration tests with sample data
- GitHub Actions workflows (.github/workflows/*.yml): cross-platform build, test, release

##### Architectural Patterns & Principles
- Layered Architecture:
- Presentation/CLI layer (main.rs)
- Application Core (modular library for scanning, parsing, metrics)
- Infrastructure: file system, Git CLI or library, JSON writer
- Single-binary deployment: all modules are compiled into one Rust executable
- Configuration by convention: reuse `.gitignore` parsing logic, add custom ignore files

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Inputs"
        fs["Local File System"]:::input
        git["Git Repository"]:::input
    end

    subgraph "CLI & Configuration"
        main["main.rs"]:::processing
    end

    subgraph "Core Library"
        lib["lib.rs"]:::processing
        fw["FileWalker\n(file_walker.rs)"]:::processing
        fsmod["FileStats\n(file_stats.rs)"]:::processing
        cld["CodeLineData\n(code_line_data.rs)"]:::processing
        loc["LOC Calculator\n(loc.rs)"]:::processing
        ind["Indentation Analyzer\n(indentation.rs)"]:::processing
        coup["Coupling Calculator\n(coupling.rs)"]:::processing
        tox["Toxicity Indicator Calculator\n(toxicity_indicator_calculator.rs)"]:::processing
        gitcore["Git Integration Core\n(git.rs)"]:::processing
        gfh["Git File History\n(git_file_history.rs)"]:::processing
        gff["Git File Future\n(git_file_future.rs)"]:::processing
        glog["Git Logger\n(git_logger.rs)"]:::processing
        gdict["Git User Dictionary\n(git_user_dictionary.rs)"]:::processing
        model["Polyglot Data Models\n(polyglot_data.rs)"]:::processing
    end

    subgraph "Postprocessing"
        flare["Flare Exporter\n(flare.rs)"]:::processing
        post["Postprocessing\n(postprocessing.rs)"]:::processing
    end

    subgraph "Outputs"
        json["JSON Report\n(.json)"]:::output
        explorer["Polyglot Code Explorer"]:::external
    end

    subgraph "Testing & CI"
        harness["Test Harness\n(test_shared/)"]:::grey
        tests["Tests\n(tests/ & tests/integration_tests.rs)"]:::grey
        ci["CI Workflows\n(.github/workflows/)"]:::grey
    end

    fs --> fw
    git --> gitcore
    main --> lib
    lib --> fw
    fw --> fsmod
    fw --> cld
    fw --> loc
    fw --> ind
    fw --> coup
    fw --> tox
    gitcore --> gfh
    gitcore --> gff
    gitcore --> glog
    gitcore --> gdict
    fsmod --> flare
    cld --> flare
    loc --> flare
    ind --> flare
    coup --> flare
    tox --> flare
    model --> flare
    flare --> post
    post --> json
    json --> explorer
    harness --> lib
    tests --> fw
    ci --> main

    click main "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/main.rs"
    click lib "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/lib.rs"
    click fw "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/file_walker.rs"
    click fsmod "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/file_stats.rs"
    click cld "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/code_line_data.rs"
    click loc "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/loc.rs"
    click ind "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/indentation.rs"
    click coup "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/coupling.rs"
    click tox "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/toxicity_indicator_calculator.rs"
    click gitcore "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/git.rs"
    click gfh "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/git_file_history.rs"
    click gff "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/git_file_future.rs"
    click glog "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/git_logger.rs"
    click gdict "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/git_user_dictionary.rs"
    click model "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/polyglot_data.rs"
    click flare "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/flare.rs"
    click post "https://github.com/kornysietsma/polyglot-code-scanner/blob/master/src/postprocessing.rs"
    click harness "https://github.com/kornysietsma/polyglot-code-scanner/tree/master/test_shared/"
    click tests "https://github.com/kornysietsma/polyglot-code-scanner/tree/master/tests/"
    click ci "https://github.com/kornysietsma/polyglot-code-scanner/tree/master/.github/workflows/"

    classDef input fill:#CCF,stroke:#333;
    classDef processing fill:#CFC,stroke:#333;
    classDef output fill:#FCC,stroke:#333,shape:cylinder;
    classDef external fill:#EEC,stroke:#333;
    classDef grey fill:#EEE,stroke:#333;
```
