# apex-protocol/core architecture

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

- Interactive diagram: https://gitdiagram.com/apex-protocol/core
- Repository: https://github.com/apex-protocol/core

## Overview

##### Project’s Main Components
- Core Smart Contracts: These are contained in the contracts directory and its subdirectories (e.g., contracts/core, contracts/interfaces, contracts/libraries, contracts/mocks, contracts/token, contracts/utils). Indicate how the core contracts implement the main DEX functionalities.
- Deployment & Scripts: In the scripts directory you find multiple deploy and verify scripts that manage deployment for different parts of the protocol (e.g., deploy_apex.js, deploy_fee_treasury.js, deploy_limit_order.js, deploy_migrator.js, etc.). These represent the orchestration layer for interacting with blockchain networks.
- Testing Suite: The test directory (with tests for different modules such as core functionality (amm.js, margin.js, etc.), limit orders, and shared utilities) reveals that a comprehensive testing framework is in place.
- Configuration & Environment: Files like hardhat.config.js, .env.example, package.json, and other configuration files set up the development and deployment environments.
- Documentation & Audit: The docs folder contains documentation such as audit_report.pdf which indicates security and compliance evaluation.

##### Relationships and Interactions
- The interactions among the smart contracts themselves (e.g., how the core contracts interact with interfaces such as UniswapV2 and UniswapV3 interfaces in contracts/interfaces).
- How deployment scripts trigger the initialization and linkage of these contracts on the blockchain.

##### Architectural Patterns & Design Principles
- Separation of contract logic into distinct modules (using folders like core, interfaces, libraries) which indicates modular design.
- Use of Hardhat as both a configuration and testing framework by adding a “Hardhat Environment” component that connects with deployment scripts and tests.

##### Relevant Technologies
- Smart Contracts (Solidity source files, grouped by purpose).
- Hardhat (configured through hardhat.config.js, including testing and deployment integration).
- NPM (via package.json, managing dependencies).
- External protocols (Uniswap interfaces placed under contracts/interfaces).

##### Elements
- Clearly labeled nodes for every major module: "Core Contracts", "Interfaces (UniswapV2/V3)", "Libraries", "Mocks & Utilities", "Deployment Scripts", and "Tests".
- Annotations that pinpoint technologies (e.g., Hardhat, npm, Solidity) and note any modular separation (e.g., the role of each contract folder).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Smart Contracts Modules"
        CC["Core Contracts"]:::contract
        IN["Interfaces (Uniswap)"]:::contract
        LB["Libraries"]:::contract
        MU["Mocks & Utilities"]:::contract
    end

    DS["Deployment Scripts"]:::scripts
    TF["Testing Framework"]:::tests
    CE["Configuration & Environment"]:::config
    DA["Documentation & Audit"]:::docs
    HE["Hardhat Environment"]:::environment
    EP["External Protocols (Uniswap)"]:::external

    %% Relationships
    DS -->|"deploys"| CC
    TF -->|"tests"| CC
    DS <-->|"uses"| CE
    DS -->|"runs-in"| HE
    TF -->|"runs-on"| HE
    CE -->|"configures"| HE
    IN -->|"integrates"| EP

    %% Click Events
    click CC "https://github.com/apex-protocol/core/tree/master/contracts/"
    click DS "https://github.com/apex-protocol/core/tree/master/scripts/"
    click TF "https://github.com/apex-protocol/core/tree/master/test/"
    click CE "https://github.com/apex-protocol/core/blob/master/hardhat.config.js"
    click DA "https://github.com/apex-protocol/core/blob/master/docs/audit_report.pdf"

    %% Styles
    classDef contract fill:#d9e8ff,stroke:#0066cc,stroke-width:2px;
    classDef scripts fill:#ffdead,stroke:#cc6600,stroke-width:2px;
    classDef tests fill:#ffe0e0,stroke:#cc0000,stroke-width:2px;
    classDef config fill:#e0ffe0,stroke:#008000,stroke-width:2px;
    classDef docs fill:#fffacd,stroke:#cd853f,stroke-width:2px;
    classDef external fill:#fff8dc,stroke:#daa520,stroke-width:2px;
    classDef environment fill:#e6e6fa,stroke:#800080,stroke-width:2px;
```
