# thrasher-corp/gocryptotrader architecture

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

- Interactive diagram: https://gitdiagram.com/thrasher-corp/gocryptotrader
- Repository: https://github.com/thrasher-corp/gocryptotrader

## Overview

##### Main Components
- Frontend/UI Layer:
- Web GUI (found under the “web” directory with Angular code, assets, and nginx configuration).
- CLI tools (gctcli, gctscript, etc., under “cmd/gctcli”, “cmd/gen_cert”, and others).
- API & Communication:
- gRPC service and JSON RPC proxy (see “gctrpc”).
- REST & Websocket interfaces integrated in exchange adapters.
- Core Trading Engine:
- Core engine modules (in “engine”), which include the event manager, order manager, portfolio manager, and communication managers.
- Backtesting module (“backtester”) that allows simulation of trading strategies.
- Exchange Integration Layer:
- A large “exchanges” module which modularizes communication and market data retrieval from multiple cryptocurrency exchanges.
- Unified exchange API (various directories inside “exchanges” for Binance, Bitfinex, etc.).
- Data & Persistence:
- Database support (the “database” directory) featuring drivers (Postgres, SQLite3), migrations, and repository abstractions.
- Configuration & Auxiliary Services:
- Configuration management (the “config” directory) with encrypted config files.
- Communication services (Slack, SMS, Telegram – under “communications”).
- Logging and diagnostics (in “log”, “common”, etc.).
- Utility libraries (in “common”, “currency”, “sqlboiler_example.json”, etc.).
- Scripting & Extensions:
- Scripting support (“gctscript”) for defining and executing custom trading strategies.
- Plugin system for exchange strategies (“backtester/plugins/strategies”).

##### Relationships and Interactions
- The UI layer (web front end and CLI) acts as clients that send commands/queries.
- These commands are processed by the Core Trading Engine (order management, event manager, portfolio manager) and might route through the gRPC/JSON-RPC API (exposed via “gctrpc”).
- The Engine in turn relies on the Exchange Integration Layer to communicate with external exchanges through REST/websocket interfaces.
- All modules use a unified configuration system, and access the persistence layer (database) to store trade history, orders, and other data.
- Additionally, communications modules are used to send alerts or notifications (via Slack, SMS, Telegram) when key events occur (managed under “communications”).
- The backtesting module similarly leverages the engine’s simulation capabilities upon historical data (in “backtester”) to test trading strategies.

##### Architectural Patterns/Design Principles
- Modularity: Each major function (exchange integrations, engine components, communication, configuration) is placed in its own directory/module.
- Layer separation: Different layers – UI/CLI, API/Service, Business Logic (Engine), Data Access – are clearly separated.
- Interface-based design: Common interfaces unify interactions between disparate exchange implementations and utility components.
- Plug-in/Extension: The strategy and scripting modules show how third-party code or new trading strategies can be added.
- Configurability: Encrypted config files and versioned configuration support (observed in “config/versions”) enhance maintainability.

##### Additional Elements to Highlight
- That the project allows for plug-and-play extensions particularly in the exchange interfaces and trading strategies.
- A note regarding build configurations (like enabling Sonic for JSON processing) in a “Configuration Options” section.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        WF["Web Frontend"]:::frontend
        CLI["CLI Tools"]:::frontend
    end

    %% API & Communication
    subgraph "API & Communication"
        RPC["gRPC/JSON RPC API"]:::api
    end

    %% Core Trading Engine
    subgraph "Core Trading Engine"
        ENG["Core Trading Engine\n(Order Manager, Event Manager, Portfolio Manager)"]:::engine
    end

    %% Exchange Integration
    subgraph "Exchange Integration"
        EX["Exchange Integration\n(Binance, Bitfinex, etc.)"]:::exchange
    end

    %% Data & Persistence
    subgraph "Data & Persistence"
        DB["Database\n(Postgres, SQLite3)"]:::database
    end

    %% Configuration & Auxiliary Services
    subgraph "Configuration & Auxiliary Services"
        CONF["Configuration Management"]:::config
        COMM["Communication Services\n(Slack, SMS, Telegram)"]:::aux
    end

    %% Scripting & Extensions
    subgraph "Scripting & Extensions"
        SCRIPT["Scripting Support"]:::scripting
        PLUG["Plugin System for Trading Strategies"]:::plugin
        BACKTEST["Backtesting Module"]:::backtest
    end

    %% Data Flow Connections
    WF -->|"sendsCommand"| RPC
    CLI -->|"sendsCommand"| RPC
    RPC -->|"processesRequest"| ENG
    ENG -->|"fetchMarketData"| EX
    ENG -->|"storesData"| DB
    ENG -->|"readsConfig"| CONF
    ENG -->|"sendsAlerts"| COMM
    ENG -->|"runsSimulation"| BACKTEST
    ENG -->|"executesScript"| SCRIPT
    SCRIPT -->|"usesPlugin"| PLUG

    %% Click Events
    click WF "https://github.com/thrasher-corp/gocryptotrader/tree/master/web"
    click CLI "https://github.com/thrasher-corp/gocryptotrader/tree/master/cmd/gctcli"
    click RPC "https://github.com/thrasher-corp/gocryptotrader/tree/master/gctrpc"
    click ENG "https://github.com/thrasher-corp/gocryptotrader/tree/master/engine"
    click BACKTEST "https://github.com/thrasher-corp/gocryptotrader/tree/master/backtester"
    click EX "https://github.com/thrasher-corp/gocryptotrader/tree/master/exchanges"
    click DB "https://github.com/thrasher-corp/gocryptotrader/tree/master/database"
    click CONF "https://github.com/thrasher-corp/gocryptotrader/tree/master/config"
    click COMM "https://github.com/thrasher-corp/gocryptotrader/tree/master/communications"
    click SCRIPT "https://github.com/thrasher-corp/gocryptotrader/tree/master/gctscript"
    click PLUG "https://github.com/thrasher-corp/gocryptotrader/tree/master/backtester/plugins/strategies"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef api fill:#A9DFBF,stroke:#1D8348,stroke-width:2px;
    classDef engine fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef exchange fill:#F5CBA7,stroke:#C0392B,stroke-width:2px;
    classDef database fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
    classDef config fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
    classDef aux fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;
    classDef scripting fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef plugin fill:#EBDEF0,stroke:#7D3C98,stroke-width:2px;
    classDef backtest fill:#D1F2EB,stroke:#27AE60,stroke-width:2px;
```
