# rakshithkanaje/instagram-sentiment-analyzer architecture

> Architecture diagram of the GitHub repository rakshithkanaje/instagram-sentiment-analyzer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rakshithkanaje/instagram-sentiment-analyzer
- Repository: https://github.com/rakshithkanaje/instagram-sentiment-analyzer

## Overview

##### Project type and purpose
- This is a data-processing pipeline (an ETL-style backend application) for real-time Instagram sentiment analysis. It ingests data (posts by hashtag), transforms it (sentiment scoring), stores it, then trains and evaluates a machine-learning model.

##### File structure
- Top level:
- main.py – the orchestration script
- requirements.txt – dependency list
- models/ – directory containing the saved TensorFlow model
- README.md, LICENSE, .gitignore
- No frontend/UI; purely backend.
- Key external services/configs implied: MongoDB instance, Playwright browser.

##### Extract architectural insights from the README
- Ingestion: “Scrapes Instagram posts by hashtag using Playwright”
- Processing: “Analyzes image captions for sentiment using TextBlob”
- Storage: “Stores data in MongoDB”
- Training: “Trains an LSTM model on captions using TensorFlow/Keras”
- Visualization: “Plots training accuracy with Matplotlib”
- Model persistence: “Saves model and metrics to models/ and disk.”

##### Main components & their interactions
a. External Source – Instagram (via HTTP)
b. Ingestion Module – Playwright-based scraper
c. NLP Module – Text preprocessor + TextBlob sentiment analyzer
d. Data Store – MongoDB database (collection for raw posts, collection for scored posts, collection for training data)
e. Training Module – TensorFlow/Keras LSTM trainer
f. Visualization Module – Matplotlib plot generator
g. Model Store – files under models/ (HDF5) and metrics output
h. Orchestrator – main.py ties all steps together

##### Architectural patterns & design principles
- ETL pipeline: clear separation of Extract → Transform → Load
- Modular scripting: each step encapsulated in functions or classes, invoked by main.py
- Single process but could be refactored to microservices (one service per stage)
- Persist intermediate and final artifacts for reproducibility

##### Technology labels
- Scraper: Python + Playwright
- NLP: Python + TextBlob
- DB: MongoDB via PyMongo
- Trainer: Python + TensorFlow/Keras + scikit-learn (for data prep) + NumPy
- Plotter: Python + Matplotlib

## Diagram (Mermaid)

```mermaid
flowchart TD
    Instagram["Instagram"]:::external
    Playwright["Playwright Scraper<br/>(Python + Playwright)"]:::ingestion
    TextProc["Text Preprocessor<br/>(Python + TextBlob)"]:::ingestion
    Sentiment["TextBlob Sentiment Analyzer"]:::ingestion
    MongoDB[(MongoDB<br/>raw_posts, scored_posts, training_data)]:::storage
    Trainer["TensorFlow LSTM Trainer<br/>(Python + TensorFlow/Keras)"]:::training
    Plotter["Matplotlib Plotter<br/>(Python + Matplotlib)"]:::training
    ModelStore["Model Store<br/>instagram_sentiment_model_tf.h5 & metrics"]:::storage
    Orchestrator["Orchestrator<br/>main.py"]:::orchestrator
    requirements["requirements.txt"]:::orchestrator
    readme["README.md"]:::orchestrator
    license1["LICENSE"]:::orchestrator
    gitignore[".gitignore"]:::orchestrator

    Instagram -->|"HTTP requests (hashtags)"| Playwright
    Playwright -->|"raw captions + metadata"| TextProc
    TextProc -->|"cleaned captions"| Sentiment
    Sentiment -->|"scored records"| MongoDB
    MongoDB -->|"fetch training set"| Trainer
    Trainer -->|"model.h5 + metrics"| ModelStore
    Trainer -->|"accuracy plot.png"| Plotter
    ModelStore -->|deployment/retrain loop| Orchestrator
    Orchestrator --> Playwright
    Orchestrator --> Trainer
    Orchestrator --> Plotter

    classDef ingestion fill:#D0E4F5,stroke:#333,stroke-width:1px
    classDef storage fill:#D5E8D4,stroke:#333,stroke-width:1px
    classDef training fill:#F8CECC,stroke:#333,stroke-width:1px
    classDef orchestrator fill:#E8E8E8,stroke:#333,stroke-width:1px
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px

    click Orchestrator "https://github.com/rakshithkanaje/instagram-sentiment-analyzer/blob/main/main.py"
    click ModelStore "https://github.com/rakshithkanaje/instagram-sentiment-analyzer/blob/main/models/instagram_sentiment_model_tf.h5"
    click requirements "https://github.com/rakshithkanaje/instagram-sentiment-analyzer/blob/main/requirements.txt"
    click readme "https://github.com/rakshithkanaje/instagram-sentiment-analyzer/blob/main/README.md"
    click license1 "https://github.com/rakshithkanaje/instagram-sentiment-analyzer/tree/main/LICENSE"
    click gitignore "https://github.com/rakshithkanaje/instagram-sentiment-analyzer/blob/main/.gitignore"
```
