# jason8745/llm-stock-analyzer architecture

> Architecture diagram of the GitHub repository jason8745/llm-stock-analyzer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jason8745/llm-stock-analyzer
- Repository: https://github.com/jason8745/llm-stock-analyzer

## Overview

##### Project type and purpose
- This is a backend API service (“llm-stock-analyzer”) providing LLM-powered stock analysis via HTTP endpoints.
- It uses FastAPI for the API layer, LangChain for LLM orchestration, Pydantic for validation, and integrates with YFinance, Shioaji, and an LLM provider.

##### File structure
- Top-level:
- app/ – application code
- tests/ – pytest test suite
- .github/ – CI config
- Makefile, pyproject.toml – build and dependency management
- app/ subdirectories:
- api/v1/endpoints.py – HTTP endpoints (LLM analysis, health)
- configs/ – config loader (YAML + Pydantic)
- internal/ – core implementation:
– analysis/indicators.py – indicator functions
– llm/chain.py – LangChain prompt/response chaining
– shioaji/stock_data.py – TW market data adapter
– yfinance/stock_data.py – global market data adapter
- services/analysis/ – business logic and pipelines:
– stock_trend_pipeline.py – data enrichment with indicators
– trend_analysis.py – generate buy/sell signals
- prompts/ – versioned prompt templates for the LLM
- utils/logger.py – structured logging via Loguru
- No persistent database; external dependencies are real-time data APIs and an LLM service.

##### README for additional insights
- Confirms layered, modular architecture
- Highlights key frameworks: FastAPI, LangChain, Pydantic, YFinance, Shioaji
- Mentions CI pipeline (lint, type check, tests)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client\n(curl/Postman)"]:::external

    %% API Layer
    subgraph "API Layer"
        direction TB
        APIEntrypoint["FastAPI Entrypoint\napp/main.py"]:::api
        APIEndpoints["HTTP Endpoints\napp/api/v1/endpoints.py"]:::api
    end

    %% Config & Logger
    subgraph "Config & Logger"
        direction TB
        ConfigLoader["Configuration Loader\napp/configs/config.py\napp/configs/config.example.yaml"]:::config
        StructuredLogger["Structured Logger\napp/utils/logger.py"]:::config
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        StockPipeline["Stock Trend Pipeline\napp/services/analysis/stock_trend_pipeline.py"]:::service
        TrendAnalysis["Trend Analysis\napp/services/analysis/trend_analysis.py"]:::service
    end

    %% Internal Modules
    subgraph "Internal Modules"
        direction TB
        Indicators["Technical Indicators\napp/internal/analysis/indicators.py"]:::internal
        LLMChain["LLM Chain Orchestration\napp/internal/llm/chain.py"]:::internal
        subgraph "Data Adapters"
            direction TB
            YFinanceAdapter["YFinance Adapter\napp/internal/yfinance/stock_data.py"]:::internal
            ShioajiAdapter["Shioaji Adapter\napp/internal/shioaji/stock_data.py"]:::internal
        end
    end

    %% Prompt Store
    PromptStore["Prompt Templates\napp/prompts/stock_analyzer_prompt.md"]:::internal

    %% External Services
    subgraph "External Services"
        direction TB
        YFinance["YFinance API"]:::external
        Shioaji["Shioaji API"]:::external
        LLMProvider["LLM Provider"]:::external
    end

    %% CI/CD
    CICD["CI/CD Pipeline\n.github/workflows/ci.yaml"]:::cicd

    %% Connections
    Client -->|"HTTP Request"| APIEntrypoint
    APIEntrypoint -->|"routes to"| APIEndpoints
    APIEntrypoint -->|"loads"| ConfigLoader
    APIEntrypoint -->|"initializes"| StructuredLogger
    APIEndpoints -->|"calls"| StockPipeline
    APIEndpoints -->|"calls"| TrendAnalysis
    StockPipeline -->|"fetch raw data"| YFinanceAdapter
    StockPipeline -->|"fetch raw data"| ShioajiAdapter
    StockPipeline -->|"compute indicators"| Indicators
    TrendAnalysis -->|"compute signals"| Indicators
    TrendAnalysis -->|"invoke LLM"| LLMChain
    LLMChain -->|"uses templates"| PromptStore
    YFinanceAdapter -->|"REST API"| YFinance
    ShioajiAdapter -->|"REST API"| Shioaji
    LLMChain -->|"API call"| LLMProvider
    APIEndpoints -->|"response"| Client

    %% CI/CD arrow
    CICD -.-> APIEntrypoint

    %% Click Events
    click APIEntrypoint "https://github.com/jason8745/llm-stock-analyzer/blob/master/app/main.py"
    click APIEndpoints "https://github.com/jason8745/llm-stock-analyzer/blob/master/app/api/v1/endpoints.py"
    click ConfigLoader "https://github.com/jason8745/llm-stock-analyzer/blob/master/app/configs/config.py"
    click StructuredLogger "https://github.com/jason8745/llm-stock-analyzer/blob/master/app/utils/logger.py"
    click StockPipeline "https://github.com/jason8745/llm-stock-analyzer/blob/master/app/services/analysis/stock_trend_pipeline.py"
    click TrendAnalysis "https://github.com/jason8745/llm-stock-analyzer/blob/master/app/services/analysis/trend_analysis.py"
    click Indicators "https://github.com/jason8745/llm-stock-analyzer/blob/master/app/internal/analysis/indicators.py"
    click LLMChain "https://github.com/jason8745/llm-stock-analyzer/blob/master/app/internal/llm/chain.py"
    click YFinanceAdapter "https://github.com/jason8745/llm-stock-analyzer/blob/master/app/internal/yfinance/stock_data.py"
    click ShioajiAdapter "https://github.com/jason8745/llm-stock-analyzer/blob/master/app/internal/shioaji/stock_data.py"
    click PromptStore "https://github.com/jason8745/llm-stock-analyzer/blob/master/app/prompts/stock_analyzer_prompt.md"
    click CICD "https://github.com/jason8745/llm-stock-analyzer/blob/master/.github/workflows/ci.yaml"

    %% Styles
    classDef api fill:#D0E8FF,stroke:#0366D6;
    classDef service fill:#E6F7E6,stroke:#219653;
    classDef internal fill:#FFF9C4,stroke:#F2C94C;
    classDef external fill:#F2F2F2,stroke:#828282,stroke-dasharray: 5 5;
    classDef config fill:#E8F0FE,stroke:#4B9CE2;
    classDef cicd fill:#F5E6FF,stroke:#8E44AD;
```
