# faizack/supply-chain-blockchain architecture

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

- Interactive diagram: https://gitdiagram.com/faizack/supply-chain-blockchain
- Repository: https://github.com/faizack/supply-chain-blockchain

## Overview

##### Project type and purpose
- This is a full-stack Ethereum DApp for supply-chain management.
- Frontend: React application (client/)
- Blockchain backend: Solidity smart contract (contracts/) deployed via Truffle (migrations/) to a testnet (Gode Testnet or Ganache).
- Web3.js & MetaMask provide the bridge between frontend and blockchain.

##### File structure
- client/: React-based user interface
– src/: React components (AddMed.js, AssignRoles.js, Supply.js, Track.js, Home.js, App.js)
– artifacts/: compiled ABI and network addresses for SupplyChain and Migrations contracts
– public/: index.html and assets
- contracts/: Solidity source code for SupplyChain and Migrations
- migrations/: scripts to deploy smart contracts to the blockchain
- truffle-config.js: Truffle network configuration (RPC endpoints)
- test/: placeholder for Solidity/JS tests
- package.json / package-lock.json: dependencies (React, web3, Truffle, etc.)

##### README for additional insights
- Architecture section describes:
– Solidity smart contract compiled & deployed via Truffle on Gode Testnet
– Frontend uses Web3.js to talk to the smart contract
– MetaMask injects Web3 provider to the React app

a. Main components
1. React Frontend
- UI pages: Home, AssignRoles, AddMed, Supply, Track
- Web3.js integration module
2. Web3 Provider (injected by MetaMask)
3. Browser Wallet (MetaMask)
- Manages user accounts & signs transactions
4. JSON-RPC endpoint / Blockchain network
- Gode Testnet or local Ganache instance
5. Truffle Suite
- truffle-config.js, migrations scripts
6. Smart Contracts
- SupplyChain.sol, Migrations.sol
- Deployed contract address and ABI
7. Off-chain artifacts
- build artifacts (JSON ABI) consumed by frontend
b. Relationships & interactions
- User clicks UI → React component calls Web3.js → MetaMask popup to sign → JSON-RPC call to blockchain → Smart contract state updated → transaction receipt returned → React updates UI.
- Deployment flow: Truffle migrations → RPC endpoint → contract deployed → artifacts written to client/src/artifacts.
c. Architectural patterns & design principles
- Separation of concerns:
– Presentation (React UI)
– Application logic (Web3.js + ABI wrappers)
– Data & state persistence (blockchain smart contract)
- Role-based access control in smart contract (owner, raw material supplier, manufacturer, distributor, retailer)
- Single smart contract hosting multiple state machines (medicine tracking stages)
d. Technologies, frameworks, libraries
- React.js, Web3.js, MetaMask (frontend)
- Solidity, Truffle Suite (backend smart contract tooling)
- Ganache / Gode Testnet (blockchain node)

