# praveenkumar76/hashtrace architecture

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

- Interactive diagram: https://gitdiagram.com/praveenkumar76/hashtrace
- Repository: https://github.com/praveenkumar76/hashtrace

## Overview

##### Project Type & Purpose
- This is a desktop full-stack application.
- Frontend: Qt Quick (QML files: Main.qml, FileCard.qml).
- Backend: C++ modules (Preprocessor, Rabin-Karp, FileReader, Backend class).

##### File Structure & Components
Top-level source files (ignore the `build/` folder):
- main.cpp: entry point, sets up QML engine and exposes C++ backend.
- FileCard.qml & Main.qml: UI components for file list, comparison view.
- filereader.cpp/.h: reads raw text from files.
- Preprocessor.cpp/.h: strips comments, blank lines, reserved keywords.
- Rabin_karp.cpp/.h: implements rolling-hash fingerprinting.
- backend.cpp/.h: QObject subclass with Q_INVOKABLE methods coordinating the pipeline.

##### README Insights
- Workflow: Preprocessing → Hashing → Comparison → Visualization.
- Tech stack: Qt6/QML (UI), C++17 (logic), CMake (build), Rabin-Karp algorithm.

##### Main Components & Interactions
a. Components
- UI Layer (QML)
- Backend Controller (QObject in backend.cpp)
- File I/O (FileReader)
- Preprocessor Module
- Hashing Module (Rabin-Karp)
- Comparison Engine (takes two hash streams, computes matches & similarity score)
- Data Model & Results (structures holding matched segments & scores)
- File System (external service)

b. Relationships & Data Flow
1. User drags files into QML UI → emits QML signal.
2. QML signal invokes C++ Backend API (Q_INVOKABLE).
3. Backend calls FileReader → returns raw text.
4. Backend passes text to Preprocessor → returns cleaned text.
5. Backend passes cleaned text to Rabin-Karp → returns hash sequences.
6. Backend Comparison Engine compares hash sequences → builds match data + similarity %.
7. Backend emits Qt signal / returns result to QML.
8. QML UI binds to result model → renders highlighted blocks side-by-side.

c. Architectural Patterns
- MVC/MVVM flavor: QML = View, C++ backend = Model/Controller.
- Pipeline pattern: sequential modules (Preprocessor → Hash → Compare).
- Signal-Slot / Q_INVOKABLE for async interactions between UI and backend.

d. Key Technologies
- Qt Quick (QML), Qt C++ (QtCore, QtQml)
- C++17 standard library
- CMake build definitions
- Rabin-Karp Rolling Hash algorithm

##### Putting It All Together
[Tier 1: QML UI] ←→ [Tier 2: C++ Backend Pipeline] ←→ [Tier 3: File System]
- Inside Tier 2, horizontally chain: FileReader → Preprocessor → RabinKarp → ComparisonEngine → ResultModel.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        Main["Main.qml"]:::ui
        FileCard["FileCard.qml"]:::ui
    end

    %% Backend Pipeline
    subgraph "Backend Pipeline"
        BackendController["BackendController\n(backend.cpp/.h)"]:::core
        FileReader["FileReader\n(filereader.cpp/.h)"]:::core
        Preprocessor["Preprocessor\n(Preprocessor.cpp/.h)"]:::algo
        RabinKarp["RabinKarp\n(Rabin_karp.cpp/.h)"]:::algo
        ComparisonEngine["ComparisonEngine"]:::core
        ResultModel["ResultModel"]:::core
    end

    %% Entry Point & Resources
    main["main.cpp"]:::core
    Resources["Resources\n(icons/, QML assets)"]:::ext

    %% External Systems & Documentation
    FileSystem["File System"]:::ext
    README["README.md"]:::doc
    CMake1["CMakeLists.txt"]:::doc
    CMake2["CMakeLists.txt.user"]:::doc

    %% Data Flow
    main -->|"initialize QML engine"| Main
    main -->|"expose Backend API"| BackendController

    Main -->|"signal/Q_INVOKABLE"| BackendController
    BackendController -->|"readFile()"| FileReader
    FileReader -->|reads from| FileSystem
    FileReader -->|"raw text"| Preprocessor
    Preprocessor -->|"cleaned text"| RabinKarp
    RabinKarp -->|"hash list"| ComparisonEngine
    ComparisonEngine -->|"match data & score"| ResultModel
    ResultModel -->|"update model (Qt signal)"| Main

    %% UI Resources
    Main --> Resources
    FileCard --> Resources

    %% Click Events
    click Main "https://github.com/praveenkumar76/hashtrace/blob/main/Main.qml"
    click FileCard "https://github.com/praveenkumar76/hashtrace/blob/main/FileCard.qml"
    click BackendController "https://github.com/praveenkumar76/hashtrace/blob/main/backend.cpp"
    click BackendController "https://github.com/praveenkumar76/hashtrace/blob/main/backend.h"
    click FileReader "https://github.com/praveenkumar76/hashtrace/blob/main/filereader.cpp"
    click FileReader "https://github.com/praveenkumar76/hashtrace/blob/main/filereader.h"
    click Preprocessor "https://github.com/praveenkumar76/hashtrace/blob/main/Preprocessor.cpp"
    click Preprocessor "https://github.com/praveenkumar76/hashtrace/blob/main/Preprocessor.h"
    click RabinKarp "https://github.com/praveenkumar76/hashtrace/blob/main/Rabin_karp.cpp"
    click RabinKarp "https://github.com/praveenkumar76/hashtrace/blob/main/Rabin_karp.h"
    click main "https://github.com/praveenkumar76/hashtrace/blob/main/main.cpp"
    click Resources "https://github.com/praveenkumar76/hashtrace/tree/main/icons/"
    click README "https://github.com/praveenkumar76/hashtrace/blob/main/README.md"
    click CMake1 "https://github.com/praveenkumar76/hashtrace/blob/main/CMakeLists.txt"
    click CMake2 "https://github.com/praveenkumar76/hashtrace/blob/main/CMakeLists.txt.user"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#2E86C1;
    classDef core fill:#ABEBC6,stroke:#239B56;
    classDef algo fill:#F9E79F,stroke:#B7950B;
    classDef ext fill:#D5DBDB,stroke:#566573;
    classDef doc fill:#F5CBA7,stroke:#D35400;
```
