# utkarsh-chauhannn/saari-news-walah architecture

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

- Interactive diagram: https://gitdiagram.com/utkarsh-chauhannn/saari-news-walah
- Repository: https://github.com/utkarsh-chauhannn/saari-news-walah

## Overview

##### Main Components
- AI Agent Module (ai_agent.py): This module implements the core AI functionality using LangChain and LangGraph. It leverages a ReAct (Reasoning + Acting) framework to interact with models (like Groq’s LLaMA) and external search tools (e.g., Tavily Search).
- Backend API (backend.py): Developed with FastAPI and using Pydantic for data validation, this layer handles API requests, integrates the AI agent, and provides interactive documentation (Swagger UI).
- Frontend Interface (frontend.py): Built with Streamlit, this component provides an interactive chat UI, which connects to the backend to display real-time, AI-powered responses.
- External Services & Tools: Although not explicitly in the file tree, mention the integration with external APIs/services for Groq, OpenAI, and Tavily Search as documented in the README.

##### Relationships and Interactions
- The Frontend sends chat input requests to the Backend API.
- The Backend API receives requests, validates them with Pydantic models, and routes them to the AI Agent module.
- The AI Agent processes the request using the LangChain and LangGraph frameworks. It communicates with external services (for instance, real-time news fetching and model inference).
- The Backend then sends the AI agent’s response back to the Frontend for display.
- Data flow from the user (via the Frontend) to the Backend.
- Internal communication from the Backend to the AI Agent.
- Outbound interactions from the AI Agent to external APIs/services.

##### Architectural Patterns & Technologies
- Separation of concerns: the clear split between the UI (Streamlit), API layer (FastAPI), and business logic (AI agent with LangChain/LangGraph).
- Modularity and scalability gates (easily extensible with additional tools or models).
- Detailed dependencies: FastAPI for RESTful endpoints, Pydantic for validation, LangChain & LangGraph for AI workflows, and Streamlit for an interactive, lightweight web interface.
- Mention design principles such as the ReAct pattern for reasoning and acting, which is central to the AI Agent’s operation.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Frontend Layer"
        F["Streamlit Frontend (frontend)"] 
    end

    subgraph "Backend Layer"
        B["FastAPI Backend (backend)"]
    end

    subgraph "AI Module"
        AI["AI Agent (LangChain & LangGraph) (ai_agent)"]
    end

    subgraph "External Services"
        Ext1["Groq's LLaMA"]
        Ext2["OpenAI"]
        Ext3["Tavily Search"]
    end

    F -->|"sendsChatInput"| B
    B -->|"routesRequestToAgent"| AI
    AI -->|"invokesExternalAPIs"| Ext1
    AI -->|"invokesExternalAPIs"| Ext2
    AI -->|"invokesExternalAPIs"| Ext3
    Ext1 -->|"returnsData"| AI
    Ext2 -->|"returnsData"| AI
    Ext3 -->|"returnsData"| AI
    AI -->|"sendsAIResponse"| B
    B -->|"respondsToChat"| F

    click F "https://github.com/utkarsh-chauhannn/saari-news-walah/blob/main/frontend.py"
    click B "https://github.com/utkarsh-chauhannn/saari-news-walah/blob/main/backend.py"
    click AI "https://github.com/utkarsh-chauhannn/saari-news-walah/blob/main/ai_agent.py"

    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef aiAgent fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px;

    class F frontend;
    class B backend;
    class AI aiAgent;
    class Ext1,Ext2,Ext3 external;
```