##### Final advice
- Be very detailed: capture each React component group, the Web3 adapter, wallet/provider, RPC node, and the smart contract with its roles.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        ReactFE["React Frontend"]:::frontend
        App["App.js (Web3 Init)"]:::frontend
        Index["index.js"]:::frontend
        subgraph "UI Pages"
            Home["Home"]:::frontend
            AssignRoles["AssignRoles"]:::frontend
            AddMed["AddMed"]:::frontend
            Supply["Supply"]:::frontend
            Track["Track"]:::frontend
        end
    end

    %% Integration Layer
    subgraph "Integration Layer"
        Web3Adpt["Web3.js Adapter"]:::integration
        MetaMask["MetaMask (Browser Wallet)"]:::integration
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer"
        RPC["JSON-RPC Endpoint"]:::blockchain
        Node["Gode Testnet / Ganache Node"]:::blockchain
        subgraph "Smart Contracts"
            SC1["SupplyChain.sol"]:::blockchain
            SC2["Migrations.sol"]:::blockchain
        end
        Events["Event Logs"]:::blockchain
    end

    %% Deployment Tooling
    subgraph "Deployment Tooling"
        TruffleCLI["Truffle CLI"]:::tooling
        Config["truffle-config.js"]:::tooling
        M1["1_initial_migration.js"]:::tooling
        M2["2_deploy_contracts.js"]:::tooling
    end

    %% Artifacts
    subgraph "Artifacts"
        ArtifactsDir["Build Artifacts"]:::artifacts
        MigrationsJSON["Migrations.json"]:::artifacts
        SupplyChainJSON["SupplyChain.json"]:::artifacts
    end

    %% Connections
    ReactFE --> App
    ReactFE --> Home
    ReactFE --> AssignRoles
    ReactFE --> AddMed
    ReactFE --> Supply
    ReactFE --> Track
    App -->|initializes| Web3Adpt
    Home -->|calls| Web3Adpt
    AssignRoles -->|calls| Web3Adpt
    AddMed -->|calls| Web3Adpt
    Supply -->|calls| Web3Adpt
    Track -->|calls| Web3Adpt
    Web3Adpt -->|requestSignature| MetaMask
    MetaMask -->|sendRPC| RPC
    RPC -->|processTx| Node
    Node -->|invoke| SC1
    Node -->|invoke| SC2
    SC1 -->|emitEvent| Events
    SC2 -->|emitEvent| Events
    Events -->|subscribe| Web3Adpt
    Node -->|returnReceipt| Web3Adpt
    Web3Adpt -->|updateUI| ReactFE

    TruffleCLI -->|usesConfig| Config
    TruffleCLI -->|runMigration| M1
    TruffleCLI -->|runMigration| M2
    TruffleCLI -->|deploy via RPC| RPC
    RPC -->|writeContract| Node
    Node -->|generateArtifacts| ArtifactsDir
    ArtifactsDir --> MigrationsJSON
    ArtifactsDir --> SupplyChainJSON
    MigrationsJSON -->|consumedBy| ReactFE
    SupplyChainJSON -->|consumedBy| ReactFE

    %% Click Events
    click ReactFE "https://github.com/faizack/supply-chain-blockchain/tree/master/client/src"
    click App "https://github.com/faizack/supply-chain-blockchain/blob/master/client/src/App.js"
    click Index "https://github.com/faizack/supply-chain-blockchain/blob/master/client/src/index.js"
    click Home "https://github.com/faizack/supply-chain-blockchain/blob/master/client/src/Home.js"
    click AssignRoles "https://github.com/faizack/supply-chain-blockchain/blob/master/client/src/AssignRoles.js"
    click AddMed "https://github.com/faizack/supply-chain-blockchain/blob/master/client/src/AddMed.js"
    click Supply "https://github.com/faizack/supply-chain-blockchain/blob/master/client/src/Supply.js"
    click Track "https://github.com/faizack/supply-chain-blockchain/blob/master/client/src/Track.js"
    click MigrationsJSON "https://github.com/faizack/supply-chain-blockchain/blob/master/client/src/artifacts/Migrations.json"
    click SupplyChainJSON "https://github.com/faizack/supply-chain-blockchain/blob/master/client/src/artifacts/SupplyChain.json"
    click SC1 "https://github.com/faizack/supply-chain-blockchain/blob/master/contracts/SupplyChain.sol"
    click SC2 "https://github.com/faizack/supply-chain-blockchain/blob/master/contracts/Migrations.sol"
    click M1 "https://github.com/faizack/supply-chain-blockchain/blob/master/migrations/1_initial_migration.js"
    click M2 "https://github.com/faizack/supply-chain-blockchain/blob/master/migrations/2_deploy_contracts.js"
    click Config "https://github.com/faizack/supply-chain-blockchain/blob/master/truffle-config.js"

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:1px
    classDef integration fill:#FFD8A9,stroke:#333,stroke-width:1px
    classDef blockchain fill:#A9F7B0,stroke:#333,stroke-width:1px
    classDef tooling fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef artifacts fill:#FFDCB2,stroke:#333,stroke-width:1px
```
