# bharath-541/social_media_insights architecture

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

- Interactive diagram: https://gitdiagram.com/bharath-541/social_media_insights
- Repository: https://github.com/bharath-541/social_media_insights

## Overview

##### Project type and purpose
- This is a data-pipeline project that fetches Instagram post metrics via the Instagram Graph API, persists them in AstraDB, and then runs analytical flows using Langflow integrated with the Google Gemini API.
- Key use case: ETL of social-media performance data and AI-driven analysis of engagement trends.

##### File structure
- Top-level files:
- InstaGetData.py – the ETL script
- instagram_data.csv – output of the ETL step
- Insta_Insights.json – (possibly saved API response or config)
- README.md – project overview
- Pre-Hackathon Assignment_ Social Media Performance Analysis.pdf – documentation/assignment specification
- No frontend/backend separation in code; the architecture consists of an extraction component (Python script), a storage layer (AstraDB), and a processing layer (Langflow + Google Gemini).

##### README for additional insights
- The README describes three major steps:
1. Instagram Graph API extraction via Python + OAuth token
2. CSV creation + upload to AstraDB
3. Langflow pipeline that reads from AstraDB, calls Google Gemini, and renders results

##### Main components
a. Instagram Graph API (External Service)
b. ETL Script (InstaGetData.py)
c. Data Artifacts (CSV file, JSON file)
d. AstraDB (Cassandra-compatible cloud database)
e. Langflow Application (Pipeline definition and runtime)
f. Google Gemini API (External LLM/AI service)
g. Langflow Playground / End-user Interface

##### Relationships and interactions
- InstaGetData.py → calls → Instagram Graph API → returns → JSON data
- InstaGetData.py → writes → instagram_data.csv
- InstaGetData.py → uploads → CSV → AstraDB
- Langflow → reads → data from AstraDB (AstraDB Tool node)
- Langflow → sends data → Google Gemini API → receives → AI-driven insights
- Langflow Playground → displays → insights to user

##### Architectural patterns & design principles
- ETL pipeline for ingestion and persistence
- Separation of concerns: extraction layer, storage layer, processing/analysis layer, and presentation layer
- Use of managed external services (AstraDB, Google Gemini API) to minimize operational overhead
- Declarative flow composition via Langflow as a low-code orchestration layer

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "Extraction Layer"
        ETL["ETL Script<br/>InstaGetData.py"]:::internal
        JSON["Config JSON<br/>Insta_Insights.json"]:::datastore
    end

    subgraph "Storage Layer"
        CSV["Data Artifact<br/>instagram_data.csv"]:::datastore
        DB["AstraDB"]:::datastore
    end

    subgraph "Processing Layer"
        Langflow["Langflow Application"]:::internal
        Gemini["Google Gemini API"]:::external
    end

    subgraph "Presentation Layer"
        UI["Langflow Playground UI"]:::internal
    end

    subgraph "Documentation"
        README["README.md"]:::internal
        ASSIGN["Pre-Hackathon Assignment<br/>Social Media Performance Analysis.pdf"]:::internal
    end

    %% External Service
    Instagram["Instagram Graph API"]:::external

    %% Data Flows
    ETL -->|"GET /media_insights\nREST over HTTPS\nOAuth2" | Instagram
    Instagram -->|"JSON Response"| ETL
    JSON -->|"Config"| ETL

    ETL -->|"Write CSV"| CSV
    ETL -->|"Upload CSV\nvia Cassandra API"| DB

    Langflow -->|"Fetch data\nvia AstraDB Tool"| DB
    Langflow -->|"Analyze\nREST over HTTPS\nAPI Key"| Gemini
    Gemini -->|"Insights"| Langflow
    Langflow -->|"Render"| UI

    %% Click Events
    click ETL "https://github.com/bharath-541/social_media_insights/blob/main/InstaGetData.py"
    click CSV "https://github.com/bharath-541/social_media_insights/blob/main/instagram_data.csv"
    click JSON "https://github.com/bharath-541/social_media_insights/blob/main/Insta_Insights.json"
    click README "https://github.com/bharath-541/social_media_insights/blob/main/README.md"
    click ASSIGN "https://github.com/bharath-541/social_media_insights/blob/main/Pre-Hackathon Assignment_ Social Media Performance Analysis.pdf"

    %% Styles
    classDef external fill:#bfdbfe,stroke:#93c5fd
    classDef internal fill:#e5e7eb,stroke:#9ca3af
    classDef datastore fill:#fed7aa,stroke:#fdba74
```
