# arthurarthurarthur0817/stock-ii architecture

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

- Interactive diagram: https://gitdiagram.com/arthurarthurarthur0817/stock-ii
- Repository: https://github.com/arthurarthurarthur0817/stock-ii

## Overview

##### Project type and purpose
- From the README and file tree, this is a full-stack Flask web application (“Stock”) for stock trading and analysis.
- It includes user management (register/login), real-time and historical trade execution (buy/sell), portfolio tracking, simulation, risk analysis, news integration, and a library of trading strategies.

##### File structure
Top-level:
- app.py – Flask application entrypoint, route definitions.
- db.py – database connection and ORM or raw-SQL helper.
- trade.py – encapsulates core trading logic (execute buy/sell, update portfolio/transactions).
- static/ – front-end assets (CSS, JS, images, Bootstrap/SCSS libraries).
- templates/ – Jinja2 HTML templates (views for account, login, register, trade, transaction history, analysis pages).
- data/ – CSV files for historical price data.
- strategies/ – individual Python modules implementing various technical-analysis trading strategies.
- Additional scripts (gemini*.py, simulation.py, risk_analysis.py, news.py, history_trading.py, etc.) implement backtesting, simulations, machine-learning, news aggregation, risk profiling.

##### README for additional insights
- The MySQL DDL indicates user balance, per-stock holdings, and transaction history.
- Static and templates refer to Bootstrap CSS/JS for styling and interactivity.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Browser"]:::frontend
        Templates["Templates (Jinja2 HTML)"]:::frontend
        StaticAssets["Static Assets (CSS/JS/Images)"]:::frontend
        ContactHandler["Mail Handler"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        FlaskApp["Flask App (app.py)"]:::backend
        Auth["Authentication & User Management"]:::backend
        TradeEngine["Trade Engine"]:::backend
        Backtesting["Backtesting & Simulation"]:::backend
        StrategyLib["Strategy Library"]:::backend
        NewsAgg["News Aggregator"]:::backend
        MLModules["ML & Gemini Modules"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MySQLDB[(MySQL Database)]:::data
        subgraph "CSV Data Store"
            direction TB
            CSV1["0050.csv"]:::data
            CSV2["1301.csv"]:::data
            CSV3["2344.csv"]:::data
            CSV4["2603.csv"]:::data
            CSV5["2882.csv"]:::data
        end
    end

    %% Connections
    Browser -->|HTTP requests| FlaskApp
    FlaskApp -->|renders| Templates
    FlaskApp -->|serves| StaticAssets
    Browser -->|contact form| ContactHandler

    FlaskApp -->|uses| Auth
    FlaskApp -->|invokes| TradeEngine
    FlaskApp -->|invokes| Backtesting
    FlaskApp -->|loads| StrategyLib
    FlaskApp -->|invokes| NewsAgg
    FlaskApp -->|uses| MLModules

    Auth -->|read/write| MySQLDB
    TradeEngine -->|read/write| MySQLDB
    Backtesting -->|reads| CSV1 & CSV2 & CSV3 & CSV4 & CSV5
    StrategyLib -->|reads| CSV1 & CSV2 & CSV3 & CSV4 & CSV5
    NewsAgg -->|optional external API| NewsAgg

    %% Click Events
    click Templates "https://github.com/arthurarthurarthur0817/stock-ii/tree/main/templates/"
    click StaticAssets "https://github.com/arthurarthurarthur0817/stock-ii/tree/main/static/"
    click ContactHandler "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/static/mail/contact.php"
    click ContactHandler "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/static/mail/contact.js"
    click FlaskApp "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/app.py"
    click Auth "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/app.py"
    click Auth "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/db.py"
    click TradeEngine "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/trade.py"
    click TradeEngine "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/risk_analysis.py"
    click Backtesting "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/simulation.py"
    click Backtesting "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/gemini_simulation.py"
    click Backtesting "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/history_trading.py"
    click StrategyLib "https://github.com/arthurarthurarthur0817/stock-ii/tree/main/strategies/"
    click NewsAgg "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/news.py"
    click MySQLDB "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/db.py"
    click MLModules "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/gemini.py"
    click MLModules "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/gemini_learn.py"
    click CSV1 "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/data/0050.csv"
    click CSV2 "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/data/1301.csv"
    click CSV3 "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/data/2344.csv"
    click CSV4 "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/data/2603.csv"
    click CSV5 "https://github.com/arthurarthurarthur0817/stock-ii/blob/main/data/2882.csv"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#333,stroke-width:1px
    classDef backend fill:#ABEBC6,stroke:#333,stroke-width:1px
    classDef data fill:#F9E79F,stroke:#333,stroke-width:1px
```
