# mohadtt/chartscanai_autonomous architecture

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

- Interactive diagram: https://gitdiagram.com/mohadtt/chartscanai_autonomous
- Repository: https://github.com/mohadtt/chartscanai_autonomous

## Overview

##### Project type and purpose
- ChartScanAI is a specialized full-stack single-page application combining a Streamlit-based frontend with a Python backend that performs deep-learning inference.
- Its purpose is to automate pattern detection (Buy/Sell signals) in financial candlestick charts by loading/generating chart images, running them through a YOLOv8 model, and displaying results in real time.

##### File structure
Top level:
- app.py             – the Streamlit application entry point (UI + controller)
- requirements.txt   – Python dependencies (Streamlit, ultralytics, yfinance, mplfinance, etc.)
- packages.txt       – auxiliary package listing (possibly for deployment)
- weights/           – directory containing the trained model weights (custom_yolov8.pt)
- images/            – static assets (logo, sample outputs)
- README.md, LICENSE, .gitignore

Architectural hints:
- No separate “frontend” folder: UI and app logic are co-located in app.py.
- Model file under weights indicates a ML inference component.
- Use of yfinance & mplfinance implies an external data-fetching subcomponent.
- Streamlit handles both HTTP serving and UI rendering.

##### Extract additional insights from README
- Architecture: single monolithic service written in Python.
- Dependencies: YOLOv8 (ultralytics), Streamlit, yfinance, mplfinance.
- Workflow described: data acquisition → chart plotting → model inference → result rendering.

##### Main components and interactions
a. Components
1) User Interface (Streamlit Frontend)
2) Application Logic / Controller (app.py)
3) Model Inference Engine (YOLOv8 loaded from weights/custom_yolov8.pt)
4) Data Acquisition Module (yfinance)
5) Chart Generation Module (mplfinance)
6) Result Renderer (Streamlit canvas + Matplotlib overlays)
7) External Services (yfinance API)
8) Static Assets (images/, weights/)
9) Deployment Environment (e.g., Streamlit Cloud or Docker host)

b. Relationships & Data Flow
1) User interacts via browser → Streamlit Frontend
2) Frontend calls controller functions in app.py
3) Controller either:
- Fetches data from yfinance → Chart Generation Module → generates image
- Or accepts user-uploaded chart image
5) Controller sends annotated result to Result Renderer → streams back to UI
6) Logging & error-handling spans all stages

c. Architectural patterns & principles
- Layered approach: UI layer (Streamlit components) → Service/Controller layer (app logic) → Model/Inference layer → Data layer (external APIs + local weights)
- Single Responsibility: each module (data fetch, chart gen, inference, rendering) encapsulates one concern
- Scalability: weights and model code separated from UI code; easy to swap in updated models
- Extensibility: new chart-pattern models or data sources can be added with minimal change

d. Key technologies & frameworks
- Streamlit – UI & HTTP server
- Python – core language
- ultralytics YOLOv8 – object detection inference
- yfinance – stock/crypto data API
- mplfinance – candlestick charting
- Roboflow – used offline for annotation (not in runtime)

##### Diagramming recommendations
- Use rectangles for components (UI, Controller, Inference Engine, Data Module).
– Blue for UI components
– Green for backend services
– Orange for ML/model layers
– Gray for external services/storage
- Related components within containers (e.g., “app.py” container encapsulating Controller + Data Acquisition + Chart Generation + Result Renderer).

##### Detail
- Weights folder as an artifact the controller loads at startup.
- Environment details (Python, Streamlit Cloud/Docker) if relevant for deployment.

## Diagram (Mermaid)

```mermaid
flowchart TB
    User["User"]:::external
    UI["Streamlit Frontend UI"]:::ui
    subgraph "Application (app.py)"
        Controller["Controller\n(fetch_data, plot_chart,\nrun_model, display_output)"]:::backend
        DataAcq["Data Acquisition Module\n(yfinance)"]:::backend
        ChartGen["Chart Generation Module\n(mplfinance)"]:::backend
        ResultRenderer["Result Renderer\n(Streamlit + Matplotlib)"]:::backend
    end
    ModelInference["Model Inference Engine\n(YOLOv8)"]:::ml
    ExternalAPI["yfinance API"]:::external
    StaticWeights["Model Weights\n(weights/)"]:::storage
    StaticImages["Static Images\n(images/)"]:::storage
    Deployment["Deployment Environment\n(Streamlit Cloud/Docker)"]:::external

    User -->|"interacts via browser"| UI
    UI -->|"user actions"| Controller
    Controller -->|"fetch_data()"| DataAcq
    DataAcq -->|"fetch OHLC data"| ExternalAPI
    Controller -->|"plot_chart()"| ChartGen
    ChartGen -->|"generate chart image"| StaticImages
    Controller -->|"run_model()"| ModelInference
    ModelInference -->|"load model weights"| StaticWeights
    ModelInference -->|"return bounding boxes"| Controller
    Controller -->|"display_output()"| ResultRenderer
    ResultRenderer -->|"render annotated chart"| UI
    Deployment --> UI
    Deployment --> Controller

    click UI "https://github.com/mohadtt/chartscanai_autonomous/blob/main/app.py"
    click Controller "https://github.com/mohadtt/chartscanai_autonomous/blob/main/app.py"
    click DataAcq "https://github.com/mohadtt/chartscanai_autonomous/blob/main/app.py"
    click ChartGen "https://github.com/mohadtt/chartscanai_autonomous/blob/main/app.py"
    click ResultRenderer "https://github.com/mohadtt/chartscanai_autonomous/blob/main/app.py"
    click ModelInference "https://github.com/mohadtt/chartscanai_autonomous/blob/main/weights/custom_yolov8.pt"
    click StaticWeights "https://github.com/mohadtt/chartscanai_autonomous/tree/main/weights/"
    click StaticImages "https://github.com/mohadtt/chartscanai_autonomous/tree/main/images/"

    classDef ui fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1,stroke-width:1.5px;
    classDef backend fill:#E8F5E9,stroke:#66BB6A,color:#1B5E20,stroke-width:1.5px;
    classDef ml fill:#FFF3E0,stroke:#FFA726,color:#E65100,stroke-width:1.5px;
    classDef storage fill:#ECEFF1,stroke:#B0BEC5,color:#37474F,stroke-width:1.5px;
    classDef external fill:#F5F5F5,stroke:#BDBDBD,color:#424242,stroke-width:1.5px;
```
