# corfucinas/crypto-candlesticks architecture

> Architecture diagram of the GitHub repository corfucinas/crypto-candlesticks, 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/corfucinas/crypto-candlesticks
- Repository: https://github.com/corfucinas/crypto-candlesticks

## Overview

##### Project Overview and Main Purpose
- This project is a command-line tool built with Python that facilitates downloading and processing cryptocurrency candlestick data from exchanges – currently, Bitfinex is supported.
- The tool gathers data (candlestick values like open, high, low, close, volume, timestamp) and converts/stores it in multiple file formats (CSV, SQLite, pickle) for analysis.
- The CLI is implemented using Click and there is clear separation between data collection, processing, and storage.

##### Analyzing the File Structure
- Top-Level Directories:
- “src” contains the core application code.
- “docs” holds the documentation (including reStructuredText files that detail various modules and usage).
- “tests” include test modules indicating the project is well-tested.
- “examples” showcase sample data files for demonstration.
- “.github” holds CI/CD and GitHub workflow configurations.
- main.py: Likely the entry point that initializes the CLI.
- get_data.py: Contains logic to fetch candlestick data.
- database.py: Contains routines to convert and store data in different file formats.
- exchanges (with bitfinex.py): Implements the integration with Bitfinex.
- symbols (with quote_currencies.py and time_intervals.py): Handles symbol-related processing.
- text_console.py: Likely manages console output for user interactions.
- There are even some playful directories and files (e.g., src/🎁) that might be related to additional features or packaging.

##### Key Architectural Components and Their Roles
a. User Interface Layer:
- CLI Interface: Based on Click, handling user prompts and command-line argument parsing (activated mainly by the main.py and text_console.py).
b. Data Retrieval/Processing Layer:
- Data Collector Module: The get_data.py module orchestrates data fetching.
- Exchanges Module: Under src/crypto_candlesticks/exchanges (specifically bitfinex.py) implementing the API calls.
- Symbols Module: Contains logic for validating and converting cryptocurrency symbols, base currencies, and time intervals.
c. Data Persistence/Conversion Layer:
- Database Module: Reads the retrieved data and provides functions to persist it as CSV, SQLite, or pickle files.
d. External Dependencies and Services:
- Bitfinex Exchange API: The external resource from which the candlestick data is fetched.
- Documentation, tests, CI/CD configurations (indicating adherence to quality standards).

- Data Retrieval Flow:
- Symbols and Parameter Processing:
- A module labeled “Symbols Module (quote_currencies, time_intervals)” linked to “Data Collector” to indicate preprocessing or validation of the currency and interval inputs.
- Data Storage and Conversion:
- Console Output:
- “Text Console (text_console.py)” connected back to the CLI layer for displaying user feedback or results.
- Testing and CI/CD:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        CLI["CLI Interface (Click)"]:::ui
        MAIN["Main Module (main.py)"]:::ui
        TEXT["Text Console (text_console.py)"]:::ui
    end

    %% Data Retrieval and Processing Layer
    subgraph "Data Retrieval and Processing Layer"
        DC["Data Collector (get_data.py)"]:::logic
        BITFINEX["Bitfinex API Integration (exchanges/bitfinex.py)"]:::logic
        QUOTE["Symbols Module - Quote Currencies (quote_currencies.py)"]:::logic
        INTERVAL["Symbols Module - Time Intervals (time_intervals.py)"]:::logic
    end

    %% Data Persistence and Storage Layer
    subgraph "Data Persistence and Storage Layer"
        DB["Database Module (database.py)"]:::storage
        CSV["CSV Output"]:::storage
        SQLITE["SQLite3 Output"]:::storage
        PICKLE["Pickle Output"]:::storage
    end

    %% External Services
    subgraph "External Services"
        BITFINEX_API["Bitfinex Exchange API"]:::external
    end

    %% Quality Assurance
    subgraph "Quality Assurance"
        TESTS["Tests"]:::qa
        GITHUB["GitHub Workflows"]:::qa
    end

    %% Connections in UI Layer
    CLI -->|"start"| MAIN
    MAIN -->|"display_output"| TEXT
    TEXT -->|"feedback"| CLI

    %% Connections in Data Flow
    MAIN -->|"initiate_collection"| DC
    DC -->|"api_calls_for_candlestick_data"| BITFINEX
    BITFINEX -->|"fetch_data"| BITFINEX_API
    DC -->|"validate"| QUOTE
    DC -->|"validate"| INTERVAL
    DC -->|"process_and_store"| DB

    %% Connections for Data Persistence
    DB -->|"CSV"| CSV
    DB -->|"SQLite3"| SQLITE
    DB -->|"Pickle"| PICKLE

    %% Quality Assurance Connections
    TESTS ---|"tests_against"| MAIN
    GITHUB ---|"CI_CD"| MAIN

    %% Click Events
    click MAIN "https://github.com/corfucinas/crypto-candlesticks/blob/master/src/crypto_candlesticks/main.py"
    click TEXT "https://github.com/corfucinas/crypto-candlesticks/blob/master/src/crypto_candlesticks/text_console.py"
    click DC "https://github.com/corfucinas/crypto-candlesticks/blob/master/src/crypto_candlesticks/get_data.py"
    click BITFINEX "https://github.com/corfucinas/crypto-candlesticks/blob/master/src/crypto_candlesticks/exchanges/bitfinex.py"
    click QUOTE "https://github.com/corfucinas/crypto-candlesticks/blob/master/src/crypto_candlesticks/symbols/quote_currencies.py"
    click INTERVAL "https://github.com/corfucinas/crypto-candlesticks/blob/master/src/crypto_candlesticks/symbols/time_intervals.py"
    click DB "https://github.com/corfucinas/crypto-candlesticks/blob/master/src/crypto_candlesticks/database.py"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef logic fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef storage fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef external fill:#FF6347,stroke:#000,stroke-width:1px;
    classDef qa fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
