# joni0108/mql5-sdk architecture

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

- Interactive diagram: https://gitdiagram.com/joni0108/mql5-sdk
- Repository: https://github.com/joni0108/mql5-sdk

## Overview

##### Project Type & Purpose
- This is an open-source SDK/framework for developing Expert Advisors (EAs), indicators, and scripts in MQL5 (MetaTrader 5’s language).
- It provides a stable, modular API on top of native MQL5 features, grouping functionality into packages, modules, and classes to simplify EA development and extension.

##### File-Structure Analysis
- Top-Level:
- modules/       ← All public packages & modules (mql5, network, terminal, apis, concepts, utils)
- internal/      ← Core utilities (enums, error handling) used by multiple modules
- sdk.mqh        ← Root “umbrella” include that pulls in everything
- docs/          ← Documentation for users and each module
- .github, README, CHANGELOG, LICENSE, CONTRIBUTING

- Patterns:
- Package-Module-Class hierarchy under modules/
- Single entry point: modules/mql5.mqh (the “mql” package) that auto-imports submodules
- internal/ as a shared library of common definitions

##### README Insights
- Emphasis on stable, backward-compatible API versions (semantic versioning)
- Installation target: copy `.mqh` headers into MetaTrader’s Include folder, `.dll` files into Libraries
- Modular imports: users can include entire SDK or cherry-pick modules

a. Main Components
- MQL5-SDK Core (sdk.mqh)
- Package Layers:
– MQL Package: account, terminal, market, trade, files modules
– Network Package: web-requests, sockets, JSON serialization
– Terminal Package: UI simulation (clicks, keymap, login)
– APIs Package: Discord, Telegram, Notion, etc.
– Concepts Package: trading patterns, zones, liquidity, trend detection
– Utils Package: logging, backtesting support, reporting, tools
- Internal Layer: enums, errors, shared macros
- Host Environment: Metatrader 5 (compiler, runtime), file system, network stack, external services

b. Relationships & Interactions
- sdk.mqh → imports Internal Layer + selected modules
- Modules → depend on Internal Layer (enums, error handling)
- MQL Package modules → call native MQL5 API under the hood
- Network & APIs → call Metatrader network functions / DLLs to reach external services
- Utils → used by other packages (e.g., logging by any module; backtest by trading modules)
- Host Environment ←→ SDK (compile-time includes, runtime interactions)

c. Architectural Patterns & Principles
- Layered Architecture:
– Core/Internal at the bottom
– Functional Packages in the middle
– SDK Entry Point at top
- Modular Design: each package is self-contained, can be included individually
- Semantic Versioning: clear boundary between stable vs breaking changes
- Separation of Concerns: trading logic, network, UI simulation, and utilities are distinct

