How parilpaladiya/p2506-network works
Purpose and Composition
A Docker Compose-operated IoT monitoring and integrity stack. It simulates telemetry, ingests it through MQTT into PostgreSQL, detects critical anomalies, archives them immutably through encrypted IPFS content plus an EVM anchor, and exposes operational/audit APIs and Grafana dashboards. Composition and service wiring originate in docker-compose.yaml; database schema is initialized by postgres/init/01-schema.sql.
Entry Points
• Bring up the complete system with Docker Compose using docker-compose.yaml.
• Telemetry production starts in data-generator/generator.py.
• HTTP control and query surface is Flask in alert-api/alert_api.py (health, device alerts, verification, rehydration).
• Standalone operational entry points are alert-api/run_archive_verification.py and alert-api/rehydrate_from_ipfs.py.
• Local ledger deployment is scripted by hardhat/scripts/deploy.js.
Telemetry Ingestion: Two Independent Paths
Mosquitto is the central MQTT boundary, configured by mosquitto/config/mosquitto.conf. Generated readings are consumed along two paths:
1. Node-RED persists raw time-series data to PostgreSQL, with flow definitions in node-red/data/flows.json.
2. Alert Manager consumes the same telemetry, evaluates anomalies, and stores classified alerts in PostgreSQL via alert-manager/alert_manager.py.
This separation preserves raw historical ingestion independently from alerting and archival decisions.
Critical-Alert Buffer and Archival
alert-manager/alert_manager.py sends critical readings to Redis as a FIFO work queue; Redis isolates real-time detection from slower external persistence. archiver-worker/archiver_worker.py blocks on and drains that queue, batches records on item-count or elapsed-time thresholds, encrypts batches with AES-256-GCM, and writes the encrypted artifact to private IPFS. Its container boundary is defined by archiver-worker/Dockerfile.
Immutable Baseline and Blockchain Anchor
The archiver records IPFS CIDs on a local Hardhat EVM chain through the IntegrityRegistry contract at hardhat/contracts/IntegrityRegistry.sol. Hardhat runtime configuration and startup behavior reside in hardhat/hardhat.config.js and hardhat/entrypoint.js. IPFS provides content-addressed archival storage; the chain supplies the authoritative append-only CID baseline used for later verification and recovery.
Verification and Disaster Recovery
alert-api/archive_verifier.py reads on-chain CID references, retrieves/decrypts corresponding IPFS archives, and compares their canonical records to PostgreSQL. It classifies database state as valid, tampered, deleted, or injected/unarchived. alert-api/rehydrate_from_ipfs.py uses the same immutable source to insert missing rows and optionally repair altered rows. These processes deliberately cross the PostgreSQL/IPFS/blockchain trust boundaries rather than trusting database records alone.
API and Observability
alert-api/alert_api.py provides the REST facade for alert lookup and invoking verification/rehydration workflows. Grafana is pre-provisioned against the system’s data sources and dashboards in grafana/provisioning/datasources/datasources.yaml, grafana/provisioning/dashboards/api-postgres-dashboard.json, and grafana/provisioning/dashboards/blockchain-verification-dashboard.json. Node-RED and Grafana are user-facing operational UIs; Alert API is the programmatic interface.
Material Runtimes and Infrastructure
Service containers use Python for generator, alert manager, archiver, and API; Flask for HTTP; PostgreSQL for primary relational state; Mosquitto/MQTT for telemetry transport; Redis for transient critical-event buffering; IPFS Kubo for private content-addressed storage; and Node.js/Hardhat/Solidity for the local EVM ledger. Docker Compose owns service networking, startup, and externally exposed endpoints.
Main entry points: 01-schema.sql PostgreSQL · alert_api.py Alert API · archive_verifier.py Archive verifier · mosquitto.conf Mosquitto MQTT
Components 17
Telemetry ingestion
- Telemetry generator
data-generator/generator.py - Mosquitto MQTT · Central telemetry transport boundary.
mosquitto/config/mosquitto.conf - Node-RED · Independently persists raw telemetry.
node-red/data/flows.json - Alert manager · Classifies anomalies and queues critical readings.
alert-manager/alert_manager.py
Archival integrity
- Critical alert queue · Decouples detection from archival latency.
- Archiver worker · Batches and AES-256-GCM encrypts critical records.
archiver-worker/archiver_worker.py - Archiver container
archiver-worker/Dockerfile - Private IPFS · Stores encrypted, content-addressed batches.
- Hardhat EVM · Append-only CID baseline runtime.
hardhat/entrypoint.js - IntegrityRegistry · Records archive CIDs on chain.
hardhat/contracts/IntegrityRegistry.sol - Ledger deployment
hardhat/scripts/deploy.js
Operations and recovery
- Alert API · Programmatic alert, verification, and recovery facade.
alert-api/alert_api.py - Archive verifier · Compares chain-backed archives with database records.
alert-api/archive_verifier.py - IPFS rehydration · Restores missing or optionally altered database rows.
alert-api/rehydrate_from_ipfs.py - Grafana · Pre-provisioned data and verification dashboards.
grafana/provisioning/dashboards/blockchain-verification-dashboard.json
Runtime platform
- Docker Compose · Owns service networking, startup, and exposed endpoints.
docker-compose.yaml - PostgreSQL · Primary raw telemetry and alert state.
postgres/init/01-schema.sql
Connections 25
- Docker Compose → Mosquitto MQTT: runs
- Docker Compose → PostgreSQL: runs
- Docker Compose → Alert API: runs
- Telemetry generator → Mosquitto MQTT: publishes readings
- Mosquitto MQTT → Node-RED: raw telemetry
- Mosquitto MQTT → Alert manager: telemetry
- Node-RED → PostgreSQL: persists raw data
- Alert manager → PostgreSQL: stores alerts
- Alert manager → Critical alert queue: critical readings
- Critical alert queue → Archiver worker: FIFO drain
- Archiver container → Archiver worker: contains
- Archiver worker → Private IPFS: encrypted batches
- Archiver worker → IntegrityRegistry: anchors CID
- Ledger deployment → IntegrityRegistry: deploys
- Hardhat EVM → IntegrityRegistry: executes
- Alert API → PostgreSQL: queries alerts
- Alert API → Archive verifier: invokes
- Alert API → IPFS rehydration: invokes
- Archive verifier → IntegrityRegistry: reads CIDs
- Archive verifier → Private IPFS: retrieves and decrypts
- Archive verifier → PostgreSQL: compares state
- IPFS rehydration → Private IPFS: reads immutable archives
- IPFS rehydration → PostgreSQL: repairs rows
- Grafana → PostgreSQL: operational data
- Grafana → Hardhat EVM: verification dashboard