# mahanteshimath/bazaaraisaathi architecture

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

- Interactive diagram: https://gitdiagram.com/mahanteshimath/bazaaraisaathi
- Repository: https://github.com/mahanteshimath/bazaaraisaathi

## Overview

##### Project Type and Purpose
- This is a full-stack, AI-driven analytics web app built with Streamlit.
- Purpose: Provide investors with real-time stock data, AI-powered research, portfolio analysis, hypothesis testing, and personalized financial planning.

##### File Structure
- Top-level entry point: Home.py
- pages/ — Streamlit sub‐apps (UI routes) for each major feature: Architecture, Deep Research, Real-Time Data, Portfolio Analysis, etc.
- utils/ — Business logic modules (data fetch, analysis, OCR, AI integration)
- src/ — Static assets and data sources (CSV market data, book summaries, architecture image)
- config files: requirements.txt, .streamlit/config.toml

##### Key Architecture Insights from README
- Frontend: Streamlit UI with multiple “pages” modules.
- Backend logic: Python utils + LangChain, Perplexity AI, EasyOCR.
- Data: Local CSVs + external real-time APIs.
- Visualization: Plotly, Pandas.

##### Main Components
a. User Interface Layer
- Streamlit App (Home.py) & dynamic pages modules.
- UI controls (forms, charts, tables).

