# iamkk369/ecogaurdmonitor architecture

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

- Interactive diagram: https://gitdiagram.com/iamkk369/ecogaurdmonitor
- Repository: https://github.com/iamkk369/ecogaurdmonitor

## Overview

EcoGuardAI is a prototype for industrial air and water pollution monitoring. Its main workflow accepts simulated or REST/MQTT sensor readings, evaluates them through an event-driven agent system, and exposes violations, alerts, health assessments, and live dashboard updates. The graph also preserves the documented AI, persistence, and monitoring capabilities. Some connections rely on README descriptions or SOURCE INDEX references; unsampled implementation details are not inferred beyond those references.

Main entry points: [`core/orchestrator.py`](https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/orchestrator.py) (Agent Orchestrator), [`api/main.py`](https://github.com/iamkk369/ecogaurdmonitor/blob/main/api/main.py) (FastAPI Application), [`core/database.py`](https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/database.py) (PostgreSQL Database), [`api/routes/monitoring.py`](https://github.com/iamkk369/ecogaurdmonitor/blob/main/api/routes/monitoring.py) (Monitoring API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Ingestion and API"]
  node_simulator["Sensor Simulator"]
  node_ingestion["Sensor Ingestion<br/>[data_ingestion.py]"]
  node_api["FastAPI Application<br/>[main.py]"]
  node_monitoring_api["Monitoring API<br/>[monitoring.py]"]
  node_middleware["API Middleware<br/>[middleware.py]"]
end

subgraph group_agents["Monitoring Agents"]
  node_orchestrator["Agent Orchestrator<br/>[orchestrator.py]"]
  node_base_agent["Agent Interface<br/>[base_agent.py]"]
  node_emission["Emission Monitoring<br/>[emission_agent.py]"]
  node_violation["Violation Detection<br/>[violation_agent.py]"]
end

subgraph group_insights["Analysis and Alerts"]
  node_health["Health Risk Assessment<br/>[health_agent.py]"]
  node_granite["Granite Analysis<br/>[ibm_granite.py]"]
  node_ibm_cloud["IBM Cloud Integration<br/>[ibm_cloud.py]"]
  node_alerts["Regulatory Alerts<br/>[alert_agent.py]"]
end

subgraph group_state["Persistence"]
  node_persistence["Event Persistence<br/>[persistence.py]"]
  node_database[("PostgreSQL Database<br/>[database.py]")]
  node_monitoring_data["Reading and Station Models<br/>[sensor_reading.py]"]
  node_violation_model["Violation Model<br/>[violation.py]"]
  node_alert_model["Alert Model<br/>[alert.py]"]
end

subgraph group_experience["Dashboard and Access"]
  node_dashboard_agent["Dashboard Aggregation<br/>[dashboard_agent.py]"]
  node_dashboard["Live Dashboard<br/>[app.js]"]
end

node_sensor_source(("Sensor Sources"))
node_browser(("Dashboard User"))
node_email_webhook["Email and Webhook"]

node_sensor_source -->|"sends readings"| node_ingestion
node_simulator -->|"simulates feeds"| node_sensor_source
node_api -->|"starts lifecycle"| node_orchestrator
node_api -->|"configures"| node_middleware
node_api -->|"routes requests"| node_monitoring_api
node_ingestion -->|"dispatches readings"| node_orchestrator
node_monitoring_api -->|"triggers pipeline"| node_orchestrator
node_monitoring_api -->|"reads and writes"| node_database
node_monitoring_api -->|"uses model"| node_monitoring_data
node_orchestrator -->|"dispatches readings"| node_emission
node_orchestrator -->|"dispatches violations"| node_violation
node_orchestrator -->|"dispatches violations"| node_alerts
node_orchestrator -->|"dispatches violations"| node_health
node_orchestrator -->|"dispatches events"| node_dashboard_agent
node_emission -->|"emits violations"| node_orchestrator
node_violation -->|"generates reports"| node_granite
node_health -->|"requests advisories"| node_granite
node_alerts -->|"persists alerts"| node_persistence
node_alerts -->|"escalates alerts"| node_email_webhook
node_violation -.->|"persists violations"| node_persistence
node_persistence -->|"writes events"| node_database
node_database -->|"stores readings"| node_monitoring_data
node_database -->|"stores violations"| node_violation_model
node_database -->|"stores alerts"| node_alert_model
node_dashboard_agent -->|"streams SSE"| node_api
node_api -->|"serves live updates"| node_dashboard
node_browser -->|"views monitoring"| node_dashboard
node_api -.->|"health integration"| node_ibm_cloud

click node_simulator "https://github.com/iamkk369/ecogaurdmonitor/blob/main/scripts/simulate_sensors.py"
click node_ingestion "https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/data_ingestion.py"
click node_api "https://github.com/iamkk369/ecogaurdmonitor/blob/main/api/main.py"
click node_monitoring_api "https://github.com/iamkk369/ecogaurdmonitor/blob/main/api/routes/monitoring.py"
click node_middleware "https://github.com/iamkk369/ecogaurdmonitor/blob/main/api/middleware.py"
click node_orchestrator "https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/orchestrator.py"
click node_base_agent "https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/base_agent.py"
click node_emission "https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/emission_agent.py"
click node_violation "https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/violation_agent.py"
click node_health "https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/health_agent.py"
click node_granite "https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/ibm_granite.py"
click node_ibm_cloud "https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/ibm_cloud.py"
click node_alerts "https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/alert_agent.py"
click node_dashboard_agent "https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/dashboard_agent.py"
click node_persistence "https://github.com/iamkk369/ecogaurdmonitor/blob/main/services/persistence.py"
click node_database "https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/database.py"
click node_monitoring_data "https://github.com/iamkk369/ecogaurdmonitor/blob/main/models/sensor_reading.py"
click node_violation_model "https://github.com/iamkk369/ecogaurdmonitor/blob/main/models/violation.py"
click node_alert_model "https://github.com/iamkk369/ecogaurdmonitor/blob/main/models/alert.py"
click node_dashboard "https://github.com/iamkk369/ecogaurdmonitor/blob/main/dashboard/app.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_simulator,node_ingestion,node_api,node_monitoring_api,node_middleware,node_browser toneBlue
class node_orchestrator,node_base_agent,node_emission,node_violation toneAmber
class node_health,node_granite,node_ibm_cloud,node_alerts,node_email_webhook toneMint
class node_persistence,node_database,node_monitoring_data,node_violation_model,node_alert_model toneRose
class node_dashboard_agent,node_dashboard,node_sensor_source toneIndigo
```

## Components

### Ingestion and API

- [Sensor Simulator](https://github.com/iamkk369/ecogaurdmonitor/blob/main/scripts/simulate_sensors.py): `scripts/simulate_sensors.py`
- [Sensor Ingestion](https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/data_ingestion.py): `core/data_ingestion.py`
- [FastAPI Application](https://github.com/iamkk369/ecogaurdmonitor/blob/main/api/main.py): `api/main.py`
- [Monitoring API](https://github.com/iamkk369/ecogaurdmonitor/blob/main/api/routes/monitoring.py): `api/routes/monitoring.py`
- [API Middleware](https://github.com/iamkk369/ecogaurdmonitor/blob/main/api/middleware.py): `api/middleware.py`

### Monitoring Agents

- [Agent Orchestrator](https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/orchestrator.py): `core/orchestrator.py`
- [Agent Interface](https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/base_agent.py): `agents/base_agent.py`
- [Emission Monitoring](https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/emission_agent.py): `agents/emission_agent.py`
- [Violation Detection](https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/violation_agent.py): `agents/violation_agent.py`

### Analysis and Alerts

- [Health Risk Assessment](https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/health_agent.py): `agents/health_agent.py`
- [Granite Analysis](https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/ibm_granite.py): `core/ibm_granite.py`
- [IBM Cloud Integration](https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/ibm_cloud.py): `core/ibm_cloud.py`
- [Regulatory Alerts](https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/alert_agent.py): `agents/alert_agent.py`

### Persistence

- [Event Persistence](https://github.com/iamkk369/ecogaurdmonitor/blob/main/services/persistence.py): `services/persistence.py`
- [PostgreSQL Database](https://github.com/iamkk369/ecogaurdmonitor/blob/main/core/database.py): `core/database.py`
- [Reading and Station Models](https://github.com/iamkk369/ecogaurdmonitor/blob/main/models/sensor_reading.py): `models/sensor_reading.py`
- [Violation Model](https://github.com/iamkk369/ecogaurdmonitor/blob/main/models/violation.py): `models/violation.py`
- [Alert Model](https://github.com/iamkk369/ecogaurdmonitor/blob/main/models/alert.py): `models/alert.py`

### Dashboard and Access

- [Dashboard Aggregation](https://github.com/iamkk369/ecogaurdmonitor/blob/main/agents/dashboard_agent.py): `agents/dashboard_agent.py`
- [Live Dashboard](https://github.com/iamkk369/ecogaurdmonitor/blob/main/dashboard/app.js): `dashboard/app.js`

### Other components

- **Sensor Sources**
- **Dashboard User**
- **Email and Webhook**

## Connections

- Sensor Sources → Sensor Ingestion: sends readings (evidence: `README.md`)
- Sensor Simulator → Sensor Sources: simulates feeds (evidence: `README.md`)
- FastAPI Application → Agent Orchestrator: starts lifecycle (evidence: `api/main.py`)
- FastAPI Application → API Middleware: configures (evidence: `api/main.py`)
- FastAPI Application → Monitoring API: routes requests (evidence: `api/main.py`)
- Sensor Ingestion → Agent Orchestrator: dispatches readings (evidence: `core/orchestrator.py`)
- Monitoring API → Agent Orchestrator: triggers pipeline (evidence: `api/routes/monitoring.py`)
- Monitoring API → PostgreSQL Database: reads and writes (evidence: `api/routes/monitoring.py`)
- Monitoring API → Reading and Station Models: uses model (evidence: `api/routes/monitoring.py`)
- Agent Orchestrator → Emission Monitoring: dispatches readings (evidence: `core/orchestrator.py`)
- Agent Orchestrator → Violation Detection: dispatches violations (evidence: `core/orchestrator.py`)
- Agent Orchestrator → Regulatory Alerts: dispatches violations (evidence: `core/orchestrator.py`)
- Agent Orchestrator → Health Risk Assessment: dispatches violations (evidence: `core/orchestrator.py`)
- Agent Orchestrator → Dashboard Aggregation: dispatches events (evidence: `core/orchestrator.py`)
- Emission Monitoring → Agent Orchestrator: emits violations (evidence: `README.md`)
- Violation Detection → Granite Analysis: generates reports (evidence: `agents/violation_agent.py`)
- Health Risk Assessment → Granite Analysis: requests advisories (evidence: `agents/health_agent.py`)
- Regulatory Alerts → Event Persistence: persists alerts (evidence: `agents/alert_agent.py`)
- Regulatory Alerts → Email and Webhook: escalates alerts (evidence: `README.md`)
- Violation Detection → Event Persistence: persists violations
- Event Persistence → PostgreSQL Database: writes events (evidence: `services/persistence.py`)
- PostgreSQL Database → Reading and Station Models: stores readings (evidence: `core/database.py`)
- PostgreSQL Database → Violation Model: stores violations (evidence: `core/database.py`)
- PostgreSQL Database → Alert Model: stores alerts (evidence: `core/database.py`)
- Dashboard Aggregation → FastAPI Application: streams SSE (evidence: `api/main.py`)
- FastAPI Application → Live Dashboard: serves live updates (evidence: `README.md`)
- Dashboard User → Live Dashboard: views monitoring (evidence: `README.md`)
- FastAPI Application → IBM Cloud Integration: health integration
