# itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain architecture

> Architecture diagram of the GitHub repository itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain
- Repository: https://github.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain

## Overview

##### Main Components
- Frontend Layer:
- The browser client (index.html and style.css) where users interact with the DApp.
- The JavaScript layer in the src/js folder (app.js and truffle-contract.js) that handles blockchain communication.
- MetaMask integration and the Web3.js layer that acts as the bridge between the UI and the blockchain.
- Backend / Blockchain Layer:
- The collection of smart contracts (in the contracts directory) including SupplyChain, and the role-based contracts (FarmerRole, DistributorRole, RetailerRole, ConsumerRole, plus supporting libraries like Roles).
- Deployment and migration scripts (in migrations and truffle.js) which move contracts to a blockchain network (using Ganache locally or Rinkeby on test networks).
- The build directory that holds the compiled contract artifacts (JSON files) that serve as the interface for interactions initiated by the frontend.
- Development & Testing Tools:
- Truffle Framework (for smart contract compilation, migration, and testing).
- Ganache-cli (for running a local blockchain instance during development).
- Test scripts in the test folder (TestSupplychain.js) ensuring the correctness of contract behavior.

##### Relationships and Interactions
- Two-way interaction where transactions are sent to the smart contracts and blockchain events are returned to the frontend.
- Migration scripts and build artifacts act as the bridge between development and deployment, showing the flow from Solidity source code to compiled artifacts that the frontend uses.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Frontend (UI and web logic) is decoupled from the blockchain smart contract logic.
- The smart contracts are organized modularly: one set for access control and roles (in separate directories) and one for the supply chain logic.
- Client–Server (or Client–Blockchain) Interaction:
- The browser acts as the client initiating transactions, while the blockchain (Ethereum network) “serves” state and processes transactions.
- Use of standard tools for testing & deployment:
- Truffle for contract lifecycle management, Ganache for local testing, and MetaMask/Web3.js for user interactions.

##### Relevant Technologies, Frameworks, or Libraries
- Solidity for smart contracts.
- Truffle Framework (including migration scripts, build artifacts).
- Web3.js and truffle-contract.js for front-end blockchain communication.
- MetaMask for providing secure access to user accounts and signing transactions.
- Ganache-cli for local blockchain environment.
- Node.js, as shown in package.json, for overall project tooling.

##### Elements
- Use clear labels (e.g., “User Browser”, “Frontend (app.js)”, “Smart Contracts (SupplyChain, Roles)”, “Blockchain Node (Ganache / Rinkeby)”, “Test Scripts”, “Migration Scripts”).
- Concise notes on external interactions (e.g., Truffle commands, Ganache CLI, MetaMask).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        browserClient("Browser Client"):::frontend
        jsLayer("JavaScript Logic"):::frontend
        metaInterface("MetaMask/Web3 Interface"):::frontend
    end

    subgraph "Blockchain Layer"
        smartContracts("Smart Contracts (SupplyChain & Roles)"):::blockchain
        deploymentScripts("Deployment & Migration Scripts"):::deployment
        contractArtifacts("Contract Artifacts"):::deployment
        blockchainNode("Blockchain Node (Ganache/Rinkeby)"):::blockchain
    end

    subgraph "Development & Testing"
        truffleFramework("Truffle Framework"):::external
        testScripts("Test Scripts"):::testing
    end

    %% Data Flow Connections
    browserClient -->|"UserActions"| jsLayer
    jsLayer -->|"BlockchainCalls"| metaInterface
    metaInterface -->|"SubmitTx"| blockchainNode
    blockchainNode -->|"Executes"| smartContracts
    blockchainNode -->|"EventEmit"| metaInterface
    deploymentScripts -->|"DeployContracts"| smartContracts
    smartContracts -->|"CompiledTo"| contractArtifacts
    testScripts -->|"TestContracts"| smartContracts
    truffleFramework -->|"ManageDeployment"| deploymentScripts

    %% Click Events
    click browserClient "https://github.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain/blob/master/index.html"
    click browserClient "https://github.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain/blob/master/style.css"
    click jsLayer "https://github.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain/blob/master/src/js/app.js"
    click jsLayer "https://github.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain/blob/master/src/js/truffle-contract.js"
    click smartContracts "https://github.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain/tree/master/contracts"
    click deploymentScripts "https://github.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain/blob/master/migrations/1_initial_migration.js"
    click deploymentScripts "https://github.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain/blob/master/migrations/2_deploy_contracts.js"
    click deploymentScripts "https://github.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain/blob/master/truffle.js"
    click contractArtifacts "https://github.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain/tree/master/build/contracts"
    click testScripts "https://github.com/itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain/blob/master/test/TestSupplychain.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef blockchain fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef deployment fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef testing fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
