# dforce-network/dtoken architecture

> Architecture diagram of the GitHub repository dforce-network/dtoken, 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/dforce-network/dtoken
- Repository: https://github.com/dforce-network/dtoken

## Overview

##### Main Components
- Smart Contracts Layer:
- “contracts” directory which is composed of subdirectories (assets, helper, interface, library, mock) representing various smart contract modules.
- Contracts such as the DToken Controller and various Handler contracts (Internal, Aave, Compound, USR, etc.).

- Migration/Deployment Scripts:
- “migrations” folder which contains deployment scripts (e.g., 1_deploy_contracts.js, 3_deploy_dForce_implementation.js, etc.).
- Role of Buidler and Truffle in compiling, testing, and migrating the contracts.

- Testing Infrastructure:
- “test” directory that covers unit and integration tests for smart contracts (e.g., testAaveHandler.js, testDToken.js, etc.).
- This component to illustrate how robustness is verified across different protocol integrations.

- Web Frontend (dApp):
- “web-dapp” directory as a separate, but connected, frontend layer.
- This frontend (built with React, as suggested by files like App.js, index.js, and React component folders) interacts with the blockchain and smart contracts (through imported ABIs, serviceWorker, and utility scripts).

- External Infrastructure & Environment:
- Connections to external services like Infura (via INFURA_APIKEY in the .env configuration).
- Blockchain networks (Ethereum Mainnet, Kovan, and BSC) where the smart contracts are deployed.

##### Relationships and Interactions
- That the Testing Infrastructure interacts directly with both the smart contracts and migration scripts to ensure system correctness.
- Blockchain External Networks component with the Smart Contracts layer, highlighting that it’s deployed on these networks.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly delineate between smart contract code, deployment scripts, tests, and frontend dApp.
- Modular Components: Emphasize the modular structure of smart contracts (evident from the multiple directories under “contracts”) and how each module (e.g., assets, handlers, interfaces) encapsulates a particular functionality.
- External Integration: Mark segments showing how the system communicates with external services like Infura and different blockchain networks.

##### Relevant Technologies and Frameworks
- Buidler and Truffle: Note these tools under the deployment and local development portion.
- React and Webpack: Under the “web-dapp” component, emphasize use of React (files such as App.js, index.js) and associated build tools.
- Testing frameworks and CI/CD: Reference files like .circleci/config.yml and jest configuration files from the web-dapp configuration to show that automated testing and integration (CircleCI) are in use.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Smart Contracts Layer
    subgraph "Smart Contracts Layer"
        SC["Smart Contracts – DToken Controller & Handlers"]:::smart
    end

    %% Deployment & Migration Scripts
    subgraph "Deployment & Migration Scripts"
        MIG["Deployment & Migration Scripts"]:::deploy
    end

    %% Testing Infrastructure
    subgraph "Testing Infrastructure"
        TEST["Testing Suite"]:::test
    end

    %% Web Frontend (React dApp)
    subgraph "Web Frontend (React dApp)"
        WEB["Web Frontend (React dApp)"]:::frontend
    end

    %% External Integration & Environment Configuration
    subgraph "External Integration"
        EXT["Blockchain Networks\n(Ethereum Mainnet, Kovan, BSC)"]:::external
        subgraph "Configuration"
            ENV[".example.env"]:::config
            BU["buidler.config.js"]:::config
            TR["truffle-config.js"]:::config
        end
    end

    %% Connections
    WEB -->|"sendsTxn"| EXT
    EXT -->|"accessContracts"| SC
    MIG -->|"deploys"| SC
    TEST -->|"testsContracts"| SC
    TEST -->|"testsDeploy"| MIG
    ENV -->|"setsNetwork"| EXT
    BU -->|"configDeploy"| MIG
    TR -->|"configDeploy"| MIG

    %% Click Events
    click SC "https://github.com/dforce-network/dtoken/tree/master/contracts/"
    click MIG "https://github.com/dforce-network/dtoken/tree/master/migrations/"
    click TEST "https://github.com/dforce-network/dtoken/tree/master/test/"
    click WEB "https://github.com/dforce-network/dtoken/tree/master/web-dapp/"
    click ENV "https://github.com/dforce-network/dtoken/blob/master/.example.env"
    click BU "https://github.com/dforce-network/dtoken/blob/master/buidler.config.js"
    click TR "https://github.com/dforce-network/dtoken/blob/master/truffle-config.js"

    %% Styles
    classDef smart fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef deploy fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef test fill:#577590,stroke:#fff,stroke-width:2px;
    classDef frontend fill:#f94144,stroke:#333,stroke-width:2px;
    classDef external fill:#43aa8b,stroke:#333,stroke-width:2px;
    classDef config fill:#277da1,stroke:#fff,stroke-width:2px;
```
