# tusharqlab/stock-alert-engine architecture

> Architecture diagram of the GitHub repository tusharqlab/stock-alert-engine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tusharqlab/stock-alert-engine
- Repository: https://github.com/tusharqlab/stock-alert-engine

## Overview

This is an automated NSE stock-alert engine, managed through configuration and a Colab alert-management notebook, with scans, daily summaries, history, and monthly Telegram archives. The normal scan path is explicit in main.py and run.py; run.py also dispatches separate summary and archive modes. Market data comes from Yahoo Finance, while alert definitions, settings, and Parquet history are file-backed. The notebook is a user-facing capability documented in the README, but its internals were not sampled. Edges reflect cited calls or README claims; omitted implementation details are not inferred.

Main entry points: [`run.py`](https://github.com/tusharqlab/stock-alert-engine/blob/main/run.py) (Scan orchestration), [`main.py`](https://github.com/tusharqlab/stock-alert-engine/blob/main/main.py) (Pipeline orchestration), [`engine/paths.py`](https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/paths.py) (Path resolution), [`engine/notifier.py`](https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/notifier.py) (Notification formatting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Scan workflow"]
  node_scan_entry["Scan orchestration<br/>[run.py]"]
  node_pipeline_entry["Pipeline orchestration<br/>[main.py]"]
  node_market_fetch["Market data fetch<br/>[data_fetcher.py]"]
end

subgraph group_domain["Alert domain"]
  node_alert_check["Alert evaluation<br/>[alert_checker.py]"]
  node_trendline["Trendline calculation<br/>[trendline.py]"]
end

subgraph group_persistence["Configuration and history"]
  node_alerts_config["Alert definitions<br/>[alerts.json]"]
  node_settings["Engine settings<br/>[config.yaml]"]
  node_paths["Path resolution<br/>[paths.py]"]
  node_history["History and archives<br/>[history.py]"]
  node_parquet[("Parquet history")]
end

subgraph group_delivery["Reporting and delivery"]
  node_summary["Daily summary<br/>[summary.py]"]
  node_notifier["Notification formatting<br/>[notifier.py]"]
end

subgraph group_management["Alert management"]
  node_alert_notebook["Colab alert manager"]
  node_alert_manager["Alert CRUD<br/>[alert_manager.py]"]
end

node_operator(("Operator"))
node_scheduler(("GitHub Actions schedule"))
node_yahoo["Yahoo Finance"]
node_telegram["Telegram"]

node_operator -->|"manages alerts"| node_alert_notebook
node_alert_notebook -.->|"uses"| node_alert_manager
node_alert_manager -->|"reads and writes"| node_alerts_config
node_scheduler -->|"dispatches"| node_scan_entry
node_operator -->|"runs mode"| node_scan_entry
node_scan_entry -->|"reads"| node_alerts_config
node_scan_entry -->|"fetches data"| node_market_fetch
node_market_fetch -->|"fetches prices"| node_yahoo
node_scan_entry -->|"checks alerts"| node_alert_check
node_alert_check -->|"calculates level"| node_trendline
node_alert_check -->|"reads and updates"| node_alerts_config
node_scan_entry -->|"appends triggers"| node_history
node_history -->|"reads and writes"| node_parquet
node_scan_entry -->|"sends alerts"| node_notifier
node_scan_entry -->|"builds summary"| node_summary
node_scan_entry -->|"sends summary"| node_notifier
node_notifier -->|"sends messages"| node_telegram
node_operator -->|"runs pipeline"| node_pipeline_entry
node_pipeline_entry -->|"fetches data"| node_market_fetch
node_pipeline_entry -->|"checks alerts"| node_alert_check
node_pipeline_entry -->|"appends triggers"| node_history
node_pipeline_entry -->|"sends notifications"| node_notifier
node_pipeline_entry -->|"builds summary"| node_summary
node_pipeline_entry -->|"sends summary"| node_notifier
node_operator -->|"selects summary or archive"| node_scan_entry
node_scan_entry -->|"creates archive"| node_history
node_scan_entry -->|"sends archive"| node_notifier
node_paths -->|"resolves settings path"| node_settings
node_paths -->|"resolves alerts path"| node_alerts_config
node_history -->|"gets storage paths"| node_paths
node_alert_check -->|"gets config paths"| node_paths
node_market_fetch -->|"gets config path"| node_paths
node_notifier -->|"gets config path"| node_paths
node_summary -->|"reads triggered history"| node_history
node_summary -->|"gets config paths"| node_paths

click node_scan_entry "https://github.com/tusharqlab/stock-alert-engine/blob/main/run.py"
click node_pipeline_entry "https://github.com/tusharqlab/stock-alert-engine/blob/main/main.py"
click node_market_fetch "https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/data_fetcher.py"
click node_alert_check "https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/alert_checker.py"
click node_trendline "https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/trendline.py"
click node_alert_notebook "https://github.com/tusharqlab/stock-alert-engine/blob/main/Alert_Manager.ipynb"
click node_alert_manager "https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/alert_manager.py"
click node_alerts_config "https://github.com/tusharqlab/stock-alert-engine/blob/main/config/alerts.json"
click node_settings "https://github.com/tusharqlab/stock-alert-engine/blob/main/config/config.yaml"
click node_paths "https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/paths.py"
click node_history "https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/history.py"
click node_parquet "https://github.com/tusharqlab/stock-alert-engine/blob/main/data/alert_history.parquet"
click node_summary "https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/summary.py"
click node_notifier "https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/notifier.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_scan_entry,node_pipeline_entry,node_market_fetch toneBlue
class node_alert_check,node_trendline toneAmber
class node_alerts_config,node_settings,node_paths,node_history,node_parquet toneMint
class node_summary,node_notifier toneRose
class node_alert_notebook,node_alert_manager,node_operator,node_scheduler,node_yahoo,node_telegram toneIndigo
```

## Components

### Scan workflow

- [Scan orchestration](https://github.com/tusharqlab/stock-alert-engine/blob/main/run.py): `run.py`
- [Pipeline orchestration](https://github.com/tusharqlab/stock-alert-engine/blob/main/main.py): `main.py`
- [Market data fetch](https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/data_fetcher.py): `engine/data_fetcher.py`

### Alert domain

- [Alert evaluation](https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/alert_checker.py): `engine/alert_checker.py`
- [Trendline calculation](https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/trendline.py): `engine/trendline.py`

### Configuration and history

- [Alert definitions](https://github.com/tusharqlab/stock-alert-engine/blob/main/config/alerts.json): `config/alerts.json`
- [Engine settings](https://github.com/tusharqlab/stock-alert-engine/blob/main/config/config.yaml): `config/config.yaml`
- [Path resolution](https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/paths.py): `engine/paths.py`
- [History and archives](https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/history.py): `engine/history.py`
- [Parquet history](https://github.com/tusharqlab/stock-alert-engine/blob/main/data/alert_history.parquet): `data/alert_history.parquet`

### Reporting and delivery

- [Daily summary](https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/summary.py): `engine/summary.py`
- [Notification formatting](https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/notifier.py): `engine/notifier.py`

### Alert management

- [Colab alert manager](https://github.com/tusharqlab/stock-alert-engine/blob/main/Alert_Manager.ipynb): `Alert_Manager.ipynb`
- [Alert CRUD](https://github.com/tusharqlab/stock-alert-engine/blob/main/engine/alert_manager.py): `engine/alert_manager.py`

### Other components

- **Operator**
- **GitHub Actions schedule**
- **Yahoo Finance**
- **Telegram**

## Connections

- Operator → Colab alert manager: manages alerts (evidence: `README.md`)
- Colab alert manager → Alert CRUD: uses
- Alert CRUD → Alert definitions: reads and writes (evidence: `engine/alert_manager.py`)
- GitHub Actions schedule → Scan orchestration: dispatches (evidence: `README.md`)
- Operator → Scan orchestration: runs mode (evidence: `run.py`)
- Scan orchestration → Alert definitions: reads (evidence: `run.py`)
- Scan orchestration → Market data fetch: fetches data (evidence: `run.py`)
- Market data fetch → Yahoo Finance: fetches prices (evidence: `engine/data_fetcher.py`)
- Scan orchestration → Alert evaluation: checks alerts (evidence: `run.py`)
- Alert evaluation → Trendline calculation: calculates level (evidence: `engine/alert_checker.py`)
- Alert evaluation → Alert definitions: reads and updates (evidence: `engine/alert_checker.py`)
- Scan orchestration → History and archives: appends triggers (evidence: `run.py`)
- History and archives → Parquet history: reads and writes (evidence: `engine/history.py`)
- Scan orchestration → Notification formatting: sends alerts (evidence: `run.py`)
- Scan orchestration → Daily summary: builds summary (evidence: `run.py`)
- Scan orchestration → Notification formatting: sends summary (evidence: `run.py`)
- Notification formatting → Telegram: sends messages (evidence: `engine/notifier.py`)
- Operator → Pipeline orchestration: runs pipeline (evidence: `main.py`)
- Pipeline orchestration → Market data fetch: fetches data (evidence: `main.py`)
- Pipeline orchestration → Alert evaluation: checks alerts (evidence: `main.py`)
- Pipeline orchestration → History and archives: appends triggers (evidence: `main.py`)
- Pipeline orchestration → Notification formatting: sends notifications (evidence: `main.py`)
- Pipeline orchestration → Daily summary: builds summary (evidence: `main.py`)
- Pipeline orchestration → Notification formatting: sends summary (evidence: `main.py`)
- Operator → Scan orchestration: selects summary or archive (evidence: `run.py`)
- Scan orchestration → History and archives: creates archive (evidence: `run.py`)
- Scan orchestration → Notification formatting: sends archive (evidence: `run.py`)
- Path resolution → Engine settings: resolves settings path (evidence: `engine/paths.py`)
- Path resolution → Alert definitions: resolves alerts path (evidence: `engine/paths.py`)
- History and archives → Path resolution: gets storage paths (evidence: `engine/history.py`)
- Alert evaluation → Path resolution: gets config paths (evidence: `engine/alert_checker.py`)
- Market data fetch → Path resolution: gets config path (evidence: `engine/data_fetcher.py`)
- Notification formatting → Path resolution: gets config path (evidence: `engine/notifier.py`)
- Daily summary → History and archives: reads triggered history (evidence: `engine/summary.py`)
- Daily summary → Path resolution: gets config paths (evidence: `engine/summary.py`)
