# kaustubhvaidya404/news-summary-ai architecture

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

- Interactive diagram: https://gitdiagram.com/kaustubhvaidya404/news-summary-ai
- Repository: https://github.com/kaustubhvaidya404/news-summary-ai

## Overview

##### Main Components
- Client Layer
- Web Browser (end user interacting with Streamlit UI)
- HTTP Client (cURL or other tools calling FastAPI)
- Presentation Layer
- Streamlit App (app.py) running on port 8501
- FastAPI Server (api.py) running on port 8000
- Business Logic Layer (modules/)
- extract_articles.py (scrapes Times of India)
- analysis.py (frequency-based summarizer + VADER sentiment analyser)
- text_to_speech.py (translate + gTTS TTS engine)
- Utility Layer
- utils.py (shared helper functions)
- Development/Extension Layer (Jupyter config & pydeck extension under etc/ and share/)
- External Services & Libraries
- Times of India (news source via HTTP requests)
- NLTK (tokenization, VADER)
- translate library (text translation)
- gTTS (Google TTS engine)

##### Relationships & Data Flows
- Streamlit → calls modules directly for:
a) Article extraction → summarization → sentiment → optional TTS
b) Displays summary, sentiment charts, audio player
- FastAPI → exposes endpoints under `/v1/company` and `/v1/company/audio`
- On GET request: orchestrates the same module workflow, returns JSON or audio stream
- Modules interact in sequence:
User query → extract_articles → analysis (summarize + sentiment) → if requested, text_to_speech → return results

##### Architectural Patterns
- Layered (Presentation → Business → Utility)
- Separation of concerns:
- Frontend (Streamlit UI) vs. API (FastAPI) vs. Core Logic (modules)
- Stateless micro-service style (no persistent DB, each request re-runs the pipeline)

##### Technologies & Frameworks
- Python 3, Streamlit, FastAPI
- NLTK (sent_tokenize, word_tokenize, VADER)
- gTTS and translate library
- PyDeck Jupyter extension (development/visualization)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Web Browser"]:::external
        HTTPClient["HTTP Client (cURL)"]:::external
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        StreamlitUI["Streamlit UI\n(app.py)\nPort 8501"]:::frontend
        FastAPIServer["FastAPI Server\n(api.py)\nPort 8000"]:::frontend
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Extract["Article Extraction\n(extract_articles.py)"]:::business
        Analysis["Summarization & Sentiment\n(analysis.py)"]:::business
        TTS["Text-to-Speech\n(text_to_speech.py)"]:::business
    end

    %% Utility Layer
    Utils["Shared Utilities\n(utils.py)"]:::util

    %% Development/Extension Layer
    subgraph "Development/Extension Layer"
        JupyterConfig["Jupyter Config\n(pydeck.json)"]:::dev
        PydeckExt["PyDeck Extension"]:::dev
    end

    %% External Services & Libraries
    subgraph "External Services & Libraries"
        TimesOfIndia["Times of India"]:::external
        NLTK["NLTK"]:::external
        TranslateLib["translate lib"]:::external
        gTTS["gTTS"]:::external
    end

    %% Data Flows
    Browser -->|"HTTP 8501"| StreamlitUI
    HTTPClient -->|"HTTP 8000"| FastAPIServer

    StreamlitUI -->|"calls"| Extract
    FastAPIServer -->|"calls"| Extract

    Extract -->|"passes articles"| Analysis
    Analysis -->|"passes summary & sentiment"| TTS
    TTS -->|"returns audio/text"| StreamlitUI
    TTS -->|"returns audio/text"| FastAPIServer

    %% Utilities usage
    Extract --> Utils
    Analysis --> Utils
    TTS --> Utils

    %% External interactions
    Extract -->|"scrapes"| TimesOfIndia
    Analysis -->|"uses tokenization & VADER"| NLTK
    TTS -->|"uses translation"| TranslateLib
    TTS -->|"uses TTS engine"| gTTS

    %% Click Events
    click StreamlitUI "https://github.com/kaustubhvaidya404/news-summary-ai/blob/main/app.py"
    click FastAPIServer "https://github.com/kaustubhvaidya404/news-summary-ai/blob/main/api.py"
    click Extract "https://github.com/kaustubhvaidya404/news-summary-ai/blob/main/modules/extract_articles.py"
    click Analysis "https://github.com/kaustubhvaidya404/news-summary-ai/blob/main/modules/analysis.py"
    click TTS "https://github.com/kaustubhvaidya404/news-summary-ai/blob/main/modules/text_to_speech.py"
    click Utils "https://github.com/kaustubhvaidya404/news-summary-ai/blob/main/utils.py"
    click JupyterConfig "https://github.com/kaustubhvaidya404/news-summary-ai/blob/main/etc/jupyter/nbconfig/notebook.d/pydeck.json"
    click PydeckExt "https://github.com/kaustubhvaidya404/news-summary-ai/tree/main/share/jupyter/nbextensions/pydeck"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef business fill:#90EE90,stroke:#333,stroke-width:1px
    classDef util fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef dev fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
```
