# vyom-yadav/fake-product-detection-hyperledger architecture

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

- Interactive diagram: https://gitdiagram.com/vyom-yadav/fake-product-detection-hyperledger
- Repository: https://github.com/vyom-yadav/fake-product-detection-hyperledger

## Overview

##### Project type and purpose
- This is a blockchain-based asset-transfer system built on Hyperledger Fabric.
- It provides a permissioned DLT network plus a Go-based REST API for invoking and querying chaincode.
- Its goal is to track product ownership, generate QR codes, and prevent counterfeit products.

##### File structure
Top-level directories & files:
- asset-transfer/product-chaincode/…
- Chaincode implementation in Go (smartcontract.go and assetTransfer.go).
- asset-transfer/rest-api-go/…
- REST server in Go with app.go, initialize.go, invoke.go, query.go.
- compose/…
- Docker Compose files for CA services and network.
- config/ and configtx/…
- Fabric network configuration (orderers, channels).
- organizations/…
- CA scripts, MSP ENVs and templates.
- network.sh, scripts/…
- Scripts to install/clean network, create channels, deploy chaincode, set anchors.

##### README for additional insights
- Single channel, single chaincode on Fabric network.
- One Orderer, one Peer per Org, one CA per Org, one User/Admin each.
- Hard-coded channel name and chaincode name in REST API.
- QR code generation pointing to the REST endpoints.

##### Elements
- Client → REST API (HTTP calls)
- REST API → Peer/Orderer (gRPC or CLI invokes)
- Peer → Orderer (transaction distribution)
- Orderer → Peers (block delivery)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client / QR Scanner / cURL"]:::client

    %% REST API Layer
    subgraph "REST API Service"
        direction TB
        REST_Main["main.go"]:::rest
        REST_App["app.go"]:::rest
        REST_Init["initialize.go"]:::rest
        REST_Invoke["invoke.go"]:::rest
        REST_Query["query.go"]:::rest
        REST_Gomod["go.mod"]:::rest
        QRGen["QR Code Generator"]:::rest
    end

    %% Fabric Network Layer
    subgraph "Hyperledger Fabric Network"
        direction TB
        subgraph "Certificate Authorities"
            Org1CA["Org1 CA"]:::fabric
            Org2CA["Org2 CA"]:::fabric
        end
        Orderer["Orderer"]:::fabric
        subgraph "Peer Nodes"
            Peer1["Peer0.Org1"]:::fabric
            Peer2["Peer0.Org2"]:::fabric
        end
        CouchDB["CouchDB"]:::fabric
        ChaincodeCont["Chaincode Container"]:::fabric
    end

    %% Deployment & Configuration
    subgraph "Deployment & Configuration"
        direction TB
        subgraph "Docker Compose"
            ComposeCA["compose-ca.yaml"]:::infra
            ComposeNet["compose-net.yaml"]:::infra
        end
        subgraph "Scripts"
            NetScript["network.sh"]:::infra
            ChanScript["createChannel.sh"]:::infra
            DeployCC["deployCC.sh"]:::infra
            AnchorScript["setAnchorPeer.sh"]:::infra
            EnvUtil["envVar.sh"]:::infra
            Utils["utils.sh"]:::infra
            CCUtils["ccutils.sh"]:::infra
            ConfigUpd["configUpdate.sh"]:::infra
        end
        subgraph "Configuration Files"
            CoreCfg["config/core.yaml"]:::infra
            OrdererCfg["config/orderer.yaml"]:::infra
            Configtx1["configtx.yaml"]:::infra
            Configtx2["configtx/configtx.yaml"]:::infra
            PeerCfg["compose/docker/peercfg/core.yaml"]:::infra
            CCPJson["organizations/ccp-template.json"]:::infra
            CCPYaml["organizations/ccp-template.yaml"]:::infra
        end
    end

    %% Interactions
    Client -->|"HTTP Invoke/Query"| REST_Main
    REST_Main --> REST_Init
    REST_Main --> REST_App
    REST_App --> REST_Invoke
    REST_App --> REST_Query
    REST_Invoke -->|"Endorsement"| Peer1
    REST_Invoke -->|"Endorsement"| Peer2
    REST_Invoke -->|"Order Transaction"| Orderer
    Orderer -->|"Block Delivery"| Peer1
    Orderer -->|"Block Delivery"| Peer2
    REST_Query -->|"Query Ledger"| Peer1
    REST_Query -->|"Query Ledger"| Peer2
    REST_App --> QRGen
    ChaincodeCont --> Peer1
    ChaincodeCont --> Peer2
    Org1CA --> Peer1
    Org2CA --> Peer2

    %% Deployment to Fabric
    NetScript --> ComposeCA
    NetScript --> ComposeNet
    ChanScript --> Orderer
    DeployCC --> ChaincodeCont
    AnchorScript --> Peer1
    AnchorScript --> Peer2

    %% Click Events
    click ChaincodeCont "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/asset-transfer/product-chaincode/assetTransfer.go"
    click ChaincodeCont "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/asset-transfer/product-chaincode/chaincode/smartcontract.go"
    click REST_Main "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/asset-transfer/rest-api-go/main.go"
    click REST_App "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/asset-transfer/rest-api-go/web/app.go"
    click REST_Init "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/asset-transfer/rest-api-go/web/initialize.go"
    click REST_Invoke "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/asset-transfer/rest-api-go/web/invoke.go"
    click REST_Query "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/asset-transfer/rest-api-go/web/query.go"
    click REST_Gomod "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/asset-transfer/rest-api-go/go.mod"
    click NetScript "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/network.sh"
    click ChanScript "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/scripts/createChannel.sh"
    click DeployCC "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/scripts/deployCC.sh"
    click AnchorScript "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/scripts/setAnchorPeer.sh"
    click EnvUtil "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/scripts/envVar.sh"
    click Utils "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/scripts/utils.sh"
    click CCUtils "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/scripts/ccutils.sh"
    click ConfigUpd "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/scripts/configUpdate.sh"
    click ComposeCA "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/compose/compose-ca.yaml"
    click ComposeNet "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/compose/compose-net.yaml"
    click CoreCfg "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/config/core.yaml"
    click OrdererCfg "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/config/orderer.yaml"
    click Configtx1 "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/config/configtx.yaml"
    click Configtx2 "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/configtx/configtx.yaml"
    click PeerCfg "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/compose/docker/peercfg/core.yaml"
    click CCPJson "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/organizations/ccp-template.json"
    click CCPYaml "https://github.com/vyom-yadav/fake-product-detection-hyperledger/blob/master/organizations/ccp-template.yaml"

    %% Styles
    classDef client fill:#E8F1FA,stroke:#1E6BB8,color:#1E6BB8
    classDef rest fill:#F0F4C3,stroke:#9E9D24,color:#827717
    classDef fabric fill:#E0F7FA,stroke:#006064,color:#004D40
    classDef infra fill:#FFF3E0,stroke:#EF6C00,color:#E65100
```
