# khemanth630/stockgen architecture

> Architecture diagram of the GitHub repository khemanth630/stockgen, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/khemanth630/stockgen
- Repository: https://github.com/khemanth630/stockgen

## Overview

StockGEN combines a Streamlit forecasting interface and a Flask prediction API. The main workflow gathers historical prices and news, merges them, scores news sentiment, computes volatility, predicts price and trend, then generates confidence and a Buy/Sell/Hold recommendation. The interface also offers a separate retrieval-based question-answering path over the generated sentiment-and-volatility CSV. The excerpts show the API orchestration and key dataset routines; some implementation details are omitted, so only evidenced integrations and calls are drawn.

Main entry points: [`app.py`](https://github.com/khemanth630/stockgen/blob/main/app.py) (Streamlit App), [`api.py`](https://github.com/khemanth630/stockgen/blob/main/api.py) (Prediction API), [`dataset_app.py`](https://github.com/khemanth630/stockgen/blob/main/dataset_app.py) (Price & News), [`finetuned_lora_model_confidence`](https://github.com/khemanth630/stockgen/tree/main/finetuned_lora_model_confidence) (Confidence Model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User Interface"]
  node_streamlit["Streamlit App<br/>[app.py]"]
  node_flask["Prediction API<br/>[api.py]"]
  node_result["Forecast Result<br/>[api.py]"]
end

subgraph group_data["Market Data"]
  node_marketdata["Price &amp; News<br/>[dataset_app.py]"]
  node_yahoo["Yahoo Finance"]
  node_alpaca["Alpaca News"]
  node_merged["Merged Data"]
end

subgraph group_analysis["Forecasting"]
  node_sentiment["FinBERT Sentiment<br/>[api.py]"]
  node_volatility["Volatility Scoring<br/>[api.py]"]
  node_priceforecast["Price Forecast<br/>[api.py]"]
  node_confidence["Confidence Model"]
  node_recommendation["Recommendation Model"]
end

subgraph group_qa["Stock Q&amp;A"]
  node_csv["Sentiment CSV"]
  node_retrieval["Row Retrieval<br/>[app.py]"]
  node_answer["Answer Generation<br/>[app.py]"]
  node_t5["Flan-T5 Model"]
  node_embedder["Sentence Embedder"]
  node_faiss[("FAISS Index<br/>[app.py]")]
end

node_user(("Investor"))

node_user -->|"enters inputs"| node_streamlit
node_streamlit -->|"POSTs prediction"| node_flask
node_flask -->|"calls fetch and merge"| node_marketdata
node_marketdata -->|"fetches prices"| node_yahoo
node_marketdata -->|"fetches news"| node_alpaca
node_marketdata -->|"returns merged data"| node_merged
node_flask -->|"scores news"| node_sentiment
node_sentiment -->|"adds sentiment scores"| node_volatility
node_volatility -->|"provides features"| node_priceforecast
node_priceforecast -->|"supplies trend"| node_confidence
node_priceforecast -->|"supplies forecast"| node_recommendation
node_confidence -->|"supplies confidence"| node_recommendation
node_flask -->|"returns prediction"| node_result
node_result -->|"renders metrics"| node_streamlit
node_user -->|"asks question"| node_streamlit
node_streamlit -->|"reads generated data"| node_csv
node_csv -->|"provides rows"| node_retrieval
node_retrieval -->|"embeds rows and query"| node_embedder
node_retrieval -->|"indexes and searches"| node_faiss
node_retrieval -->|"provides context"| node_answer
node_answer -->|"generates answer"| node_t5
node_answer -->|"displays response"| node_streamlit

click node_streamlit "https://github.com/khemanth630/stockgen/blob/main/app.py"
click node_flask "https://github.com/khemanth630/stockgen/blob/main/api.py"
click node_marketdata "https://github.com/khemanth630/stockgen/blob/main/dataset_app.py"
click node_sentiment "https://github.com/khemanth630/stockgen/blob/main/api.py"
click node_volatility "https://github.com/khemanth630/stockgen/blob/main/api.py"
click node_priceforecast "https://github.com/khemanth630/stockgen/blob/main/api.py"
click node_confidence "https://github.com/khemanth630/stockgen/tree/main/finetuned_lora_model_confidence"
click node_recommendation "https://github.com/khemanth630/stockgen/tree/main/finetuned_lora_model_recommendation"
click node_result "https://github.com/khemanth630/stockgen/blob/main/api.py"
click node_retrieval "https://github.com/khemanth630/stockgen/blob/main/app.py"
click node_answer "https://github.com/khemanth630/stockgen/blob/main/app.py"
click node_faiss "https://github.com/khemanth630/stockgen/blob/main/app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_streamlit,node_flask,node_result toneBlue
class node_marketdata,node_yahoo,node_alpaca,node_merged toneAmber
class node_sentiment,node_volatility,node_priceforecast,node_confidence,node_recommendation toneMint
class node_csv,node_retrieval,node_answer,node_t5,node_embedder,node_faiss toneRose
class node_user toneIndigo
```

## Components

### User Interface

- [Streamlit App](https://github.com/khemanth630/stockgen/blob/main/app.py): `app.py`
- [Prediction API](https://github.com/khemanth630/stockgen/blob/main/api.py): `api.py`
- [Forecast Result](https://github.com/khemanth630/stockgen/blob/main/api.py): `api.py`

### Market Data

- [Price & News](https://github.com/khemanth630/stockgen/blob/main/dataset_app.py): `dataset_app.py`
- **Yahoo Finance**
- **Alpaca News**
- **Merged Data**

### Forecasting

- [FinBERT Sentiment](https://github.com/khemanth630/stockgen/blob/main/api.py): `api.py`
- [Volatility Scoring](https://github.com/khemanth630/stockgen/blob/main/api.py): `api.py`
- [Price Forecast](https://github.com/khemanth630/stockgen/blob/main/api.py): `api.py`
- [Confidence Model](https://github.com/khemanth630/stockgen/tree/main/finetuned_lora_model_confidence): `finetuned_lora_model_confidence`
- [Recommendation Model](https://github.com/khemanth630/stockgen/tree/main/finetuned_lora_model_recommendation): `finetuned_lora_model_recommendation`

### Stock Q&A

- **Sentiment CSV**
- [Row Retrieval](https://github.com/khemanth630/stockgen/blob/main/app.py): `app.py`
- [Answer Generation](https://github.com/khemanth630/stockgen/blob/main/app.py): `app.py`
- **Flan-T5 Model**
- **Sentence Embedder**
- [FAISS Index](https://github.com/khemanth630/stockgen/blob/main/app.py): `app.py`

### Other components

- **Investor**

## Connections

- Investor → Streamlit App: enters inputs
- Streamlit App → Prediction API: POSTs prediction
- Prediction API → Price & News: calls fetch and merge
- Price & News → Yahoo Finance: fetches prices
- Price & News → Alpaca News: fetches news
- Price & News → Merged Data: returns merged data
- Prediction API → FinBERT Sentiment: scores news
- FinBERT Sentiment → Volatility Scoring: adds sentiment scores
- Volatility Scoring → Price Forecast: provides features
- Price Forecast → Confidence Model: supplies trend
- Price Forecast → Recommendation Model: supplies forecast
- Confidence Model → Recommendation Model: supplies confidence
- Prediction API → Forecast Result: returns prediction
- Forecast Result → Streamlit App: renders metrics
- Investor → Streamlit App: asks question
- Streamlit App → Sentiment CSV: reads generated data
- Sentiment CSV → Row Retrieval: provides rows
- Row Retrieval → Sentence Embedder: embeds rows and query
- Row Retrieval → FAISS Index: indexes and searches
- Row Retrieval → Answer Generation: provides context
- Answer Generation → Flan-T5 Model: generates answer
- Answer Generation → Streamlit App: displays response
