# imsudip/comparego architecture

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

- Interactive diagram: https://gitdiagram.com/imsudip/comparego
- Repository: https://github.com/imsudip/comparego

## Overview

##### Main Components
a. Presentation Layer (Frontend)
- Web Browser / Client
- Static assets (static/)
- Templates (templates/index.html, search.html, details.html)
b. Application Layer (Backend)
- Flask Web Server (main.py)
- Route Handlers:
- Price Comparison Endpoint (scrape.py invoked by main.py)
- Sentiment Analysis Endpoint (predict.py invoked by main.py)
c. Service Modules
- Scraper Service (scrape.py)
- Sentiment Service (predict.py + tfidf.pkl + logreg_model.pkl)
d. Data Layer
- Pre-trained Models: tfidf.pkl, logreg_model.pkl
- Datasets & Temp Files: AmazonReview.csv, amazon_reviews.csv, a.json, data.json
e. External Dependencies
- E-commerce Websites (Requests + BeautifulSoup)
- Python Libraries (Flask, sklearn, requests, bs4, pandas, etc.)

##### Relationships & Data Flows
- User → HTTP Request → Flask Routes
- For Price Comparison:
Flask Route → Scraper Service → External Websites → Raw HTML → Parsed Prices → JSON Response → Frontend
- For Sentiment Analysis:
Flask Route → Sentiment Service → Load tfidf + SVM Model → Classify Review Text → Score/Label → JSON Response → Frontend
- Static/Template files served by Flask to render UI.

##### Architectural Patterns
- Monolithic Flask Application with clear separation of concerns (routes vs. service modules).
- Two distinct functional domains (price scraping vs. sentiment classification).
- File-based “data store” instead of a dedicated database—flat files and pickled models.

##### Detailed Elements
- Frontend:
- Browser
- HTTP GET / POST
- Templates + Static files
- Backend (Flask Monolith):
- Route: “/search” → Scraper Service → external e-commerce sites
- Route: “/predict” → Sentiment Service → tfidf.pkl + logreg_model.pkl
- Data:
- Filesystem (CSV, JSON)
- Model artifacts (pickle files)
- External:
- E-commerce websites (Amazon, etc.)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    Browser["Web Browser"]:::frontend
    Browser -->|HTTP GET/POST| Flask["Flask Web Server (main.py)"]:::backend

    subgraph "Frontend / Presentation"
        direction TB
        Static["Static Assets"]:::frontend
        Templates["HTML Templates"]:::frontend
        subgraph "Templates"
            direction TB
            Index["index.html"]:::frontend
            SearchT["search.html"]:::frontend
            Details["details.html"]:::frontend
        end
    end

    Flask -->|serves files| Static
    Flask -->|renders templates| Templates

    %% Scraping Pipeline
    Flask -->|calls /search| ScraperRoute["Price Comparison Route"]:::service
    ScraperRoute --> ScraperService["Scraper Module"]:::service
    ScraperService -->|HTTP Requests| Websites["E-commerce Websites"]:::external
    Websites -->|Raw HTML| ScraperService
    ScraperService -->|Parsed Prices JSON| Flask

    %% Sentiment Pipeline
    Flask -->|calls /predict| SentimentRoute["Sentiment Analysis Route"]:::service
    SentimentRoute --> SentimentService["Sentiment Module"]:::service
    SentimentService --> TFIDF["tfidf.pkl"]:::storage
    SentimentService --> LOGREG["logreg_model.pkl"]:::storage
    SentimentService -->|Score/Label JSON| Flask

    %% Data Layer
    subgraph "Flat-file Data Storage"
        direction TB
        CSV1["AmazonReview.csv"]:::storage
        CSV2["amazon_reviews.csv"]:::storage
        JSON1["a.json"]:::storage
        JSON2["data.json"]:::storage
    end

    %% Other Project Files
    subgraph "Project Files"
        direction TB
        README["README.md"]:::storage
        Notebook["m.ipynb"]:::storage
        TempRun["tempCodeRunnerFile.py"]:::storage
    end

    %% Click Events
    click Static "https://github.com/imsudip/comparego/tree/master/static/"
    click Templates "https://github.com/imsudip/comparego/tree/master/templates/"
    click Index "https://github.com/imsudip/comparego/blob/master/templates/index.html"
    click SearchT "https://github.com/imsudip/comparego/blob/master/templates/search.html"
    click Details "https://github.com/imsudip/comparego/blob/master/templates/details.html"
    click Flask "https://github.com/imsudip/comparego/blob/master/main.py"
    click ScraperRoute "https://github.com/imsudip/comparego/blob/master/scrape.py"
    click ScraperService "https://github.com/imsudip/comparego/blob/master/scrape.py"
    click SentimentRoute "https://github.com/imsudip/comparego/blob/master/predict.py"
    click SentimentService "https://github.com/imsudip/comparego/blob/master/predict.py"
    click TFIDF "https://github.com/imsudip/comparego/blob/master/tfidf.pkl"
    click LOGREG "https://github.com/imsudip/comparego/blob/master/logreg_model.pkl"
    click CSV1 "https://github.com/imsudip/comparego/blob/master/AmazonReview.csv"
    click CSV2 "https://github.com/imsudip/comparego/blob/master/amazon_reviews.csv"
    click JSON1 "https://github.com/imsudip/comparego/blob/master/a.json"
    click JSON2 "https://github.com/imsudip/comparego/blob/master/data.json"
    click README "https://github.com/imsudip/comparego/blob/master/README.md"
    click Notebook "https://github.com/imsudip/comparego/blob/master/m.ipynb"
    click TempRun "https://github.com/imsudip/comparego/blob/master/tempCodeRunnerFile.py"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef service fill:#32CD32,stroke:#333,stroke-width:1px
    classDef storage fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:1px
```
