# srgitq/instagram-crawler-app architecture

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

- Interactive diagram: https://gitdiagram.com/srgitq/instagram-crawler-app
- Repository: https://github.com/srgitq/instagram-crawler-app

## Overview

##### Project type and purpose
- This is a full-stack application for crawling data from public Instagram profiles, processing it, and exposing it via a dashboard.
- The backend is a Flask-based “crawler_api” that orchestrates scrapers, stores data, and applies preprocessing.
- The frontend is a Streamlit app (“streamlit-front”) that renders charts and tables based on the scraped data.

##### File structure
- Top-level directories:
- crawler_api/ – Python package that includes:
· db.py – database connection and ORM or queries
· scrapper/ – modules that actually fetch data (instagram_conf.py, navigator_assistant.py)
· utils/ – helper modules (preprocessing, timer, userParser)
- streamlit-front/ – Streamlit UI code: atoms/ (reusable widgets), frontutils/, display.py, main.py
- Requirements.txt defines backend dependencies (Flask, scraping libraries, database drivers)
- No Docker or Kubernetes manifests—this is deployed as two separate services.

##### README for additional insights
- Describes task distribution among multiple extractors to speed up scraping
- Mentions multiple accounts to avoid abuse detection
- Points at advanced data-processing steps (sentiment analysis, topic modeling, clustering)
- Indicates scalability but no dedicated message queue—likely Python threads or processes.

a. Main components:
1. Streamlit Frontend
2. Flask Backend API
3. Scraper Engine (the “crawler_api.scrapper” modules)
4. Data Processing / Preprocessing modules
5. Database (e.g., Postgres, MongoDB, or SQLite)
6. External Service: Instagram Public API / Web endpoints
b. Relationships & interactions:
- Streamlit UI → (HTTP/gRPC) → Flask API endpoints to start a crawl or fetch results
- Flask API → orchestrates Scraper Engine → fetches raw data from Instagram
- Scraper Engine → passes raw data → Preprocessing modules (sentiment, clustering)
- Processed data → saved into Database via db.py
- Streamlit UI → polls or subscribes for new data → renders bar charts, post lists, user info
c. Architectural patterns / design principles:
- Separation of concerns: UI vs. API vs. Scraper vs. Data Store
- Modular design (utils, scrapper vs. orchestration layer)
d. Key technologies & frameworks:
- Python 3.x, Flask for API
- Streamlit for frontend
- Scraping libraries (Selenium, Instaloader or custom navigator_assistant)
- Pandas / Numpy… for preprocessing
- Database driver (psycopg2, SQLAlchemy, PyMongo)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Dashboard (Streamlit)" 
        direction TB
        Main["main.py"]:::frontend
        Display["display.py"]:::frontend
        subgraph "atoms/" 
            direction TB
            Bar["bar.py"]:::frontend
            PolBullet["polbullet.py"]:::frontend
            Posts["posts.py"]:::frontend
            UserInfo["userInfo.py"]:::frontend
        end
        QueryUtils["frontutils/queryd.py"]:::frontend
    end

    %% Backend/API Layer
    subgraph "Flask API (crawler_api)" 
        direction TB
        API["__init__.py"]:::backend
        DBInterface["db.py"]:::database
    end

    %% Scraper Engine
    subgraph "Scraper Engine" 
        direction TB
        InstaConf["instagram_conf.py"]:::backend
        Navigator["navigator_assistant.py"]:::backend
    end

    %% Preprocessing Layer
    subgraph "Preprocessing" 
        direction TB
        Preproc["preprocessing.py"]:::backend
        Timer["timer.py"]:::backend
        UserParser["userParser.py"]:::backend
    end

    %% Database
    Database[(Database)]:::database

    %% External Service
    Instagram[(Instagram Public Endpoints)]:::external

    %% Connections
    Main -->|"HTTP/JSON"| API
    Display -->|"HTTP/JSON"| API
    API -->|"start scrape"| InstaConf
    API -->|"start scrape"| Navigator
    InstaConf -->|"GET requests"| Instagram
    Navigator -->|"GET requests"| Instagram
    InstaConf -->|"raw data"| Preproc
    Navigator -->|"raw data"| Preproc
    Preproc -->|"write DataFrame"| Database
    API -->|"read/write"| Database
    API -->|"response JSON"| Display

    %% Click Events
    click Main "https://github.com/srgitq/instagram-crawler-app/blob/main/streamlit-front/main.py"
    click Display "https://github.com/srgitq/instagram-crawler-app/blob/main/streamlit-front/display.py"
    click Bar "https://github.com/srgitq/instagram-crawler-app/blob/main/streamlit-front/atoms/bar.py"
    click PolBullet "https://github.com/srgitq/instagram-crawler-app/blob/main/streamlit-front/atoms/polbullet.py"
    click Posts "https://github.com/srgitq/instagram-crawler-app/blob/main/streamlit-front/atoms/posts.py"
    click UserInfo "https://github.com/srgitq/instagram-crawler-app/blob/main/streamlit-front/atoms/userInfo.py"
    click QueryUtils "https://github.com/srgitq/instagram-crawler-app/blob/main/streamlit-front/frontutils/queryd.py"
    click API "https://github.com/srgitq/instagram-crawler-app/blob/main/crawler_api/__init__.py"
    click DBInterface "https://github.com/srgitq/instagram-crawler-app/blob/main/crawler_api/db.py"
    click InstaConf "https://github.com/srgitq/instagram-crawler-app/blob/main/crawler_api/scrapper/instagram_conf.py"
    click Navigator "https://github.com/srgitq/instagram-crawler-app/blob/main/crawler_api/scrapper/navigator_assistant.py"
    click Preproc "https://github.com/srgitq/instagram-crawler-app/blob/main/crawler_api/utils/preprocessing.py"
    click Timer "https://github.com/srgitq/instagram-crawler-app/blob/main/crawler_api/utils/timer.py"
    click UserParser "https://github.com/srgitq/instagram-crawler-app/blob/main/crawler_api/utils/userParser.py"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef backend fill:#E2F8E6,stroke:#28A745,color:#22863A
    classDef database fill:#FFE5CC,stroke:#D2691E,color:#A63D00
    classDef external fill:#F0F0F0,stroke:#6A737D,color:#6A737D
```
