# kuldeep23907/supply-chain-using-hyperledger-fabric-and-react architecture

> Architecture diagram of the GitHub repository kuldeep23907/supply-chain-using-hyperledger-fabric-and-react, 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/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react
- Repository: https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react

## Overview

##### Project’s Main Components
- Hyperledger Fabric Network:
– Represented by the artifacts directory (including docker-compose files, crypto-config.yaml, configtx.yaml, and base network definitions) and scripts for generating certificates, creating channels, updating anchor peers, and managing chaincode.
– This includes multiple organizations (Manufacturer, MiddleMen, Consumer), peers, orderer, certificate authorities (as laid out in the README) and the channel configuration.
- Chaincode:
– Found in the chaincode directory (supplychain.go). The chaincode implements all the critical supply chain business processes (e.g., createUser, createProduct, transfer operations, query functions).
- Middleware API Server:
– Located in the web-app/servers directory. This component (using Node.js) exposes REST APIs that interact with the blockchain network and execute chaincode functions. Notice folders for controllers (defining API endpoints), routes, models, utilities, and integration with Fabric (connection files in web-app/servers/fabric).
- Frontend Client:
– Found in web-app/client, this is a React.js application with a clear separation of components (such as create-order, create-product, and user management) that interacts with the backend API.
- Supporting Scripts:
– Shell scripts (startNetwork.sh, stopNetwork.sh, teardown.sh, generate.sh, operate.sh, etc.) in the project root and scripts folder offer automation for network operations and deployment tasks.

##### Relationships and Interactions
- The React.js front end communicates with the backend API server through HTTP calls. This server acts as an intermediary between the client and the blockchain network.
- The Node.js middleware (API server) interacts with the Hyperledger Fabric network using the Fabric SDK (via network connection profiles in the servers/fabric directory) to invoke chaincode functions and query the ledger.
- The chaincode (smart contracts) reside within the Fabric network and govern the business logic (product creation, updates, transfers, and audit queries) across the blockchain.
- The Fabric network’s configuration (setup using docker-compose files and generating certificates) underpins the chaincode execution with multiple peers, orderers, and CA services.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project clearly separates the blockchain network (Hyperledger Fabric and chaincode) from the application logic (Node.js backend) and UI presentation (React client).
- Microservice/API Layer: The backend exposes distinct REST endpoints to interact with the blockchain, which improves modularity.
- DevOps/Automation: A suite of shell scripts and Docker configurations facilitates continuous integration and deployment, as well as network orchestration.
- Security and Transparency: The use of blockchain (immutable ledger, secure identity management via Fabric CA) ensures data integrity and traceability.

##### Relevant Technologies, Frameworks, or Libraries
- Hyperledger Fabric (Blockchain Network)
- Chaincode in Go (supplychain.go)
- Node.js and Express (for the middleware API server)
- React.js (frontend client)
- Docker Compose (for orchestrating the blockchain network and potentially the API server)
- Shell scripting (for automating network set up and teardown)
- Fabric SDK for Node.js (integration of the API server with the Fabric network)

##### Overall Detailing
- Any configuration or deployment artifacts (shell scripts, YAML configuration files) can be noted as ancillary tools that support the primary components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Blockchain Network
    subgraph "Blockchain Network"
        ARTIFACTS["Artifacts & Configurations"]:::artifacts
        SN["startNetwork.sh"]:::scripts
        SP["stopNetwork.sh"]:::scripts
        TD["teardown.sh"]:::scripts
        HF1["Manufacturer Organization (Peer/CA)"]:::fabric
        HF2["MiddleMen Organization (Peer/CA)"]:::fabric
        HF3["Consumer Organization (Peer/CA)"]:::fabric
        ORDERER["Orderer Service"]:::fabric
        CHAINCODE["Chaincode (supplychain.go)"]:::chaincode
    end

    %% Middleware API Server
    subgraph "Middleware API Server"
        API["Node.js REST API Server"]:::api
        CONTROLLERS["Controllers"]:::api
        FABRIC_CONN["Fabric Connection Profiles"]:::api
        ROUTES["Routes & Utilities"]:::api
    end

    %% Frontend Client
    subgraph "Frontend Client"
        CLIENT["React.js Client Application"]:::frontend
        COMPONENTS["Client Components (create-order, create-product, user management)"]:::frontend
    end

    %% Supporting Scripts
    subgraph "Supporting Scripts"
        SCRIPTS["Automation & Deployment Scripts"]:::scripts
        GEN["generate.sh"]:::scripts
        OP["operate.sh"]:::scripts
    end

    %% Relationships
    CLIENT -->|"HTTPRequest"| API
    API -->|"ChaincodeCall"| CHAINCODE
    API -->|"UsesConfig"| ARTIFACTS
    ARTIFACTS --> SN
    ARTIFACTS --> SP
    ARTIFACTS --> TD
    ARTIFACTS --> HF1
    ARTIFACTS --> HF2
    ARTIFACTS --> HF3
    ARTIFACTS --> ORDERER
    HF1 -->|"Executes"| CHAINCODE
    HF2 -->|"Executes"| CHAINCODE
    HF3 -->|"Executes"| CHAINCODE
    CLIENT -->|"Renders"| COMPONENTS
    SCRIPTS -->|"Triggers"| GEN
    SCRIPTS -->|"Triggers"| OP

    %% Click Events for Hyperledger Fabric Network
    click ARTIFACTS "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/tree/master/artifacts"
    click SN "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/blob/master/startNetwork.sh"
    click SP "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/blob/master/stopNetwork.sh"
    click TD "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/blob/master/teardown.sh"
    click CHAINCODE "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/blob/master/chaincode/supplychain.go"

    %% Click Events for Middleware API Server
    click API "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/tree/master/web-app/servers"
    click CONTROLLERS "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/tree/master/web-app/servers/controllers"
    click FABRIC_CONN "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/tree/master/web-app/servers/fabric"
    click ROUTES "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/tree/master/web-app/servers/routes"

    %% Click Events for Frontend Client
    click CLIENT "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/tree/master/web-app/client"
    click COMPONENTS "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/tree/master/web-app/client/components"

    %% Click Events for Supporting Scripts
    click SCRIPTS "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/tree/master/scripts"
    click GEN "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/blob/master/generate.sh"
    click OP "https://github.com/kuldeep23907/supply-chain-using-hyperledger-fabric-and-react/blob/master/operate.sh"

    %% Styles
    classDef fabric fill:#f9c74f,stroke:#000,stroke-width:1px;
    classDef chaincode fill:#90be6d,stroke:#000,stroke-width:1px;
    classDef artifacts fill:#f9844a,stroke:#000,stroke-width:1px;
    classDef api fill:#577590,stroke:#fff,stroke-width:1px, color:#fff;
    classDef frontend fill:#f94144,stroke:#000,stroke-width:1px;
    classDef scripts fill:#277da1,stroke:#000,stroke-width:1px;
```
