# parilpaladiya/p2506-network architecture

> Architecture diagram of the GitHub repository parilpaladiya/p2506-network, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/parilpaladiya/p2506-network
- Repository: https://github.com/parilpaladiya/p2506-network

## Overview

#### 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: [`postgres/init/01-schema.sql`](https://github.com/parilpaladiya/p2506-network/blob/main/postgres/init/01-schema.sql) (PostgreSQL), [`alert-api/alert_api.py`](https://github.com/parilpaladiya/p2506-network/blob/main/alert-api/alert_api.py) (Alert API), [`alert-api/archive_verifier.py`](https://github.com/parilpaladiya/p2506-network/blob/main/alert-api/archive_verifier.py) (Archive verifier), [`mosquitto/config/mosquitto.conf`](https://github.com/parilpaladiya/p2506-network/blob/main/mosquitto/config/mosquitto.conf) (Mosquitto MQTT)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_telemetry["Telemetry ingestion"]
  node_generator["Telemetry generator<br/>Python producer<br/>[generator.py]"]
  node_mqtt["Mosquitto MQTT<br/>message broker<br/>[mosquitto.conf]"]
  node_node_red["Node-RED<br/>ingestion UI<br/>[flows.json]"]
  node_alert_manager["Alert manager<br/>Python detector<br/>[alert_manager.py]"]
end

subgraph group_archive["Archival integrity"]
  node_redis["Critical alert queue<br/>Redis FIFO"]
  node_archiver["Archiver worker<br/>Python worker<br/>[archiver_worker.py]"]
  node_archiver_container["Archiver container<br/>container boundary"]
  node_ipfs[("Private IPFS<br/>content archive")]
  node_hardhat{{"Hardhat EVM<br/>local ledger<br/>[entrypoint.js]"}}
  node_registry["IntegrityRegistry<br/>Solidity contract"]
  node_deployment["Ledger deployment<br/>Hardhat script<br/>[deploy.js]"]
end

subgraph group_access["Operations and recovery"]
  node_alert_api["Alert API<br/>Flask REST API<br/>[alert_api.py]"]
  node_verifier["Archive verifier<br/>verification workflow"]
  node_rehydrator["IPFS rehydration<br/>recovery workflow"]
  node_grafana["Grafana<br/>operations UI"]
end

subgraph group_platform["Runtime platform"]
  node_compose{{"Docker Compose<br/>orchestrator"}}
  node_postgres[("PostgreSQL<br/>relational store<br/>[01-schema.sql]")]
end

node_compose -->|"runs"| node_mqtt
node_compose -->|"runs"| node_postgres
node_compose -->|"runs"| node_alert_api
node_generator -->|"publishes readings"| node_mqtt
node_mqtt -->|"raw telemetry"| node_node_red
node_mqtt -->|"telemetry"| node_alert_manager
node_node_red -->|"persists raw data"| node_postgres
node_alert_manager -->|"stores alerts"| node_postgres
node_alert_manager -->|"critical readings"| node_redis
node_redis -->|"FIFO drain"| node_archiver
node_archiver_container -->|"contains"| node_archiver
node_archiver -->|"encrypted batches"| node_ipfs
node_archiver -->|"anchors CID"| node_registry
node_deployment -->|"deploys"| node_registry
node_hardhat -->|"executes"| node_registry
node_alert_api -->|"queries alerts"| node_postgres
node_alert_api -->|"invokes"| node_verifier
node_alert_api -->|"invokes"| node_rehydrator
node_verifier -->|"reads CIDs"| node_registry
node_verifier -->|"retrieves and decrypts"| node_ipfs
node_verifier -->|"compares state"| node_postgres
node_rehydrator -->|"reads immutable archives"| node_ipfs
node_rehydrator -->|"repairs rows"| node_postgres
node_grafana -->|"operational data"| node_postgres
node_grafana -->|"verification dashboard"| node_hardhat

