# tondefi/staking-in-tact architecture

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

- Interactive diagram: https://gitdiagram.com/tondefi/staking-in-tact
- Repository: https://github.com/tondefi/staking-in-tact

## Overview

##### Main Components
- Smart Contract Logic – This includes the core contract files:
- contract.tact (the designated entry point for the staking contract)
- jetton.tact and message.tact (supporting logic for the jetton tokens and message handling)
- Deployment Mechanism – The deployment scripts and configuration files:
- sources/contract.deploy.Staking.ts (handles deploying the contract by invoking the Init() function)
- tact.config.json (ensures the correct configuration if the entry point file is renamed)
- package.json scripts (e.g., “yarn deploy”)
- Operational Scripts – Scripts facilitating runtime operations and interactions:
- sources/1_Transfer_Stake.ts (script that triggers a stake transfer from a jetton wallet to the staking contract)
- sources/2_TransferURL.ts (generates a URL for users to stake jettons, referring to a WalletV4 address)
- sources/utils/ (helper functions like deploy.ts, jetton-helpers.ts, and print.ts, which support deployment and contract interaction)
- Testing Suite – Automated testing is covered by:
- sources/contract.spec.ts (defines test cases and scenarios to ensure the contract behaves correctly)
- jest.config.js (configuration for running tests)
- Build Artifacts & Outputs – The compiled output artifacts and ABIs include:
- Multiple files in sources/output (ABI files, code (in various formats such as .boc, .fc, .fif), headers, metadata, etc. for different contract sample variants such as SampleJetton_JettonDefaultWallet, SampleJetton_SampleJetton, and SampleJetton_StakingContract)

##### Relationships and Interactions
- The deployment system (via contract.deploy.Staking.ts and tact.config.json) interacts directly with the smart contract logic (contract.tact) to package and deploy the contract on the blockchain.
- The operational scripts (1_Transfer_Stake.ts, 2_TransferURL.ts) provide an interface for users and developers to interact with the deployed contract.
- The tests (contract.spec.ts) run against the contract code ensuring that all behaviors (like staking transfers) are correctly implemented.
- Utilities in the sources/utils directory assist both deployment and interactions, abstracting common functions.
- Build, configuration, and package management (via package.json, tsconfig.json, jest.config.js, etc.) orchestrate the overall development lifecycle – from building, testing, to deploying.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The project clearly separates contract logic (Tact files) from operational scripts (TypeScript files) and testing scripts.
- Build and Deployment Workflow: There is a defined workflow – tests with yarn test, build with yarn build, deployment with yarn deploy – which is supported by configuration files and utilities.
- Modular Utilities: Helper files under sources/utils encapsulate common operational tasks.
- Output Artifacts: The output directory clearly distinguishes the generated artifacts from the source code, facilitating versioning and auditability.

- Mention any external services (for instance, if the contract is to be deployed to a blockchain network such as TON, you might note “Blockchain Node” or “TON Network API” to represent where the contract would run).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Smart Contract Layer
    subgraph "Smart Contract Layer"
        SC1["contract.tact"] 
        SC2["jetton.tact"]
        SC3["message.tact"]
    end

    %% Deployment & Configuration Layer
    subgraph "Deployment & Configuration Layer"
        DEP1["contract.deploy.Staking.ts"]
        DEP2["tact.config.json"]
        DEP3["package.json"]
    end

    %% Operational & Interaction Layer
    subgraph "Operational & Interaction Layer"
        OPR1["1_Transfer_Stake.ts"]
        OPR2["2_TransferURL.ts"]
        OPR3["utils"]
    end

    %% Testing Layer
    subgraph "Testing Layer"
        TEST1["contract.spec.ts"]
        TEST2["jest.config.js"]
    end

    %% Build Artifacts Layer
    subgraph "Build Artifacts Layer"
        BUILD["Output"]
    end

    %% External Node: Blockchain
    EXTERNAL["TON Blockchain"]

    %% Connections
    DEP1 -->|"deploys"| SC1
    DEP2 -->|"configures"| SC1
    DEP3 -->|"orchestrates"| DEP1

    OPR1 -->|"calls"| SC1
    OPR2 -->|"calls"| SC1
    OPR3 -->|"supports"| DEP1

    TEST1 -->|"tests"| SC1
    TEST2 -->|"tests"| SC1

    SC1 -->|"builds"| BUILD
    BUILD -->|"deployed to"| EXTERNAL

    %% Classes
    class SC1,SC2,SC3 sc
    class DEP1,DEP2,DEP3 deploy
    class OPR1,OPR2,OPR3 oper
    class TEST1,TEST2 test
    class BUILD build
    class EXTERNAL external

    %% Class Definitions with Colors
    classDef sc fill:#fce4ec,stroke:#ad1457,stroke-width:2px;
    classDef deploy fill:#e3f2fd,stroke:#1e88e5,stroke-width:2px;
    classDef oper fill:#e8f5e9,stroke:#43a047,stroke-width:2px;
    classDef test fill:#fff3e0,stroke:#fb8c00,stroke-width:2px;
    classDef build fill:#f3e5f5,stroke:#8e24aa,stroke-width:2px;
    classDef external fill:#e0f7fa,stroke:#0097a7,stroke-width:2px;

    %% Click Events for Smart Contract Logic
    click SC1 "https://github.com/tondefi/staking-in-tact/blob/main/sources/contract.tact"
    click SC2 "https://github.com/tondefi/staking-in-tact/blob/main/sources/jetton.tact"
    click SC3 "https://github.com/tondefi/staking-in-tact/blob/main/sources/message.tact"

    %% Click Events for Deployment Mechanism
    click DEP1 "https://github.com/tondefi/staking-in-tact/blob/main/sources/contract.deploy.Staking.ts"
    click DEP2 "https://github.com/tondefi/staking-in-tact/blob/main/tact.config.json"
    click DEP3 "https://github.com/tondefi/staking-in-tact/blob/main/package.json"

    %% Click Events for Operational & Interaction Layer
    click OPR1 "https://github.com/tondefi/staking-in-tact/blob/main/sources/1_Transfer_Stake.ts"
    click OPR2 "https://github.com/tondefi/staking-in-tact/blob/main/sources/2_TransferURL.ts"
    click OPR3 "https://github.com/tondefi/staking-in-tact/tree/main/sources/utils"

    %% Click Events for Testing Suite
    click TEST1 "https://github.com/tondefi/staking-in-tact/blob/main/sources/contract.spec.ts"
    click TEST2 "https://github.com/tondefi/staking-in-tact/blob/main/jest.config.js"

    %% Click Event for Build Artifacts
    click BUILD "https://github.com/tondefi/staking-in-tact/tree/main/sources/output"
```
