# oriartyz/amazon_scrapper architecture

> Architecture diagram of the GitHub repository oriartyz/amazon_scrapper, 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/oriartyz/amazon_scrapper
- Repository: https://github.com/oriartyz/amazon_scrapper

## Overview

##### Project Type and Purpose
- This is a web scraping application that leverages the Flask framework to provide a simple user interface for scraping product data from Amazon (including product name, price, image, and description).
- The README and file tree indicate that it is a full-stack-like application: the backend handles scraping logic and HTTP requests, and the frontend is composed of HTML templates with static assets (CSS).

##### Main Components
a. User Interface (Frontend):
- HTML Templates: Represented by the files in the "templates" directory (search.html and results.html) which provide the UI screens.
- Static Assets: Located in the "static" directory (styles.css, and any additional assets like images if needed) that support the styling of the web pages.

b. Flask Application (Backend Server):
- Core Application: The app.py file that initializes and runs the Flask web server, routes user requests, and integrates with the scraping logic.

c. Scraping Logic Module:
- amazon_products.py: Contains the core functionality for sending HTTP requests (using Flask internally to trigger these actions), parsing web pages with BeautifulSoup, and extracting product data.
- Dependencies: Represent the use of external libraries such as BeautifulSoup, Requests, and Flask that are crucial for the scraping and web operations.

d. Data Store / Logging:
- CSV File: The "price_change.csv" file is used (or could be used) for persisting product price changes or historical data related to the scraping results.

e. Deployment & Configuration:
- Procfile: Indicates deployment configuration (common for platforms like Heroku) that outlines which command runs the web app.
- requirements.txt: A list of all dependencies required for the project, ensuring environment consistency.

##### Relationships and Interactions
- The User (browser) interacts with the Flask application by accessing the web pages rendered from the HTML templates.
- When a search or scraping request is made, app.py routes the request to a controller which then calls functions in amazon_products.py.
- The scraping module makes outbound requests to the Amazon site, processes the HTML response (using BeautifulSoup), and returns structured data.
- The returned data is then potentially written into a CSV (price_change.csv) for persistence or logging, and passed to the templates for user display.
- Deployment is managed via the Procfile for a cloud hosting platform.

##### Important Architectural Patterns and Design Principles
- Separation of Concerns: The project is cleanly split between the presentation layer (frontend HTML/CSS), and the backend that handles both the web server (Flask) and business logic (scraping in amazon_products.py).
- Lightweight Web Framework: Flask is used for quick development, routing, and templating.
- Modularity: The scraping functionality is modularized (amazon_products.py) for isolation and easier maintenance.
- Data Logging/Persistence: Storing price changes in a CSV demonstrates a simple form of state persistence or logging.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Browser"]:::frontend

    subgraph "User Interface (Frontend)"
        SearchTemplate["Search Template (search.html)"]:::frontend
        ResultsTemplate["Results Template (results.html)"]:::frontend
        StaticAsset["Static Asset (styles.css)"]:::frontend
    end

    Backend["Flask Application (app.py)"]:::backend
    Scraping["Scraping Module (amazon_products.py)"]:::scraping
    DataStore["CSV Data Store (price_change.csv)"]:::datastore

    subgraph "Deployment & Configuration"
        ProcfileNode["Procfile"]:::deployment
        Requirements["requirements.txt"]:::deployment
    end

    Browser -->|"sends_request"| Backend
    Backend -->|"calls_scraping"| Scraping
    Scraping -->|"returns_data"| Backend
    Backend -->|"renders_search_template"| SearchTemplate
    Backend -->|"renders_results_template"| ResultsTemplate
    Backend -->|"serves_static_asset"| StaticAsset
    Backend -->|"logs_data"| DataStore
    ProcfileNode -->|"deploy_config"| Backend
    Requirements -->|"dependency"| Backend

    click SearchTemplate "https://github.com/oriartyz/amazon_scrapper/blob/main/templates/search.html"
    click ResultsTemplate "https://github.com/oriartyz/amazon_scrapper/blob/main/templates/results.html"
    click StaticAsset "https://github.com/oriartyz/amazon_scrapper/blob/main/static/styles.css"
    click Backend "https://github.com/oriartyz/amazon_scrapper/blob/main/app.py"
    click Scraping "https://github.com/oriartyz/amazon_scrapper/blob/main/amazon_products.py"
    click DataStore "https://github.com/oriartyz/amazon_scrapper/blob/main/price_change.csv"
    click ProcfileNode "https://github.com/oriartyz/amazon_scrapper/tree/main/Procfile"
    click Requirements "https://github.com/oriartyz/amazon_scrapper/blob/main/requirements.txt"

    classDef frontend fill:#ADD8E6,stroke:#0000FF,stroke-width:2px,color:#000;
    classDef backend fill:#C8E6C9,stroke:#388E3C,stroke-width:2px,color:#000;
    classDef scraping fill:#FFE0B2,stroke:#FB8C00,stroke-width:2px,color:#000;
    classDef datastore fill:#E0E0E0,stroke:#9E9E9E,stroke-width:2px,color:#000;
    classDef deployment fill:#D1C4E9,stroke:#7E57C2,stroke-width:2px,color:#000;
```
