# origintrail/ot-node architecture

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

- Interactive diagram: https://gitdiagram.com/origintrail/ot-node
- Repository: https://github.com/origintrail/ot-node

## Overview

##### Project Type and Purpose
- Type: Backend Node.js application (no traditional “frontend”)
- Purpose: An OriginTrail DKG (Decentralized Knowledge Graph) node that exposes HTTP/RPC APIs and CLI commands, connects to blockchains, triple stores, a relational DB, and a p2p network, and implements the OT protocol (ASK, PUBLISH, GET, UPDATE, FINALITY, etc.).

##### Top-Level Architectural Layers

A. Interface Layer
- CLI entrypoint (bin/ot-node.js or index.js)
- HTTP API Controllers
- v0 controllers (REST endpoints: publish, get, update, info, etc.)
- v1 controllers (new protocol endpoints: ask, finality, direct-query, etc.)
- RPC Controllers (gRPC or custom RPC for ASK, PUBLISH, GET, UPDATE, FINALITY)

B. Application Layer
- Command Resolver & Executor
- Business-Logic Service Layer (expand these!)
- ask-service
- auth-service
- data-service
- get-service
- publish-service
- update-service
- finality-service
- paranet-service
- blockchain-events-service
- protocol-service
- pending-storage-service
- sharding-table-service
- operation-service & operation-id-service
- messaging-service
- crypto-service & signature-service
- triple-store-service
- ual-service (Uniform Asset Locator)
- validation-service & json-schema-service
- auth-service

C. Module/Plugin Layer
Each service invokes one or more “module managers” that load concrete implementations via dependency injection:
- Blockchain Module (eth, polygon, gnosis, parachain, hardhat)
- Triple-Store Module (Blazegraph, Fuseki, GraphDB, Neptune)
- Repository Module (Sequelize + MySQL)
- Network Module (libp2p p2p)
- HTTP-Client Module (Express HTTP Client + middleware: auth, rate-limiting, validation)
- Auto-Updater Module
- Telemetry Module (Quest Telemetry)
- Validation Module (Merkle-validation)

D. Infrastructure Layer
- Blockchain Networks (RPC endpoints BC1, BC2)
- Triple Store (Java process: Blazegraph / Fuseki / GraphDB / AWS Neptune)
- Relational Database (MySQL)
- P2P Network (libp2p peers)
- External Services (Papertrail logging, telemetry ingestion)

##### Component Relationships & Data Flows
- Controllers receive client requests → pass to Command Resolver
- Command Resolver selects appropriate Command → delegates to Service Layer
- Service Layer coordinates:
- Data retrieval/storage via triple-store (SPARQL) and repository (SQL)
- Blockchain interactions via Blockchain Module
- P2P messaging via Network Module
- Protocol orchestration (ASK, PUBLISH, UPDATE, FINALITY)
- Validation & cryptographic operations
- Telemetry logging
- Modules talk to external systems (DB, triple store, chains, peers)
- Responses bubble back to controllers → returned to client

##### Architectural Patterns & Design Principles
- Layered architecture (Interface → Application → Modules → Infrastructure)
- Dependency Injection for swapping module implementations
- Command pattern for protocol operations
- Repository pattern (Sequelize) for DB access
- Module Manager pattern for pluggable services
- Separation of concerns: Controllers vs. Services vs. Modules