d. Key Technologies & Libraries
- MQL5 Language & Native API
- .mqh include files (header-only modules)
- DLLs (for advanced features, copied into /libraries)
- JSON serialization, HTTP sockets (network module)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point
    SDK["sdk.mqh\n(Entry Point)"]:::entry

    %% Package Layers
    subgraph "Packages"
        direction TB
        subgraph "MQL Package" 
            direction TB
            MQLEntry["modules/mql5.mqh\n(Package Entry)"]:::package
            Account["account.mqh"]:::package
            Files["files.mqh"]:::package
            Market["market.mqh"]:::package
            TerminalMod["terminal.mqh"]:::package
            Trade["trade.mqh"]:::package
            subgraph "Files Deps"
                direction TB
                CSV["csv-file5.mqh"]:::package
                Text["text-file5.mqh"]:::package
            end
            subgraph "Trade Deps"
                direction TB
                TradeDep["trade5.mqh"]:::package
            end
        end

        subgraph "Utils Package"
            direction TB
            Logs["logs.mqh"]:::package
        end

        subgraph "Network Package"
            direction TB
            NetReq["web-requests"]:::package
            Sockets["sockets"]:::package
            JSON["json"]:::package
        end

        subgraph "APIs Package"
            direction TB
            Discord["Discord"]:::package
            Telegram["Telegram"]:::package
            Notion["Notion"]:::package
        end

        subgraph "Concepts Package"
            direction TB
            Patterns["trading patterns"]:::package
            Zones["zones"]:::package
            Liquidity["liquidity"]:::package
            Trend["trend detection"]:::package
        end
    end

    %% Internal Layer
    subgraph "Internal Layer" 
        direction TB
        Enums["enums.mqh"]:::internal
        Errors["errors.mqh"]:::internal
    end

    %% Host Environment Boundary
    subgraph "Metatrader 5 Runtime"
        direction TB
        NativeAPI["Native MQL5 API"]:::external
        FileSystem["File System"]:::external
        ExternalSvc["External Services"]:::external
    end

    %% Dependencies / Relationships
    SDK -->|"#include imports"| MQLEntry
    SDK -->|"#include imports"| Logs
    SDK -->|"#include imports"| NetReq
    SDK -->|"#include imports"| Discord
    SDK -->|"#include imports"| Patterns

    MQLEntry -->|"includes"| Account
    MQLEntry -->|"includes"| Files
    MQLEntry -->|"includes"| Market
    MQLEntry -->|"includes"| TerminalMod
    MQLEntry -->|"includes"| Trade

    Account -->|"depends on"| Enums
    Files -->|"depends on"| Enums
    Market -->|"depends on"| Enums
    TerminalMod -->|"depends on"| Enums
    Trade -->|"depends on"| Enums

    Account -->|"depends on"| Errors
    Files -->|"depends on"| Errors
    Market -->|"depends on"| Errors
    TerminalMod -->|"depends on"| Errors
    Trade -->|"depends on"| Errors

    Files -->|"includes"| CSV
    Files -->|"includes"| Text
    Trade -->|"includes"| TradeDep

    Account -->|"calls"| NativeAPI
    Market -->|"calls"| NativeAPI
    TerminalMod -->|"calls"| NativeAPI
    Trade -->|"calls"| NativeAPI

    Files -->|"writes to"| FileSystem

    NetReq -->|"runtime HTTP"| ExternalSvc
    JSON -->|"serializes"| NetReq
    Sockets -->|"runtime sockets"| ExternalSvc

    Discord -->|"uses network"| ExternalSvc
    Telegram -->|"uses network"| ExternalSvc
    Notion -->|"uses network"| ExternalSvc

    Logs -->|"used by"| Account
    Logs -->|"used by"| Trade
    Logs -->|"used by"| Patterns

    %% Click Events
    click SDK "https://github.com/joni0108/mql5-sdk/blob/main/sdk.mqh"
    click MQLEntry "https://github.com/joni0108/mql5-sdk/blob/main/modules/mql5.mqh"
    click Enums "https://github.com/joni0108/mql5-sdk/blob/main/internal/enums.mqh"
    click Errors "https://github.com/joni0108/mql5-sdk/blob/main/internal/errors.mqh"
    click Account "https://github.com/joni0108/mql5-sdk/blob/main/modules/mql5/account.mqh"
    click Files "https://github.com/joni0108/mql5-sdk/blob/main/modules/mql5/files.mqh"
    click CSV "https://github.com/joni0108/mql5-sdk/blob/main/modules/mql5/deps/csv-file5.mqh"
    click Text "https://github.com/joni0108/mql5-sdk/blob/main/modules/mql5/deps/text-file5.mqh"
    click Market "https://github.com/joni0108/mql5-sdk/blob/main/modules/mql5/market.mqh"
    click TerminalMod "https://github.com/joni0108/mql5-sdk/blob/main/modules/mql5/terminal.mqh"
    click Trade "https://github.com/joni0108/mql5-sdk/blob/main/modules/mql5/trade.mqh"
    click TradeDep "https://github.com/joni0108/mql5-sdk/blob/main/modules/mql5/deps/trade5.mqh"
    click Logs "https://github.com/joni0108/mql5-sdk/blob/main/modules/utils/logs.mqh"

    %% Styles
    classDef entry fill:#f9f,stroke:#333,stroke-width:2px;
    classDef package fill:#bbf,stroke:#333,stroke-width:1px;
    classDef internal fill:#ccc,stroke:#333,stroke-width:1px;
    classDef external fill:#cfc,stroke:#333,stroke-width:1px;
```
