# 0011ashwin/amity-hack architecture

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

- Interactive diagram: https://gitdiagram.com/0011ashwin/amity-hack
- Repository: https://github.com/0011ashwin/amity-hack

## Overview

##### Project Overview and Purpose
- The project is a web application – likely built on a Flask (or similar) framework – providing an interface for processing and analyzing documents.
- It includes capabilities such as extracting text from PDF files, classifying documents based on content (with trained machine learning models), detecting plagiarism, and handling query operations on documents.

##### Analyzing the File Structure
- Top-level Files:
- README.md (“Document Intelligence System”) that briefly defines the project's intent.
- Several Python scripts (run.py, test.py, tool.py) likely used for running or testing various functionalities.
- requirements.txt which will list dependencies and tech stack libraries.

- The app Directory:
- Contains main components of the web application (app.py, __init__.py).
- Includes modules like document_classifier.py, pdf_extractor.py, plagiarism_detector.py, and query_engine.py – each corresponding to a core functionality.
- Has a static directory (for style.css) and a templates directory (with HTML files like index.html, document_classification.html, plagiarism.html, etc.) to serve as the user interface.

- The document_classifier Directory:
- Contains supplementary scripts (e.g., hackathon.py) and training data organized into categories (financial, healthcare, legal).
- Stores critical model files (text_classifier.pkl and vectorizer.pkl) that are used in the classification process.

- Data Directory:
- Hosts sample PDF files used either for demonstration, testing, or as input documents for the system.

##### Main Components Identified
a. User Interface / Web Layer:
- Frontend templates (HTML files) and static assets (CSS) used to provide the UI.
- Located in the app/templates and app/static directories.

b. Application/Controller Layer:
- The Flask app (app/app.py) that wires up the user interface with the backend functionalities.
- Responsible for routing HTTP requests to appropriate module handlers.

c. Document Processing Modules:
- PDF Extraction Module (app/pdf_extractor.py): Extracts text from PDF documents.
- Document Classifier (app/document_classifier.py): Utilizes ML models stored in document_classifier/text_classifier.pkl and document_classifier/vectorizer.pkl to classify documents.
- Plagiarism Detector (app/plagiarism_detector.py): Checks documents for duplicated or plagiarized content.
- Query Engine (app/query_engine.py): Processes user search or query operations on documents.

d. Training Data and Model Files:
- Document classifier training data available in document_classifier/training_data (organized by domain such as financial, healthcare, legal).
- Persisted model objects (pickle files) that are loaded during runtime for classification tasks.

e. Data Storage:
- Input data (e.g., sample PDFs) located within the data directory.

f. Supporting Scripts and Tools:
- Additional scripts like run.py, test.py, and tool.py for running the server, performing tests, or executing utilities.

##### Relationships and Interactions
- Web clients interact with the UI layer (HTML templates and CSS), which is backed by the Flask application.
- The application layer (app/app.py) routes incoming requests to specialized modules (PDF extraction, classification, plagiarism detection, query engine).
- Each module interacts with its respective models (e.g., classification module loads models and vectorizers) and input documents (from the data directory or user uploads).
- Processed outputs (extracted text, classification labels, plagiarism reports) then are rendered back to the user via HTML templates.

##### Architectural Patterns and Technologies
- MVC-Inspired Structure: Separation between the view (HTML/CSS templates), controller (Flask routes in app/app.py), and the model (machine learning models and processing functions).
- Modular Design: Each functionality (extraction, classification, plagiarism detection) is implemented as a separate module, facilitating maintainability and possible future extension.
- Use of Pickle for model persistence: Ensures that the document classification component can quickly load trained models.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface"
        UI_Templates["Templates (HTML)"]:::ui
        UI_Static["Static Assets (CSS)"]:::ui
    end

    %% Application Controller Layer
    subgraph "Application Controller"
        App_Flask["Flask App"]:::controller
        App_Init["Init File"]:::controller
    end

    %% Document Processing Modules
    subgraph "Document Processing Modules"
        Mod_PDF["PDF Extractor"]:::processing
        Mod_Class["Document Classifier"]:::processing
        Mod_Plaga["Plagiarism Detector"]:::processing
        Mod_Query["Query Engine"]:::processing
    end

    %% Training Data & Models
    subgraph "Training Data & Models"
        Train_Data["Training Data"]:::data
        Train_Text["Text Classifier Model"]:::data
        Train_Vector["Vectorizer Model"]:::data
    end

    %% Data Storage
    Data_Inp["Input Documents"]:::data

    %% Supporting Scripts and Tools
    subgraph "Supporting Scripts"
        Script_Run["run.py"]:::support
        Script_Test["test.py"]:::support
        Script_Tool["tool.py"]:::support
    end

    %% Relationships
    UI_Templates -->|"request"| App_Flask
    UI_Static -->|"request"| App_Flask

    App_Flask -->|"delegate"| Mod_PDF
    App_Flask -->|"delegate"| Mod_Class
    App_Flask -->|"delegate"| Mod_Plaga
    App_Flask -->|"delegate"| Mod_Query

    Data_Inp -->|"input"| Mod_PDF
    Data_Inp -->|"input"| Mod_Class
    Data_Inp -->|"input"| Mod_Plaga
    Data_Inp -->|"input"| Mod_Query

    Mod_Class -->|"loads"| Train_Data
    Mod_Class -->|"loads"| Train_Text
    Mod_Class -->|"loads"| Train_Vector

    Mod_PDF -->|"response"| App_Flask
    Mod_Class -->|"response"| App_Flask
    Mod_Plaga -->|"response"| App_Flask
    Mod_Query -->|"response"| App_Flask

    App_Flask -->|"renders"| UI_Templates

    Script_Run -->|"starts"| App_Flask
    Script_Test -->|"tests"| App_Flask
    Script_Tool -->|"utilities"| App_Flask

    %% Click Events
    click UI_Templates "https://github.com/0011ashwin/amity-hack/tree/main/app/templates"
    click UI_Static "https://github.com/0011ashwin/amity-hack/tree/main/app/static"
    click App_Flask "https://github.com/0011ashwin/amity-hack/blob/main/app/app.py"
    click App_Init "https://github.com/0011ashwin/amity-hack/blob/main/app/__init__.py"
    click Mod_PDF "https://github.com/0011ashwin/amity-hack/blob/main/app/pdf_extractor.py"
    click Mod_Class "https://github.com/0011ashwin/amity-hack/blob/main/app/document_classifier.py"
    click Mod_Plaga "https://github.com/0011ashwin/amity-hack/blob/main/app/plagiarism_detector.py"
    click Mod_Query "https://github.com/0011ashwin/amity-hack/blob/main/app/query_engine.py"
    click Train_Data "https://github.com/0011ashwin/amity-hack/tree/main/document_classifier/training_data"
    click Train_Text "https://github.com/0011ashwin/amity-hack/blob/main/document_classifier/text_classifier.pkl"
    click Train_Vector "https://github.com/0011ashwin/amity-hack/blob/main/document_classifier/vectorizer.pkl"
    click Data_Inp "https://github.com/0011ashwin/amity-hack/tree/main/data"
    click Script_Run "https://github.com/0011ashwin/amity-hack/blob/main/run.py"
    click Script_Test "https://github.com/0011ashwin/amity-hack/blob/main/test.py"
    click Script_Tool "https://github.com/0011ashwin/amity-hack/blob/main/tool.py"

    %% Styles
    classDef ui fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef controller fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef processing fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef data fill:#e0e0e0,stroke:#424242,stroke-width:2px;
    classDef support fill:#d1c4e9,stroke:#512da8,stroke-width:2px;
```
