# mahdiahmadi87/hodhod architecture

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

- Interactive diagram: https://gitdiagram.com/mahdiahmadi87/hodhod
- Repository: https://github.com/mahdiahmadi87/hodhod

## Overview

Based on our analysis, this project is a full-stack news aggregation and recommendation system. Its purpose is to collect, classify, and display news content tailored to users’ interests. The system involves several distinct components: a Django-powered web application, background crawler scripts, machine learning modules for news classification and prediction, and a database that holds news and user-related data.

##### Main Components
- Frontend (User Interface): Represented by the Django "newsapp" component, which includes the templates, static assets (CSS, JS, images, and APK for Android), and pages (index, login, signup, news display, etc.).
- Backend (Django Framework): The core backend is built using Django (with submodules like “account” for user management and “cookie_consent”), which handles business logic, routing, and rendering views.
- Crawlers: A set of Python scripts in the “crawlers” directory (e.g., crawler.py, updateLastNews.py, deleteAllNews.py) that fetch and update news data from external sources.
- Machine Learning Modules:
- Classification Module: Found in the “classification” directory that uses pre-trained models (LogisticRegression.pkl and vectorizer.pkl) and classification logic in main.py.
- Regressor Module: In the “newsSelection” directory, which appears to perform regression analysis or predictions (regressor.py) possibly for personalized news ranking or recommendation.
- Database: Although Django uses its ORM, the README provides instructions to create a SQLite database manually (with tables like News, Viewed, and Users). This database stores all news content, user actions (views and ratings), and user metadata.
- External Services/Downloads: Additional resources include an external Persian FastText model (required for classification) and an APK download for Android distribution.

##### Relationships and Interactions
- Integration with External Resources: Indicate that the ML modules depend on external models (such as the Persian FastText vectors) by drawing a dependency link from the “Classification Module” to “External ML Models.”

##### Architectural Patterns and Technologies
- Modular Architecture: Clearly demarcate the components (crawlers, ML modules, Django web app) indicating that each is self-contained but communicates through the database.
- MVC-like Pattern: The Django project uses a Model-View approach through apps like “newsapp” and “account.” Show how views render templates while models interact with the database.
- Python/Django Ecosystem: Note the use of Python scripts, Django framework, and machine learning components integrated in a single project.
- Separation of Concerns: Emphasize that news fetching (crawlers), data processing (classification/regression), and user presentation (Django frontend) are logically separated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend (UI)"
        F1["Django Newsapp UI"]:::frontend
        F1T["Templates"]:::frontend
        F1S["Static Assets"]:::frontend
    end

    %% Backend Subgraph
    subgraph "Backend (Django)"
        B1["Core Project"]:::backend
        B2["Account Module"]:::backend
        B3["Cookie Consent Module"]:::backend
    end

    %% Crawlers Subgraph
    subgraph "Crawlers"
        C1["Crawlers Directory"]:::crawler
        C2["crawler.py"]:::crawler
        C3["updateLastNews.py"]:::crawler
        C4["deleteAllNews.py"]:::crawler
        C5["migrate_to_database_db.py"]:::crawler
    end

    %% Machine Learning Modules Subgraph
    subgraph "Machine Learning Modules"
        subgraph "Classification Module"
            ML1["main.py"]:::ml
            ML2["LogisticRegression.pkl"]:::ml
            ML3["vectorizer.pkl"]:::ml
        end
        subgraph "Regressor Module"
            ML4["regressor.py"]:::ml
            ML5["main.py"]:::ml
            ML6["deleteAllUserNews.py"]:::ml
        end
    end

    %% Database and External Dependencies
    DB["SQLite Database (News, Viewed, Users)"]:::database
    EX["External ML Model (Persian FastText)"]:::external

    %% Connections
    F1 -->|"UserRequests"| B1
    B1 <-->|"QueryUpdate"| DB
    B2 -->|"ManageUsers"| B1
    B3 -->|"CookieConsent"| B1

    C2 -->|"FetchNews"| DB
    C3 -->|"UpdateNews"| DB
    C4 -->|"DeleteNews"| DB
    C5 -->|"MigrateData"| DB

    ML1 -->|"ClassifyNews"| DB
    ML4 -->|"PredictRank"| DB

    ML1 -->|"Uses"| EX
    ML1 -->|"Feed_Classification"| B1
    ML5 -->|"Feed_Regression"| B1

    %% Click Events
    click F1 "https://github.com/mahdiahmadi87/hodhod/tree/fastLoad/hodhoddjango/newsapp"
    click F1T "https://github.com/mahdiahmadi87/hodhod/tree/fastLoad/hodhoddjango/newsapp/templates"
    click F1S "https://github.com/mahdiahmadi87/hodhod/tree/fastLoad/hodhoddjango/newsapp/static"

    click B1 "https://github.com/mahdiahmadi87/hodhod/tree/fastLoad/hodhoddjango/hodhoddjango"
    click B2 "https://github.com/mahdiahmadi87/hodhod/tree/fastLoad/hodhoddjango/account"
    click B3 "https://github.com/mahdiahmadi87/hodhod/tree/fastLoad/hodhoddjango/cookie_consent"

    click C1 "https://github.com/mahdiahmadi87/hodhod/tree/fastLoad/crawlers"
    click C2 "https://github.com/mahdiahmadi87/hodhod/blob/fastLoad/crawlers/crawler.py"
    click C3 "https://github.com/mahdiahmadi87/hodhod/blob/fastLoad/crawlers/updateLastNews.py"
    click C4 "https://github.com/mahdiahmadi87/hodhod/blob/fastLoad/crawlers/deleteAllNews.py"
    click C5 "https://github.com/mahdiahmadi87/hodhod/blob/fastLoad/crawlers/migrate_to_database_db.py"

    click ML1 "https://github.com/mahdiahmadi87/hodhod/blob/fastLoad/classification/main.py"
    click ML2 "https://github.com/mahdiahmadi87/hodhod/blob/fastLoad/classification/LogisticRegression.pkl"
    click ML3 "https://github.com/mahdiahmadi87/hodhod/blob/fastLoad/classification/vectorizer.pkl"
    click ML4 "https://github.com/mahdiahmadi87/hodhod/blob/fastLoad/newsSelection/regressor.py"
    click ML5 "https://github.com/mahdiahmadi87/hodhod/blob/fastLoad/newsSelection/main.py"
    click ML6 "https://github.com/mahdiahmadi87/hodhod/blob/fastLoad/newsSelection/deleteAllUserNews.py"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#0d47a1,color:#0d47a1;
    classDef backend fill:#c8e6c9,stroke:#2e7d32,color:#2e7d32;
    classDef crawler fill:#eeeeee,stroke:#606060,color:#606060;
    classDef ml fill:#ffe0b2,stroke:#ef6c00,color:#ef6c00;
    classDef database fill:#d1c4e9,stroke:#512da8,color:#512da8;
    classDef external fill:#ffcc80,stroke:#ef6c00,color:#ef6c00;
```
