# nishad2m8/btc-ticker architecture

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

- Interactive diagram: https://gitdiagram.com/nishad2m8/btc-ticker
- Repository: https://github.com/nishad2m8/btc-ticker

## Overview

##### Project type and purpose
- This is an embedded IoT/UI application targeting the LilyGo T-Display-AMOLED ESP32 board (PlatformIO project). Its purpose is to fetch real-time Bitcoin data over Wi-Fi (via Binance WebSocket and NTP), render charts and text on an AMOLED display using the LVGL graphics library, and allow Wi-Fi provisioning via a QR code.

##### File structure
- Top-level:
- boards/: custom PlatformIO board definition.
- lib/: reusable libraries:
– LV_Helper: LVGL setup/wrappers and configuration.
– LilyGo_AMOLED: low-level display driver and board abstractions.
– RM67162_AMOLED_SPI: SPI driver for the RM67162 OLED panel.
– initSequence: display initialization sequences.
– ui/: LVGL-based UI components (screens, fonts, images, events).
- src/: application code:
– BinanceWebSocket.{cpp,h}: manages WebSocket connection to Binance.
– BinanceCandleStick.{cpp,h}: fetches candlestick data.
– WiFiProvHelper/Screen.{cpp,h}: Wi-Fi provisioning logic & UI.
– TimeHelper.{cpp,h}: NTP client and time zone logic.
– Config.h: user-configurable settings (e.g., time zone).
– main.cpp: `setup()` and `loop()`, glue code that initializes hardware, LVGL, Wi-Fi, data streams, and drives UI updates.
- platformio.ini: build configuration, board selection, library dependencies.

##### Extract insights from the README
- Graphics: LVGL library for UI.
- Connectivity: Wi-Fi setup via QR code (provisioning); real-time data via Binance WebSocket; NTP for clock.
- LilyGo AMOLED, driver RM67162 over SPI.
- Features: live Bitcoin price ticker, candlestick chart, date/time, Wi-Fi provisioning.

##### Final advice
- Be exhaustive: break out each library as its own block if it encapsulates significant functionality.
- Initialization sequence (boot → drivers → LVGL → provisioning/data streams).
- Event channels (e.g., callback lines) distinctly from synchronous calls.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Services
    subgraph "External Services"
        direction TB
        BinanceAPI["Binance WebSocket API"]:::external
        NTPServer["NTP Server"]:::external
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        MainApp["Main Application<br/>(main.cpp)"]:::logic
        Config["Configuration<br/>(Config.h)"]:::logic
        WebSocketClient["Binance WebSocket Client<br/>(BinanceWebSocket.cpp)"]:::logic
        CandleProcessor["Candlestick Data Processor<br/>(BinanceCandleStick.cpp)"]:::logic
        TimeClient["NTP Time Client & Logic<br/>(TimeHelper.cpp)"]:::logic
        WiFiProvLogic["Wi-Fi Provisioning Logic<br/>(WiFiProvHelper.cpp)"]:::logic
        WiFiProvUI["Wi-Fi Provisioning Screen<br/>(WiFiProvScreen.cpp)"]:::logic
        UIEngine["UI Library & Screens<br/>(ui.c)"]:::ui
    end

    %% Drivers & Middleware Layer
    subgraph "Drivers & Middleware Layer"
        direction TB
        InitSeq["Init Sequences<br/>(initSequence.cpp)"]:::driver
        BoardAbstr["Board Abstraction<br/>(LilyGo_AMOLED.cpp)"]:::driver
        DisplayDrv["Display Driver<br/>(RM67162_AMOLED_SPI.cpp)"]:::driver
        LVHelper["LVGL Setup & Wrappers<br/>(LV_Helper.cpp)"]:::driver
        WiFiStack["ESP32 Wi-Fi Stack"]:::driver
    end

    %% Hardware
    subgraph "Hardware"
        direction TB
        ESP32["ESP32 Hardware<br/>(T-Display-AMOLED.json)"]:::hardware
    end

    %% Flows
    BinanceAPI -->|"push price updates"| WebSocketClient
    WebSocketClient -->|"process data"| CandleProcessor
    NTPServer -->|"sync time"| TimeClient

    CandleProcessor -->|"update events"| UIEngine
    TimeClient -->|"time events"| UIEngine

    UIEngine -->|"render"| LVHelper
    LVHelper -->|"draw calls"| DisplayDrv
    DisplayDrv -->|"SPI signals"| BoardAbstr
    BoardAbstr -->|"control signals"| ESP32

    MainApp -->|initialize| InitSeq
    InitSeq -->|init display| BoardAbstr
    MainApp -->|"setup LVGL"| LVHelper
    MainApp -->|"load UI"| UIEngine
    MainApp -->|"load config"| Config

    MainApp -->|start Wi-Fi AP| WiFiProvLogic
    WiFiProvLogic -->|display QR| WiFiProvUI
    WiFiProvUI -->|user scans| WiFiProvLogic
    WiFiProvLogic -->|credentials| WiFiStack
    WiFiStack -->|connect| ESP32

    MainApp -->|start services| WebSocketClient
    MainApp -->|start services| TimeClient

    %% Click Events
    click ESP32 "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/boards/T-Display-AMOLED.json"
    click DisplayDrv "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/lib/RM67162_AMOLED_SPI/RM67162_AMOLED_SPI.cpp"
    click BoardAbstr "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/lib/LilyGo_AMOLED/LilyGo_AMOLED.cpp"
    click LVHelper "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/lib/LV_Helper/LV_Helper.cpp"
    click UIEngine "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/lib/ui/src/ui.c"
    click WebSocketClient "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/src/BinanceWebSocket.cpp"
    click CandleProcessor "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/src/BianceCandleStick.cpp"
    click TimeClient "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/src/TimeHelper.cpp"
    click WiFiProvLogic "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/src/WiFiProvHelper.cpp"
    click WiFiProvUI "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/src/WiFiProvScreen.cpp"
    click Config "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/src/Config.h"
    click MainApp "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/src/main.cpp"
    click InitSeq "https://github.com/nishad2m8/btc-ticker/blob/master/PIO-T-Display-s3-pro/lib/initSequence/initSequence.cpp"

    %% Styles
    classDef hardware fill:#CCCCCC,stroke:#444,stroke-width:1px
    classDef driver fill:#ADD8E6,stroke:#444,stroke-width:1px
    classDef logic fill:#90EE90,stroke:#444,stroke-width:1px
    classDef ui fill:#D8BFD8,stroke:#444,stroke-width:1px
    classDef external fill:#FFA500,stroke:#444,stroke-width:1px
```
