# dr-lin-eng/stock-scanner architecture

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

- Interactive diagram: https://gitdiagram.com/dr-lin-eng/stock-scanner
- Repository: https://github.com/dr-lin-eng/stock-scanner

## Overview

##### Project Type and Purpose
- The project is a specialized stock analysis system for the A-share market, offering both single-stock analysis (via a GUI) and batch market scanning.
- The README clearly outlines three main functions/components:
– Single Stock Analysis GUI (with files like stock_analyzer.py and gui2.py)
– Batch Stock Scanner (triggered by 全部股票分析推荐1.py)
– Advanced Technical Indicator Analysis Engine (integrated in the analysis logic within stock_analyzer.py)
- Additionally, a minimal web interface exists (web_app.py and templates folder), likely to display results or summary reports.

##### Analysis of the File Structure
- Top-level configuration/utility files:
- .env: Contains API keys and environment configurations.
- requirements.txt: Lists system dependencies.
- Dockerfile and docker-compose.yml: Used for containerizing and deploying the application.
- Core Application Files:
- stock_analyzer.py: The key file for single stock analysis.
- gui.py & gui2.py: GUI implementations; note that gui2.py is the one used as per the README.
- 全部股票分析推荐1.py: Implements the batch scanning logic.
- web_app.py: Provides a web interface with HTML templates (in the templates directory).
- README.md: Contains project overview, setup instructions, and key functional details.
- The structure indicates a mix of standalone GUI-based functionality, batch processing scripts, and a simple web component.

a. Components:
- User Interfaces:
- GUI Application for Single Stock Analysis (via gui2.py and stock_analyzer.py).
- Web Application Interface (web_app.py and templates/index.html).
- Analysis Engines:
- Advanced Technical Indicator Analysis Engine (within stock_analyzer.py, performing calculations for indicators like MA, RSI, MACD, etc.).
- Batch Scanner (全部股票分析推荐1.py) for full-market scanning.
- Configuration & Infrastructure:
- Environment Variables (.env) – provide API keys and runtime configurations.
- Docker Environment (Dockerfile and docker-compose.yml) – for containerizing and running the system.
- Dependencies and External Libraries:
- Python and its libraries (PyQt6, Pandas, NumPy, AkShare, Markdown2 as per the requirements).

b. Relationships and Interactions:
- The GUI components interact with the underlying analysis engine by passing user input (stock selections and parameter configurations) and receiving analysis results.
- Both the single-stock analysis and batch scanning components likely share similar core analysis logic (technical indicator computations).
- The web interface (via web_app.py) may serve as an alternate way to view or trigger operations, pulling in HTML templates from the templates folder.
- Configuration (from .env) is loaded by the analysis scripts (especially in stock_analyzer.py) to connect with external APIs.
- Docker and docker-compose wrap the system infrastructure for consistent deployment, orchestrating service start-up and environment setups.
- Data flow is bidirectional: front-end interfaces (GUI/web) send requests to the backend analysis logic, which then returns computed analysis reports.

c. Architectural Patterns & Design Principles:
- Separation of Concerns: Distinct modules for user interface (both GUI and web), analysis computation (technical indicators), and orchestration (batch scanning vs. single analysis).
- Modularity: Scripts and components can be run independently (e.g., single stock analysis vs. full market scan).
- Containerization: Emphasizes deployment consistency via Docker, making the design more portable.
- Extensibility: The project is structured to potentially add more analysis or interface components, following a loosely coupled design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        GUI["GUI App (gui2.py)"]:::presentation
        WEB["Web Interface (web_app.py)"]:::presentation
        TEMPLATE["Template (index.html)"]:::presentation
    end

    subgraph "Business Logic Layer"
        ANALYSIS["Analysis Engine (stock_analyzer.py)"]:::business
        BATCH["Batch Scanner (全部股票分析推荐1.py)"]:::business
    end

    subgraph "Infrastructure & Deployment"
        CONFIG["Configuration (.env)"]:::deployment
        DOCKER["Docker Setup (Dockerfile)"]:::deployment
        COMPOSE["Docker Compose (docker-compose.yml)"]:::deployment
    end

    %% Data flow between Presentation and Business Logic Layers
    GUI -->|"sends_input"| ANALYSIS
    WEB -->|"sends_request"| ANALYSIS
    ANALYSIS -->|"returns_results"| GUI
    ANALYSIS -->|"returns_results"| WEB
    WEB -->|"renders_using"| TEMPLATE

    %% Business logic interactions
    BATCH -->|"uses_logic"| ANALYSIS

    %% Infrastructure interactions
    CONFIG -->|"loads_config"| ANALYSIS
    DOCKER -->|"containerizes"| GUI
    DOCKER -->|"containerizes"| ANALYSIS
    DOCKER -->|"containerizes"| BATCH
    COMPOSE -->|"orchestrates"| GUI
    COMPOSE -->|"orchestrates"| WEB
    COMPOSE -->|"orchestrates"| ANALYSIS
    COMPOSE -->|"orchestrates"| BATCH

    %% Click Events for Component Mapping
    click GUI "https://github.com/dr-lin-eng/stock-scanner/blob/main/gui2.py"
    click ANALYSIS "https://github.com/dr-lin-eng/stock-scanner/blob/main/stock_analyzer.py"
    click WEB "https://github.com/dr-lin-eng/stock-scanner/blob/main/web_app.py"
    click TEMPLATE "https://github.com/dr-lin-eng/stock-scanner/blob/main/templates/index.html"
    click BATCH "https://github.com/dr-lin-eng/stock-scanner/blob/main/全部股票分析推荐1.py"
    click CONFIG "https://github.com/dr-lin-eng/stock-scanner/blob/main/.env"
    click DOCKER "https://github.com/dr-lin-eng/stock-scanner/tree/main/Dockerfile"
    click COMPOSE "https://github.com/dr-lin-eng/stock-scanner/blob/main/docker-compose.yml"

    %% Styles
    classDef presentation fill:#d1e8ff,stroke:#0d47a1,stroke-width:2px;
    classDef business fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    classDef deployment fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
```
