How hemendrasharma04/supplychaindapp works
Project Overview
• This project is a Smart Contract based Supply Chain Management system focused on ensuring data integrity and preventing tampering.
• It integrates blockchain (Ethereum/Polygon Mumbai testnet and Solidity contracts developed with Hardhat), IoT (Arduino with DHT11 sensor and Node Red flows), a FastAPI-powered backend, and a React/Ethers.js frontend.
• The system is designed to interact between on-chain smart contracts and off-chain IoT and backend services.
Main Components
• Frontend (Client)
• Built with React, located in the "client" directory.
• Involves interaction with the blockchain via Ethers.js.
• Backend
• Developed with FastAPI (see files like main.py, contract.py, and router modules).
• Manages API endpoints to interact with blockchain/smart contracts and possibly process data coming from the IoT setup.
• Smart Contracts / Blockchain Layer
• Solidity contracts and Hardhat configuration (located in "contracts", "hardhat.config.js").
• Deployed on Polygon Mumbai testnet.
• IoT
• Arduino code ("arduino_code.c") for sensor reading.
• Node Red flow (Node_Red.json) for reading from the COM port and forwarding data via an API call.
• Other Supporting Components
• Docker setup (Dockerfile files in backend and client, docker-compose.yml) to simplify deployment.
• Testing and auxiliary scripts for development ("test" directory, "scripts" directory).
Architectural Relationships and Interactions
• The IoT component collects sensor data using Arduino and sends this data through the Node Red setup. Node Red, using its JavaScript logic, calls an API hosted in the backend.
• The Backend (FastAPI) acts as an intermediary that receives IoT data and communicates with the blockchain. It uses the contract details in contract.py to execute functions on the deployed smart contract.
• The Frontend (React app) interacts directly with the blockchain via Ethers.js, as well as making API calls to the backend to fetch or display data (products, status, workers, etc.).
• The Smart Contracts on Ethereum/Polygon ensure tamper-proof recording of supply chain events.
• Docker simplifies the deployment by containerizing each service (client, backend, and possibly IoT-related services).
Architectural Patterns & Design Principles
• Separation of Concerns: Each component (frontend, backend, IoT, smart contract) is designed to handle its own responsibilities.
• Modular Architecture: The project is divided into discrete modules/directories—evidenced by subdirectories like router inside backend and components inside client—making maintenance and scalability easier.
• Use of Containerization: Dockerfiles in both the client and backend, along with a docker-compose file, emphasize a microservice or containerized approach.
• Event-driven communication: The IoT part leverages Node Red’s event-driven programming for data handling and subsequent API calls.
• Frontend (React/Ethers.js)
• Backend (FastAPI API endpoints, smart contract interaction logic)
• Blockchain/Smart Contracts (Solidity contracts with Hardhat)
• IoT Components (Arduino sensor code and Node Red flow)
• Annotations for configuration/deployment tools (Docker, docker-compose) and note any intermediary services (like Alchemy) that enable blockchain interactions.
• For Frontend, include sub-components like API consumers, display components (e.g., DisplayData, DisplayProducts).
• For Blockchain, show the relationship between deployed contracts, Hardhat configuration, and testnet (Polygon Mumbai).
• For IoT, display the Arduino sensor setup, the role of Node Red (import flow JSON), and its API call to the backend.