click node_compose "https://github.com/parilpaladiya/p2506-network/blob/main/docker-compose.yaml"
click node_generator "https://github.com/parilpaladiya/p2506-network/blob/main/data-generator/generator.py"
click node_mqtt "https://github.com/parilpaladiya/p2506-network/blob/main/mosquitto/config/mosquitto.conf"
click node_node_red "https://github.com/parilpaladiya/p2506-network/blob/main/node-red/data/flows.json"
click node_alert_manager "https://github.com/parilpaladiya/p2506-network/blob/main/alert-manager/alert_manager.py"
click node_postgres "https://github.com/parilpaladiya/p2506-network/blob/main/postgres/init/01-schema.sql"
click node_archiver "https://github.com/parilpaladiya/p2506-network/blob/main/archiver-worker/archiver_worker.py"
click node_archiver_container "https://github.com/parilpaladiya/p2506-network/blob/main/archiver-worker/Dockerfile"
click node_hardhat "https://github.com/parilpaladiya/p2506-network/blob/main/hardhat/entrypoint.js"
click node_registry "https://github.com/parilpaladiya/p2506-network/blob/main/hardhat/contracts/IntegrityRegistry.sol"
click node_alert_api "https://github.com/parilpaladiya/p2506-network/blob/main/alert-api/alert_api.py"
click node_verifier "https://github.com/parilpaladiya/p2506-network/blob/main/alert-api/archive_verifier.py"
click node_rehydrator "https://github.com/parilpaladiya/p2506-network/blob/main/alert-api/rehydrate_from_ipfs.py"
click node_grafana "https://github.com/parilpaladiya/p2506-network/blob/main/grafana/provisioning/dashboards/blockchain-verification-dashboard.json"
click node_deployment "https://github.com/parilpaladiya/p2506-network/blob/main/hardhat/scripts/deploy.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_generator,node_mqtt,node_node_red,node_alert_manager toneBlue
class node_redis,node_archiver,node_archiver_container,node_ipfs,node_hardhat,node_registry,node_deployment toneAmber
class node_alert_api,node_verifier,node_rehydrator,node_grafana toneMint
class node_compose,node_postgres toneRose
```

## Components

### Telemetry ingestion

- [Telemetry generator](https://github.com/parilpaladiya/p2506-network/blob/main/data-generator/generator.py): Python producer · `data-generator/generator.py`
- [Mosquitto MQTT](https://github.com/parilpaladiya/p2506-network/blob/main/mosquitto/config/mosquitto.conf): message broker · Central telemetry transport boundary. · `mosquitto/config/mosquitto.conf`
- [Node-RED](https://github.com/parilpaladiya/p2506-network/blob/main/node-red/data/flows.json): ingestion UI · Independently persists raw telemetry. · `node-red/data/flows.json`
- [Alert manager](https://github.com/parilpaladiya/p2506-network/blob/main/alert-manager/alert_manager.py): Python detector · Classifies anomalies and queues critical readings. · `alert-manager/alert_manager.py`

### Archival integrity

- **Critical alert queue**: Redis FIFO · Decouples detection from archival latency.
- [Archiver worker](https://github.com/parilpaladiya/p2506-network/blob/main/archiver-worker/archiver_worker.py): Python worker · Batches and AES-256-GCM encrypts critical records. · `archiver-worker/archiver_worker.py`
- [Archiver container](https://github.com/parilpaladiya/p2506-network/blob/main/archiver-worker/Dockerfile): container boundary · `archiver-worker/Dockerfile`
- **Private IPFS**: content archive · Stores encrypted, content-addressed batches.
- [Hardhat EVM](https://github.com/parilpaladiya/p2506-network/blob/main/hardhat/entrypoint.js): local ledger · Append-only CID baseline runtime. · `hardhat/entrypoint.js`
- [IntegrityRegistry](https://github.com/parilpaladiya/p2506-network/blob/main/hardhat/contracts/IntegrityRegistry.sol): Solidity contract · Records archive CIDs on chain. · `hardhat/contracts/IntegrityRegistry.sol`
- [Ledger deployment](https://github.com/parilpaladiya/p2506-network/blob/main/hardhat/scripts/deploy.js): Hardhat script · `hardhat/scripts/deploy.js`

### Operations and recovery

- [Alert API](https://github.com/parilpaladiya/p2506-network/blob/main/alert-api/alert_api.py): Flask REST API · Programmatic alert, verification, and recovery facade. · `alert-api/alert_api.py`
- [Archive verifier](https://github.com/parilpaladiya/p2506-network/blob/main/alert-api/archive_verifier.py): verification workflow · Compares chain-backed archives with database records. · `alert-api/archive_verifier.py`
- [IPFS rehydration](https://github.com/parilpaladiya/p2506-network/blob/main/alert-api/rehydrate_from_ipfs.py): recovery workflow · Restores missing or optionally altered database rows. · `alert-api/rehydrate_from_ipfs.py`
- [Grafana](https://github.com/parilpaladiya/p2506-network/blob/main/grafana/provisioning/dashboards/blockchain-verification-dashboard.json): operations UI · Pre-provisioned data and verification dashboards. · `grafana/provisioning/dashboards/blockchain-verification-dashboard.json`

### Runtime platform

- [Docker Compose](https://github.com/parilpaladiya/p2506-network/blob/main/docker-compose.yaml): orchestrator · Owns service networking, startup, and exposed endpoints. · `docker-compose.yaml`
- [PostgreSQL](https://github.com/parilpaladiya/p2506-network/blob/main/postgres/init/01-schema.sql): relational store · Primary raw telemetry and alert state. · `postgres/init/01-schema.sql`

## Connections

- 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
