# 079035/nascent-rag architecture

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

- Interactive diagram: https://gitdiagram.com/079035/nascent-rag
- Repository: https://github.com/079035/nascent-rag

## Overview

##### Main Components
- Client Interface: Represented by the main.py, which acts as the entry point that prompts users for inputs (stock ticker and query) and coordinates operations.
- Pipeline Module: Under the src/pipeline directory, there are two specialized modules:
- news_fetcher.py (fetches news data likely through an external API using the RAPIDAPI_KEY)
- transcript_fetcher.py (handles transcript data)
- RAG Module: Under the src/rag directory, which includes:
- elasticsearch_handler.py (responsible for interactions with the Elasticsearch backend)
- query_service.py (manages query operations that leverage the Elasticsearch-indexed data)
- Data Storage / Search Engine: Elasticsearch (an external service) that indexes the fetched data and supports the sentence-based embedding search.
- Containerization & Deployment: Dockerfile, docker-compose.yml, and build.sh illustrate that the system is containerized and deployed using Docker Compose.
- Testing Suite: The tests directory which confirms unit and integration testing for components like news, transcripts, embeddings, query services, and Elasticsearch.

##### Relationships and Interactions
- The client (main.py) triggers the data retrieval process by interacting with the pipeline components (news_fetcher and transcript_fetcher) which are responsible for fetching data using external APIs.
- Once data is fetched, it is processed and sent to the Elasticsearch backend via the elasticsearch_handler for indexing.
- When the user submits a query, the main.py interacts with the query_service which in turn retrieves relevant data from Elasticsearch.
- Docker Compose manages the orchestration of these containers ensuring that services (such as the Elasticsearch instance and the application container) are running cohesively.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clear division between data retrieval (pipeline) and data querying (rag).
- Modular Design: Each module (fetchers, Elasticsearch handlers, query service) encapsulates its responsibilities for easier testing (as indicated by the tests directory) and maintenance.
- Containerized Deployment: Use of Docker ensures that the components (possibly even an Elasticsearch container) run in isolated environments that simplify deployment and scalability.
- Interactive Terminal-Based Operation: Although simple, this design focuses on a clean separation between the interactive client component (main.py) and backend processing.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Application Components
    Client["Client Interface (main.py)"]:::client

    subgraph "Pipeline Modules"
        NewsFetcher["Pipeline: News Fetcher"]:::pipeline
        TranscriptFetcher["Pipeline: Transcript Fetcher"]:::pipeline
    end

    subgraph "RAG Modules"
        ESHandler["Elasticsearch Handler"]:::rag
        QuerySvc["Query Service"]:::rag
    end

    ESBackend["Elasticsearch Backend"]:::database

    %% Deployment & Testing Artifacts
    subgraph "Deployment & Testing"
        subgraph "Containerization"
            DF["Dockerfile"]:::deployment
            DC["docker-compose.yml"]:::deployment
            BS["build.sh"]:::deployment
        end
        TS["Testing Suite"]:::testing
    end

    %% Data Flow Connections
    Client -->|"fetchData"| NewsFetcher
    Client -->|"fetchData"| TranscriptFetcher

    NewsFetcher -->|"indexData"| ESHandler
    TranscriptFetcher -->|"indexData"| ESHandler

    ESHandler -->|"storeData"| ESBackend

    Client -->|"queryData"| QuerySvc
    QuerySvc -->|"retrieveData"| ESBackend

    %% Styling Classes
    classDef client fill:#f9f,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#ccf,stroke:#333,stroke-width:2px;
    classDef rag fill:#cfc,stroke:#333,stroke-width:2px;
    classDef database fill:#fc9,stroke:#333,stroke-width:2px;
    classDef deployment fill:#9cf,stroke:#333,stroke-width:2px;
    classDef testing fill:#ffc,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mapping
    click Client "https://github.com/079035/nascent-rag/blob/main/main.py"
    click NewsFetcher "https://github.com/079035/nascent-rag/blob/main/src/pipeline/news_fetcher.py"
    click TranscriptFetcher "https://github.com/079035/nascent-rag/blob/main/src/pipeline/transcript_fetcher.py"
    click ESHandler "https://github.com/079035/nascent-rag/blob/main/src/rag/elasticsearch_handler.py"
    click QuerySvc "https://github.com/079035/nascent-rag/blob/main/src/rag/query_service.py"
    click DF "https://github.com/079035/nascent-rag/tree/main/Dockerfile"
    click DC "https://github.com/079035/nascent-rag/blob/main/docker-compose.yml"
    click BS "https://github.com/079035/nascent-rag/blob/main/build.sh"
    click TS "https://github.com/079035/nascent-rag/tree/main/tests"
```
