How itsdivik/blockchain-dapp-for-tracking-items-through-supply-chain works
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).