# salmandabbakuti/iot-blockchain architecture

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

- Interactive diagram: https://gitdiagram.com/salmandabbakuti/iot-blockchain
- Repository: https://github.com/salmandabbakuti/iot-blockchain

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    UserBrowser["User Browser"]:::frontend

    %% Backend Layer
    subgraph "Flask Backend"
        FlaskApp["Flask Application (app.py)"]:::backend
        StaticAssets["Static Assets (static/)"]:::backend
        Templates["Templates (templates/)"]:::backend
        IoTLayer["IoT Device Layer (GPIO Simulation)"]:::backend
    end

    %% Blockchain & Smart Contracts Layer
    subgraph "Blockchain & Smart Contracts"
        subgraph "Blockchain Environment"
            Hardhat["Hardhat Config (hardhat.config.js)"]:::blockchain
            Package["Package Management (package.json)"]:::blockchain
            Renovate["Renovate Config (renovate.json)"]:::blockchain
        end
        SmartContracts["Smart Contracts (contracts/)"]:::blockchain
    end

    %% CI/CD Layer
    subgraph "CI/CD Pipeline"
        CICD["CI/CD Pipeline (.github/workflows/e2e.yml)"]:::cicd
    end

    %% Connections
    UserBrowser -->|"HTTP_request"| FlaskApp
    FlaskApp -->|"Serves_static_content"| StaticAssets
    FlaskApp -->|"Serves_templates"| Templates
    FlaskApp -->|"Controls_GPIO"| IoTLayer
    FlaskApp -->|"SmartContract_calls_via_Web3.py"| Hardhat
    Hardhat -->|"Deploys_contracts_to"| SmartContracts
    CICD -->|"Automated_testing&deployment"| FlaskApp

    %% Click Events
    click FlaskApp "https://github.com/salmandabbakuti/iot-blockchain/blob/master/app.py"
    click StaticAssets "https://github.com/salmandabbakuti/iot-blockchain/tree/master/static/"
    click Templates "https://github.com/salmandabbakuti/iot-blockchain/tree/master/templates/"
    click IoTLayer "https://github.com/salmandabbakuti/iot-blockchain/blob/master/app.py"
    click Hardhat "https://github.com/salmandabbakuti/iot-blockchain/blob/master/hardhat.config.js"
    click Package "https://github.com/salmandabbakuti/iot-blockchain/blob/master/package.json"
    click Renovate "https://github.com/salmandabbakuti/iot-blockchain/blob/master/renovate.json"
    click SmartContracts "https://github.com/salmandabbakuti/iot-blockchain/tree/master/contracts/"
    click CICD "https://github.com/salmandabbakuti/iot-blockchain/blob/master/.github/workflows/e2e.yml"

    %% Styles
    classDef frontend fill:#a2d9ce, stroke:#333, color:#000, stroke-width:2px;
    classDef backend fill:#f9e79f, stroke:#333, color:#000, stroke-width:2px;
    classDef blockchain fill:#aed6f1, stroke:#333, color:#000, stroke-width:2px;
    classDef cicd fill:#f5b7b1, stroke:#333, color:#000, stroke-width:2px;
```
