# ton-community/contract-verifier-backend architecture

> Architecture diagram of the GitHub repository ton-community/contract-verifier-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ton-community/contract-verifier-backend
- Repository: https://github.com/ton-community/contract-verifier-backend

## Overview

##### Main System Components

a) API Layer
- Entry point through server.ts
- Request handling middleware (req-id-middleware.ts)
- Main controller logic (controller.ts, deploy-controller.ts)

b) Source Verification Layer
- Multiple verifier implementations:
- FunC verifier (func-source-verifier.ts)
- Fift verifier (fift-source-verifier.ts)
- Tact verifier (tact-source-verifier.ts)

c) External Integrations
- IPFS Storage (ipfs-code-storage-provider.ts)
- TON Blockchain interaction (ton-reader-client.ts)
- Smart Contract Wrappers (sources-registry.ts, verifier-registry.ts)

d) Binary Execution Layer
- Compiler version management (fetch-compiler-versions.ts)
- Binary execution handling (binaries.ts)

##### Data Flow Representation

a) Input Flow:
**Client Request → API Layer → Source Verification Layer → Binary Execution**

b) Output Flow:
**Binary Execution → Verification Result → IPFS Storage**
- → TON Blockchain (signed message)

##### External Dependencies

- TON Blockchain - Hexagon

##### Key Technical Elements

- Environment configuration (.env)
- Compiler versions support (shown in config.js)
- Security elements (private key signing)
- Smart contract interaction points

##### Specific Implementation Details

- Multiple compiler version support (0.2.0, 0.3.0, 0.4.0)
- Source code verification workflow
- Message signing process
- IPFS storage integration
- Smart contract interaction

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        A1["HTTP API (server.ts)"]:::internal
        A2["req-id Middleware (req-id-middleware.ts)"]:::middleware
        A3["Logger (logger.ts)"]:::middleware
    end

    %% Controller Module
    subgraph "Controller Module"
        C1["controller.ts"]:::internal
        C2["deploy-controller.ts"]:::internal
    end

    %% Compiler/Source Verification Module
    subgraph "Compiler/Source Verification Module"
        Comp1["binaries.ts"]:::internal
        Comp2["cell-builders.ts"]:::internal
        Comp3["utils.ts"]:::internal
        Comp4["Source Verifiers (src/source-verifier) \n[fift, func, tact]"]:::internal
    end

    %% Signature/Cryptography Module
    Sig["Signature/Cryptography Module"]:::internal

    %% External Integration Services
    subgraph "External Integration Services"
        IPS["IPFS Storage Provider (ipfs-code-storage-provider.ts)"]:::external
        subgraph "Wrappers & Registries"
            W1["source-item.ts"]:::internal
            W2["sources-registry.ts"]:::internal
            W3["verifier-registry.ts"]:::internal
        end
    end

    %% Deployment & Configuration Scripts
    subgraph "Deployment & Configuration"
        D1["deploy.sh"]:::deployment
        D2["config.js"]:::deployment
        D3["prepare_ton_release.js"]:::deployment
        D4["Deprecated Scripts (script/depracated)"]:::deployment
    end

    %% Flow arrows
    A1 --> A2
    A2 --> A3
    A3 --> C1
    C1 --> C2
    C2 --> Comp4
    %% Optionally show that utilities support the compiler
    Comp4 --- Comp1
    Comp4 --- Comp2
    Comp4 --- Comp3
    Comp4 --> Sig
    Sig --> IPS
    Sig --> W1

    %% Deployment influences API configuration
    D1 --> A1
    D2 --> A1
    D3 --> A1

    %% Legend (Informational; not part of processing flow)
    subgraph "Legend"
        L1[":::internal Internal Components (light blue)"]
        L2[":::middleware Middleware Components (light yellow)"]
        L3[":::external External Services (light pink)"]
        L4[":::deployment Deployment Scripts (light green)"]
    end

    %% Class definitions for colouring
    classDef internal fill:#cce5ff,stroke:#333,stroke-width:1px;
    classDef middleware fill:#fff3cd,stroke:#333,stroke-width:1px;
    classDef external fill:#f8d7da,stroke:#333,stroke-width:1px;
    classDef deployment fill:#d4edda,stroke:#333,stroke-width:1px;

click A1 "https://github.com/ton-community/contract-verifier-backend/blob/main/src/server.ts"
click A2 "https://github.com/ton-community/contract-verifier-backend/blob/main/src/req-id-middleware.ts"
click A3 "https://github.com/ton-community/contract-verifier-backend/blob/main/src/logger.ts"
click C1 "https://github.com/ton-community/contract-verifier-backend/blob/main/src/controller.ts"
click C2 "https://github.com/ton-community/contract-verifier-backend/blob/main/src/deploy-controller.ts"
click Comp1 "https://github.com/ton-community/contract-verifier-backend/blob/main/src/binaries.ts"
click Comp2 "https://github.com/ton-community/contract-verifier-backend/blob/main/src/cell-builders.ts"
click Comp3 "https://github.com/ton-community/contract-verifier-backend/blob/main/src/utils.ts"
click Comp4 "https://github.com/ton-community/contract-verifier-backend/tree/main/src/source-verifier"
click IPS "https://github.com/ton-community/contract-verifier-backend/blob/main/src/ipfs-code-storage-provider.ts"
click W1 "https://github.com/ton-community/contract-verifier-backend/blob/main/src/wrappers/source-item.ts"
click W2 "https://github.com/ton-community/contract-verifier-backend/blob/main/src/wrappers/sources-registry.ts"
click W3 "https://github.com/ton-community/contract-verifier-backend/blob/main/src/wrappers/verifier-registry.ts"
click D1 "https://github.com/ton-community/contract-verifier-backend/blob/main/script/deploy.sh"
click D2 "https://github.com/ton-community/contract-verifier-backend/blob/main/script/config.js"
click D3 "https://github.com/ton-community/contract-verifier-backend/blob/main/script/prepare_ton_release.js"
click D4 "https://github.com/ton-community/contract-verifier-backend/tree/main/script/depracated"
```
