# ethical-buddy/torons architecture

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

- Interactive diagram: https://gitdiagram.com/ethical-buddy/torons
- Repository: https://github.com/ethical-buddy/torons

## Overview

##### Project Type & Core Purpose
- This is a specialized web crawler designed for “dark web” environments (Tor and I2P) that also performs NLP-based hate speech classification.
- The system supports multiple modes of operation (e.g., via CLI or web interface) and incorporates asynchronous processing, randomization techniques for anonymity, and continuous background file processing.

##### Primary Components to Capture
a. Web Crawling Engines:
- Tor Crawler: Represent scripts such as async_crawl4.py and tor.py that handle the asynchronous crawling of Tor websites.
- I2P Crawler: Represent scripts like async_crawl_i2p.py and i2p.py that directly target I2P network resources.
- Shared or common crawling utilities: Include components from the Research and Scraper directories (e.g., basic_crawler.py, basic_scraper.py) which indicate experimental or core scraping logic.
b. NLP Analysis Component:
- Clearly denote the NLP module (nlp.py and nlp/main.py) responsible for hate speech classification. Emphasize that this module utilizes a pre-trained transformer model (Hugging Face’s Hate-speech-CNERG/dehatebert-mono-english).
c. Data Storage & Processing:
- Data Persistence: Include the “data” folder and note that temporary files (like those mentioned in the README, such as temp/scraped.txt) and archived HTML/CSV files are used for tracking crawl results.
- Continuous Processing: Highlight the role of background threads that monitor and process files continuously (as mentioned in the README).
d. User Interfaces:
- CLI: Represented primarily by main.py which provides the menu-based control to launch crawlers and other utilities.
- Web Application: Represent the webapp directory containing app.py and its templates. This shows that there is also a web UI component for user interaction.
e. Utility & Configuration Components:
- Tor IP Utility: Scripts such as tor_ip_utility.py and related utilities for checking and maintaining network anonymity.
- Configuration File: config.py serves as the central configuration reference for managing environment variables or settings.
- Dockerfile: Indicates that containerization is used for deployment, which is an important part of the system’s runtime infrastructure.

##### Relationships and Data Flow
- That the Tor IP Utility is invoked as needed by the crawling modules to verify or rotate the current IP address.
- The continuous processing background thread should be illustrated as having a feedback loop with the Data Storage, ensuring that files are processed as they are saved.

##### Highlighted Architectural Patterns & Design Principles
- Asynchronous Processing: Use notation (e.g., a “async” label or “non-blocking” symbol) on the crawler components to denote concurrent operations.
- Modularity: Separate each major function (crawling, NLP analysis, UI, and utilities) into distinct components that interact through defined interfaces.
- Security & Randomization: Annotate that the user agent randomization and secure random string generation are embedded within the crawling components.
- Extensibility: Given the multiple directories (Research, Scraper) and experimentations, note that the system is designed to incorporate alternative scraping strategies and modules.

5. That security, randomization, and continuous background processing are noted as special features within the architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Docker Container"
        docker["Docker Container"]:::docker
        subgraph "User Interfaces"
            cli["CLI"]:::ui
            webui["Web UI"]:::ui
        end
        subgraph "Crawling Engines"
            tor_crawler["Tor Crawler (async)"]:::crawler
            i2p_crawler["I2P Crawler (async)"]:::crawler
            subgraph "Shared Utilities"
                research_util["Research Utilities"]:::utility
                scraper_util["Scraper Utilities"]:::utility
            end
        end
        subgraph "Utility & Config"
            tor_ip["Tor IP Utility"]:::utility
            config["Configuration"]:::utility
        end
        data_storage["Data Storage"]:::data
        nlp_node["NLP Analysis"]:::nlp
        background["Background Processing"]:::background
    end

    %% Relationships
    cli -->|"triggers"| tor_crawler
    cli -->|"triggers"| i2p_crawler

    webui -->|"triggers"| tor_crawler
    webui -->|"triggers"| i2p_crawler

    tor_crawler -->|"stores"| data_storage
    i2p_crawler -->|"stores"| data_storage

    research_util -.->|"supports"| tor_crawler
    research_util -.->|"supports"| i2p_crawler

    scraper_util -.->|"supports"| tor_crawler
    scraper_util -.->|"supports"| i2p_crawler

    tor_ip -->|"checks"| tor_crawler
    tor_ip -->|"checks"| i2p_crawler

    data_storage -->|"feeds"| nlp_node
    data_storage <-->|"feedback"| background

    %% Click Events
    click tor_crawler "https://github.com/ethical-buddy/torons/blob/main/async_crawl4.py"
    click tor_crawler "https://github.com/ethical-buddy/torons/blob/main/tor.py"
    click i2p_crawler "https://github.com/ethical-buddy/torons/blob/main/async_crawl_i2p.py"
    click i2p_crawler "https://github.com/ethical-buddy/torons/blob/main/i2p.py"
    click research_util "https://github.com/ethical-buddy/torons/blob/main/Research/async_crawl2.py"
    click research_util "https://github.com/ethical-buddy/torons/blob/main/Research/aync_crawl.py"
    click research_util "https://github.com/ethical-buddy/torons/blob/main/Research/crawl.py"
    click research_util "https://github.com/ethical-buddy/torons/blob/main/Research/scrape.py"
    click scraper_util "https://github.com/ethical-buddy/torons/blob/main/Scraper/basic_crawler.py"
    click scraper_util "https://github.com/ethical-buddy/torons/blob/main/Scraper/basic_scraper.py"
    click nlp_node "https://github.com/ethical-buddy/torons/blob/main/nlp.py"
    click nlp_node "https://github.com/ethical-buddy/torons/blob/main/nlp/main.py"
    click data_storage "https://github.com/ethical-buddy/torons/blob/main/data/.gitkeep"
    click cli "https://github.com/ethical-buddy/torons/blob/main/main.py"
    click webui "https://github.com/ethical-buddy/torons/blob/main/webapp/app.py"
    click webui "https://github.com/ethical-buddy/torons/blob/main/webapp/templates/index.html"
    click tor_ip "https://github.com/ethical-buddy/torons/blob/main/tor_ip_utility.py"
    click config "https://github.com/ethical-buddy/torons/blob/main/config.py"
    click docker "https://github.com/ethical-buddy/torons/tree/main/Dockerfile"

    %% Styles
    classDef docker fill:#e5f5e0,stroke:#74c476,stroke-width:2px;
    classDef ui fill:#fdd0a2,stroke:#cc4c02,stroke-width:2px;
    classDef crawler fill:#b3cde0,stroke:#03396c,stroke-width:2px;
    classDef utility fill:#fdae61,stroke:#d73027,stroke-width:2px;
    classDef data fill:#a1d99b,stroke:#31a354,stroke-width:2px;
    classDef nlp fill:#ffffbf,stroke:#bdbdbd,stroke-width:2px;
    classDef background fill:#d9d9d9,stroke:#969696,stroke-width:2px;
```