##### Final Checklist
- All Interface endpoints (HTTP v0, HTTP v1, RPC, CLI)
- Command Resolver & Executor
- Module Managers + Implementations
- Infrastructure elements (Blockchain RPC, Triple-Store, MySQL, P2P Network)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Interface Layer"
        CLI["CLI Entrypoint"] 
        HTTPv0["HTTP API Controllers v0"]
        HTTPv1["HTTP API Controllers v1"]
        RPC["RPC Controllers"]
    end

    subgraph "Application Layer"
        Resolver["Command Resolver"]
        Executor["Command Executor"]

        subgraph "Service Layer"
            Ask["ask-service"]
            Auth["auth-service"]
            Data["data-service"]
            Get["get-service"]
            Publish["publish-service"]
            Update["update-service"]
            Finality["finality-service"]
            Paranet["paranet-service"]
            BCEvents["blockchain-events-service"]
            Protocol["protocol-service"]
            Pending["pending-storage-service"]
            Sharding["sharding-table-service"]
            Operation["operation-service"]
            OperationID["operation-id-service"]
            Messaging["messaging-service"]
            Crypto["crypto-service"]
            Signature["signature-service"]
            TripleStoreService["triple-store-service"]
            UAL["ual-service"]
            Validation["validation-service"]
            JSONSchema["json-schema-service"]
        end
    end

    subgraph "Module Manager Layer"
        BCM["Blockchain Module Manager"]
        TSM["Triple-Store Module Manager"]
        RM["Repository Module Manager"]
        NM["Network Module Manager"]
        HTTPM["HTTP-Client Module Manager"]
        AUM["Auto-Updater Module Manager"]
        TelemetryM["Telemetry Module Manager"]
        ValidationM["Validation Module Manager"]
    end

    subgraph "Infrastructure Layer"
        Chain["Blockchain Networks"]
        TripleStoreInfra["Triple Store"]
        MySQL["Relational Database (MySQL)"]
        P2P["P2P Network"]
        External["External Services"]
    end

    CLI --> Executor
    HTTPv0 --> Resolver
    HTTPv1 --> Resolver
    RPC --> Resolver
    Resolver --> Executor

    Executor --> Ask
    Executor --> Auth
    Executor --> Data
    Executor --> Get
    Executor --> Publish
    Executor --> Update
    Executor --> Finality
    Executor --> Paranet
    Executor --> BCEvents
    Executor --> Protocol
    Executor --> Pending
    Executor --> Sharding
    Executor --> Operation
    Executor --> OperationID
    Executor --> Messaging
    Executor --> Crypto
    Executor --> Signature
    Executor --> TripleStoreService
    Executor --> UAL
    Executor --> Validation
    Executor --> JSONSchema

    Ask --> BCM
    Publish --> TSM
    Data --> RM
    Paranet --> NM
    Auth --> HTTPM
    Validation --> ValidationM
    BCEvents --> TelemetryM

    BCM --> Chain
    TSM --> TripleStoreInfra
    RM --> MySQL
    NM --> P2P
    HTTPM --> External
    AUM --> External
    TelemetryM --> External
    ValidationM --> External

    click CLI "https://github.com/origintrail/ot-node/blob/v8/develop/bin/ot-node.js"
    click HTTPv0 "https://github.com/origintrail/ot-node/tree/v8/develop/src/controllers/http-api/v0/"
    click HTTPv1 "https://github.com/origintrail/ot-node/tree/v8/develop/src/controllers/http-api/v1/"
    click RPC "https://github.com/origintrail/ot-node/tree/v8/develop/src/controllers/rpc/"
    click Resolver "https://github.com/origintrail/ot-node/blob/v8/develop/src/commands/command-resolver.js"
    click Executor "https://github.com/origintrail/ot-node/blob/v8/develop/src/commands/command-executor.js"
    click Ask "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/ask-service.js"
    click Auth "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/auth-service.js"
    click Data "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/data-service.js"
    click Get "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/get-service.js"
    click Publish "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/publish-service.js"
    click Update "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/update-service.js"
    click Finality "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/finality-service.js"
    click Paranet "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/paranet-service.js"
    click BCEvents "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/blockchain-events-service.js"
    click Protocol "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/protocol-service.js"
    click Pending "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/pending-storage-service.js"
    click Sharding "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/sharding-table-service.js"
    click Operation "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/operation-service.js"
    click OperationID "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/operation-id-service.js"
    click Messaging "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/messaging-service.js"
    click Crypto "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/crypto-service.js"
    click Signature "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/signature-service.js"
    click TripleStoreService "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/triple-store-service.js"
    click UAL "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/ual-service.js"
    click Validation "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/validation-service.js"
    click JSONSchema "https://github.com/origintrail/ot-node/blob/v8/develop/src/service/json-schema-service.js"
    click BCM "https://github.com/origintrail/ot-node/blob/v8/develop/src/modules/blockchain/blockchain-module-manager.js"
    click TSM "https://github.com/origintrail/ot-node/blob/v8/develop/src/modules/triple-store/triple-store-module-manager.js"
    click RM "https://github.com/origintrail/ot-node/blob/v8/develop/src/modules/repository/repository-module-manager.js"
    click NM "https://github.com/origintrail/ot-node/blob/v8/develop/src/modules/network/network-module-manager.js"
    click HTTPM "https://github.com/origintrail/ot-node/blob/v8/develop/src/modules/http-client/http-client-module-manager.js"
    click AUM "https://github.com/origintrail/ot-node/blob/v8/develop/src/modules/auto-updater/auto-updater-module-manager.js"
    click TelemetryM "https://github.com/origintrail/ot-node/blob/v8/develop/src/modules/telemetry/telemetry-module-manager.js"
    click ValidationM "https://github.com/origintrail/ot-node/blob/v8/develop/src/modules/validation/validation-module-manager.js"
```