b. Application Logic Layer
- Page controllers (pages/*.py) orchestrate flows.
- Utility modules (utils/*.py) that implement:
– RealTime_stock_price_analysis.py → external stock API calls
– deep_research.py, get_market_insights.py → web scraping & AI calls
– finance_utils.py, portfolio_analysis.py → data processing & analytics
– fire_planner.py → financial independence logic
– tip_analysis.py → OCR (EasyOCR) + AI validation

c. Data Layer
- Local CSV data (src/BSE_Equity.csv, NSE_EQUITYS.csv, holdings.csv, Top50Books.csv)
- In-memory Pandas DataFrames

d. External Services
- Perplexity AI & LangChain for NLP/forecasting
- EasyOCR/Docling Parse for image/PDF text extraction
- Third-party stock price APIs
- (Optional) Streamlit Secrets for API keys

e. Visualization Layer
- Plotly for interactive charts
- Streamlit components for tables, forms

##### Relationships and Data Flows
- User interacts with Streamlit UI → triggers a page controller.
- Controller calls utils module(s) → fetches data from CSV or external API → processes data.
- For AI tasks: controller sends text/data to Perplexity AI via LangChain.
- Results returned → passed back to UI → rendered as charts/tables.

##### Highlighted Architectural Patterns
- Modular MVC-like separation:
- View = Streamlit pages
- Controller = pages/*.py orchestration
- Model = utils/*.py data and business logic
- Layered architecture: Presentation, Business Logic, Data Access, External Services
- Pluggable AI & data sources

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        direction TB
        Home["Home.py"]:::ui
        Architecture["Architecture.py"]:::ui
        DeepResearch["Deep_Research.py"]:::ui
        RealTimeData["Fetch_real_time_stock_data.py"]:::ui
        AIResearch["Finance_with_Perplexity.py"]:::ui
        FinancialIndependence["Financial_Independence.py"]:::ui
        Hypothesis["Hypothesis.py"]:::ui
        MarketIndicators["Market_Indicators.py"]:::ui
        PortfolioAnalysisPage["Portfolio_Analysis.py"]:::ui
        StocksList["Stocks_List.py"]:::ui
        TechnoFund["Techno_Fund_Analysis.py"]:::ui
        TipTester["Tip_Tester.py"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        RTStock["RealTime_stock_price_analysis.py"]:::logic
        DeepResearchLogic["deep_research.py"]:::logic
        MarketInsights["get_market_insights.py"]:::logic
        FinanceUtils["finance_utils.py"]:::logic
        PortfolioLogic["portfolio_analysis.py"]:::logic
        FIREPlanner["fire_planner.py"]:::logic
        TipAnalysis["tip_analysis.py"]:::logic
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        BSE["BSE_Equity.csv"]:::data
        NSE["NSE_EQUITYS.csv"]:::data
        Holdings["holdings.csv"]:::data
        Books["Top50Books.csv"]:::data
        ArchAsset["Architecture_app.txt"]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        StockAPI["Stock Price API"]:::external
        PerplexityAI["Perplexity AI / LangChain"]:::external
        EasyOCR["EasyOCR / DocParser"]:::external
        StreamlitSecrets["Streamlit Secrets"]:::external
    end

    %% Flows: UI to Logic
    Home -->|navigates to| Architecture
    Home -->|navigates to| DeepResearch
    Home -->|navigates to| RealTimeData
    Home -->|navigates to| AIResearch
    Home -->|navigates to| FinancialIndependence
    Home -->|navigates to| Hypothesis
    Home -->|navigates to| MarketIndicators
    Home -->|navigates to| PortfolioAnalysisPage
    Home -->|navigates to| StocksList
    Home -->|navigates to| TechnoFund
    Home -->|navigates to| TipTester

    RealTimeData -->|calls| RTStock
    DeepResearch -->|calls| DeepResearchLogic
    AIResearch -->|calls| MarketInsights
    PortfolioAnalysisPage -->|calls| PortfolioLogic
    FinancialIndependence -->|calls| FIREPlanner
    Hypothesis -->|calls| FinanceUtils
    MarketIndicators -->|calls| FinanceUtils
    StocksList -->|calls| FinanceUtils
    TechnoFund -->|calls| FinanceUtils
    TipTester -->|calls| TipAnalysis

    %% Logic to Data/External
    RTStock -->|fetches JSON| StockAPI
    RTStock -->|processes data| FinanceUtils

    DeepResearchLogic -->|scrapes & processes| Books
    DeepResearchLogic -->|AI call| PerplexityAI

    MarketInsights -->|sends data| PerplexityAI

    FinanceUtils -->|reads CSV| BSE
    FinanceUtils -->|reads CSV| NSE

    PortfolioLogic -->|reads CSV| Holdings
    FIREPlanner -->|reads CSV| Holdings

    TipAnalysis -->|OCR image| EasyOCR
    TipAnalysis -->|AI validation| PerplexityAI

    %% Return flows
    RTStock -->|DataFrame| RealTimeData
    DeepResearchLogic -->|text/DataFrame| DeepResearch
    MarketInsights -->|insights| AIResearch
    FinanceUtils -->|DataFrame| Hypothesis
    FinanceUtils -->|DataFrame| MarketIndicators
    PortfolioLogic -->|analysis| PortfolioAnalysisPage
    FIREPlanner -->|plan| FinancialIndependence
    TipAnalysis -->|result| TipTester

    %% Click Events
    click Home "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/Home.py"
    click Architecture "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/pages/Architecture.py"
    click DeepResearch "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/pages/Deep_Research.py"
    click RealTimeData "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/pages/Fetch_real_time_stock_data.py"
    click AIResearch "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/pages/Finance_with_Perplexity.py"
    click FinancialIndependence "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/pages/Financial_Independence.py"
    click Hypothesis "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/pages/Hypothesis.py"
    click MarketIndicators "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/pages/Market_Indicators.py"
    click PortfolioAnalysisPage "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/pages/Portfolio_Analysis.py"
    click StocksList "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/pages/Stocks_List.py"
    click TechnoFund "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/pages/Techno_Fund_Analysis.py"
    click TipTester "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/pages/Tip_Tester.py"
    click RTStock "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/utils/RealTime_stock_price_analysis.py"
    click DeepResearchLogic "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/utils/deep_research.py"
    click MarketInsights "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/utils/get_market_insights.py"
    click FinanceUtils "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/utils/finance_utils.py"
    click PortfolioLogic "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/utils/portfolio_analysis.py"
    click FIREPlanner "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/utils/fire_planner.py"
    click TipAnalysis "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/utils/tip_analysis.py"
    click BSE "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/src/BSE_Equity.csv"
    click NSE "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/src/NSE_EQUITYS.csv"
    click Holdings "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/src/holdings.csv"
    click Books "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/src/Top50Books.csv"
    click ArchAsset "https://github.com/mahanteshimath/bazaaraisaathi/blob/main/src/Architecture_app.txt"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,color:#004085;
    classDef logic fill:#d4edda,stroke:#155724,color:#155724;
    classDef data fill:#ffeeba,stroke:#856404,color:#856404;
    classDef external fill:#d6d8db,stroke:#1b1e21,color:#1b1e21;
```
