How salmandabbakuti/iot-blockchain works
Project Type and Purpose
• This project is a hybrid IoT and blockchain application that demonstrates the integration of physical (or simulated) IoT devices with a blockchain backend.
• The backend is implemented using Flask (Python) and leverages Web3.py to interact with smart contracts written in Solidity. The smart contracts are compiled with Hardhat, and the project simulates or uses actual GPIO signals for IoT interaction.
File Structure
• Top-level files and directories indicate a clear separation of concerns:
• app.py: The main Flask web application handling backend logic and interfacing with both the IoT simulation (via GPIO libraries) and blockchain (via Web3.py).
• contracts: Contains the Solidity smart contracts.
• hardhat.config.js and package.json: Define the blockchain development environment and dependencies for running the Hardhat local blockchain and contract operations.
• static and templates: Provide the frontend assets (CSS files and HTML templates) served by the Flask app.
• .github/workflows: Contains CI/CD configuration (like e2e.yml) for automated testing or deployment processes.
• The presence of requirements.txt confirms Python dependency management, while Node.js dependencies are managed via package.json for blockchain-specific operations.
• Main Components:
• IoT Device Layer: Represents either simulated GPIO pins (using the GPIO Simulator library) or real physical IoT devices on a Raspberry Pi.
• Flask Web Application: Handles HTTP requests, serves the frontend, and orchestrates interactions with both the IoT device layer and the blockchain.
• Blockchain Layer:
▪ Hardhat Environment: Local blockchain node started via Hardhat for testing and running the contracts.
▪ Smart Contracts: Deployed and compiled contracts stored in the 'contracts' directory and maintained via Hardhat.
• External Interfaces: You may include CI/CD pipelines (from the .github directory) or dependency management segments that are important for understanding deployment and maintenance.
• Relationships and Interactions:
• The Flask application (app.py) communicates with:
▪ The IoT layer using GPIO libraries (GPIOSimulator or RPi.GPIO) to simulate or control hardware signals.
▪ The local blockchain node using Web3.py to call smart contracts and listen for events.
• The blockchain layer (local Hardhat node) handles contract compilation and deployment; interaction flows from Flask to Hardhat through smart contract function calls.
• Architectural Patterns:
• The system follows a clear separation of concerns between the UI (served via static assets and templates), the backend logic (Flask app), and external services (blockchain node and IoT device simulation/control).
• It employs a client-server design for the web component, and a microservice-like division where blockchain-related operations are isolated in a separate environment (using Hardhat and Node.js tooling).
• User requests (HTTP traffic) going to the Flask backend.
• Communication from Flask to the local blockchain node (using Web3.py).
• Interaction with the GPIO simulator / Raspberry Pi for IoT device input/output.
• Annotations (if needed) to describe the purpose of each component and any critical configuration or dependency points, such as the CI/CD workflows provided in .github.
• Grouping build and deployment-related files (Hardhat config, package.json, renovate.json) in an “Infrastructure/Configuration” block if desired, as these support the blockchain deployment process.