# raunak0400/similarity-checking-from-books architecture

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

- Interactive diagram: https://gitdiagram.com/raunak0400/similarity-checking-from-books
- Repository: https://github.com/raunak0400/similarity-checking-from-books

## Overview

##### Project Type and Purpose
- This is a specialized full-text analysis project focused on comparing literary works.
- Its functions include text preprocessing, frequency analysis, and calculation of similarity scores between books.
- The README confirms that the core operations revolve around a custom Book class, advanced text preprocessing, and comparison algorithms implemented in C++.

##### File Structure
- The top-level README file outlines the project’s features, technical implementation, and output.
- The “similarity checking from books” folder contains all the raw text files and even includes the main.cpp and an executable (a.exe) indicating the project’s entry point.
- The “outputFiles” folder holds the results (common_words.txt, similarity_matrix.txt, similar_Books.txt). This separation between inputs and outputs is critical in the architecture.
- The presence of the “main.cpp” suggests a central control module where the workflow is orchestrated—including reading files, instantiating Book objects, running text preprocessing, and performing comparisons.

##### Main Components
a. Input Layer:
- Data Source: Raw text files (all the book texts) stored in “similarity checking from books.”
- File I/O Modules: Components responsible for reading text files.
b. Processing Layer:
- Text Preprocessing Pipeline: A module that sanitizes and prepares the raw text (e.g., removing punctuations, tokenizing words).
- Book Class/Representation: The custom class that encapsulates the content of each book and its associated metadata.
c. Analysis Engine:
- Word Frequency Analysis: Module responsible for identifying the top 100 most influential words across all texts.
- Similarity Calculation Algorithms: Module that computes a 64x64 similarity matrix by comparing each pair of books. This module should detail how comparisons are done and include any statistical methods if applicable.
d. Output Layer:
- Result Generation: Modules that write outputs to “outputFiles,” including the similarity matrix, top word list (common_words.txt) and the top similar book pairs (similar_Books.txt).
e. Control Flow / Orchestration:
- Main Controller (main.cpp): This component coordinates the overall processing flow from input through analysis to output generation.
- Optional Logging / Exception Handling: Given that the project emphasizes stability with a single-threaded approach, include a note about consistent error handling and logging.

##### Relationships and Interactions
- That once the raw book text is cleaned, data is encapsulated into Book objects.
- The Book objects are then processed by the Analysis Engine, which produces both global word frequency statistics and a pair-wise similarity matrix.
- A central control block (main.cpp) that manages these interactions.

##### Key Architectural Patterns and Design Principles
- Separation of Concerns: Each layer (I/O, preprocessing, analysis, output) is distinct, ensuring high modularity.
- Pipeline Architecture: The sequential flow from raw data to processed output is clearly defined.
- Encapsulation: Use of a custom Book class indicates that each book’s data and its processing can be neatly encapsulated for reusability and maintainability.
- Single-Threaded Operation: Emphasize in the design notes that while this simplifies the design, it comes with performance trade-offs.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Input Layer
    subgraph "Input Layer"
        A["Raw Book Files"]:::input
        B["File I/O Module"]:::input
    end

    %% Processing Layer
    subgraph "Processing Layer"
        C["Text Preprocessing Pipeline"]:::processing
        D["Book Class Representation"]:::processing
    end

    %% Analysis Engine
    subgraph "Analysis Engine"
        E["Word Frequency Analysis"]:::analysis
        F["Similarity Calculation Algorithms"]:::analysis
    end

    %% Output Layer
    subgraph "Output Layer"
        G["Results Output"]:::output
    end

    %% Control Flow
    H["Main Controller"]:::control

    %% Data Flow Connections
    A -->|"reads"| B
    B -->|"preprocesses"| C
    C -->|"creates"| D
    D -->|"analyzes"| E
    D -->|"compares"| F
    E -->|"generates"| G
    F -->|"generates"| G

    %% Control Flow Orchestration
    H -->|"initiates"| B
    H -->|"triggers"| C
    H -->|"executes"| E
    H -->|"executes"| F
    H -->|"finalizes"| G

    %% Click Events
    click A "https://github.com/raunak0400/similarity-checking-from-books/tree/main/similarity checking from books"
    click B "https://github.com/raunak0400/similarity-checking-from-books/blob/main/similarity checking from books/main.cpp"
    click C "https://github.com/raunak0400/similarity-checking-from-books/blob/main/similarity checking from books/main.cpp"
    click D "https://github.com/raunak0400/similarity-checking-from-books/blob/main/similarity checking from books/main.cpp"
    click E "https://github.com/raunak0400/similarity-checking-from-books/blob/main/similarity checking from books/main.cpp"
    click F "https://github.com/raunak0400/similarity-checking-from-books/blob/main/similarity checking from books/main.cpp"
    click G "https://github.com/raunak0400/similarity-checking-from-books/tree/main/similarity checking from books/outputFiles"
    click H "https://github.com/raunak0400/similarity-checking-from-books/blob/main/similarity checking from books/main.cpp"

    %% Class Styles
    classDef input fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef processing fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef analysis fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef output fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef control fill:#D2B4DE,stroke:#333,stroke-width:2px;
```
