# chaeyeon1382-arch/scada-capstone-infra architecture

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

- Interactive diagram: https://gitdiagram.com/chaeyeon1382-arch/scada-capstone-infra
- Repository: https://github.com/chaeyeon1382-arch/scada-capstone-infra

## Overview

This is a small SCADA system for collecting sensor readings over Modbus, forwarding them through MQTT to a cloud API and database, and enabling dashboard monitoring and relay control. Its main workflow runs from the edge gateway’s sensor read and anomaly check through broker ingestion and persistence, then exposes readings to the UI. Relay commands travel back through the API and broker to the gateway. The README documents the dashboard and Slack capabilities; their implementation details are not fully sampled, so those links rely on documented behavior.

Main entry points: [`server/fastapi/mqtt_client.py`](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/mqtt_client.py) (MQTT Ingestion), [`server/fastapi/routers/control.py`](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/routers/control.py) (Relay API), [`server/fastapi/main.py`](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/main.py) (API App), [`ui/index.html`](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/ui/index.html) (Web Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_edge["Edge Gateway"]
  node_modbus["Modbus I/O<br/>[modbus_client.py]"]
  node_anomaly["Anomaly Check<br/>[security.py]"]
  node_gateway_loop["Gateway Loop<br/>[main.py]"]
  node_gateway_mqtt["Gateway MQTT<br/>[mqtt_client.py]"]
end

subgraph group_api["FastAPI Backend"]
  node_api_app["API App<br/>[main.py]"]
  node_ingest["MQTT Ingestion<br/>[mqtt_client.py]"]
  node_sensor_api["Sensor API<br/>[sensor.py]"]
  node_control_api["Relay API<br/>[control.py]"]
  node_slack_api["Slack API<br/>[slack.py]"]
  node_db_access["Database Access<br/>[database.py]"]
  node_data_models["Data Models<br/>[models.py]"]
end

subgraph group_ui["Dashboard"]
  node_dashboard["Web Dashboard<br/>[index.html]"]
  node_ui_config["Dashboard Config<br/>[config.js]"]
end

subgraph group_services["External Services"]
  node_broker["MQTT Broker<br/>[rabbitmq.conf]"]
  node_postgres[("PostgreSQL<br/>[database.py]")]
end

node_sensor_hw(("Sensor Hardware"))
node_slack["Slack"]

node_sensor_hw -->|"sends readings"| node_modbus
node_gateway_loop -->|"reads and controls"| node_modbus
node_gateway_loop -->|"checks payload"| node_anomaly
node_gateway_loop -->|"publishes readings"| node_gateway_mqtt
node_gateway_mqtt -->|"publishes and subscribes"| node_broker
node_broker -->|"delivers sensor data"| node_ingest
node_api_app -->|"starts subscriber"| node_ingest
node_ingest -->|"stores readings"| node_db_access
node_ingest -->|"sends threshold alerts"| node_slack
node_api_app -->|"registers routes"| node_sensor_api
node_api_app -->|"registers routes"| node_control_api
node_api_app -->|"registers routes"| node_slack_api
node_sensor_api -->|"queries readings"| node_db_access
node_control_api -->|"records commands"| node_db_access
node_db_access -->|"connects to"| node_postgres
node_ingest -->|"creates sensor record"| node_data_models
node_sensor_api -->|"queries sensor records"| node_data_models
node_control_api -->|"creates relay log"| node_data_models
node_dashboard -.->|"uses configuration"| node_ui_config
node_dashboard -->|"requests readings"| node_sensor_api
node_dashboard -->|"sends controls"| node_control_api
node_control_api -->|"publishes relay command"| node_broker
node_broker -->|"delivers relay command"| node_gateway_mqtt
node_gateway_mqtt -->|"controls relay"| node_modbus
node_dashboard -.->|"requests alert"| node_slack_api
node_slack_api -->|"posts alert"| node_slack

click node_modbus "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/gateway/modbus_client.py"
click node_anomaly "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/gateway/security.py"
click node_gateway_loop "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/gateway/main.py"
click node_gateway_mqtt "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/gateway/mqtt_client.py"
click node_api_app "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/main.py"
click node_ingest "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/mqtt_client.py"
click node_sensor_api "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/routers/sensor.py"
click node_control_api "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/routers/control.py"
click node_slack_api "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/routers/slack.py"
click node_db_access "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/database.py"
click node_data_models "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/models.py"
click node_dashboard "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/ui/index.html"
click node_ui_config "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/ui/config.js"
click node_broker "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/rabbitmq/rabbitmq.conf"
click node_postgres "https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/database.py"

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_modbus,node_anomaly,node_gateway_loop,node_gateway_mqtt toneBlue
class node_api_app,node_ingest,node_sensor_api,node_control_api,node_slack_api,node_db_access,node_data_models toneAmber
class node_dashboard,node_ui_config toneMint
class node_broker,node_postgres toneRose
class node_sensor_hw,node_slack toneIndigo
```

## Components

### Edge Gateway

- [Modbus I/O](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/gateway/modbus_client.py): `gateway/modbus_client.py`
- [Anomaly Check](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/gateway/security.py): `gateway/security.py`
- [Gateway Loop](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/gateway/main.py): `gateway/main.py`
- [Gateway MQTT](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/gateway/mqtt_client.py): `gateway/mqtt_client.py`

### FastAPI Backend

- [API App](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/main.py): `server/fastapi/main.py`
- [MQTT Ingestion](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/mqtt_client.py): `server/fastapi/mqtt_client.py`
- [Sensor API](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/routers/sensor.py): `server/fastapi/routers/sensor.py`
- [Relay API](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/routers/control.py): `server/fastapi/routers/control.py`
- [Slack API](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/routers/slack.py): `server/fastapi/routers/slack.py`
- [Database Access](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/database.py): `server/fastapi/database.py`
- [Data Models](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/models.py): `server/fastapi/models.py`

### Dashboard

- [Web Dashboard](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/ui/index.html): `ui/index.html`
- [Dashboard Config](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/ui/config.js): `ui/config.js`

### External Services

- [MQTT Broker](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/rabbitmq/rabbitmq.conf): `server/rabbitmq/rabbitmq.conf`
- [PostgreSQL](https://github.com/chaeyeon1382-arch/scada-capstone-infra/blob/main/server/fastapi/database.py): `server/fastapi/database.py`

### Other components

- **Sensor Hardware**
- **Slack**

## Connections

- Sensor Hardware → Modbus I/O: sends readings (evidence: `README.md`)
- Gateway Loop → Modbus I/O: reads and controls (evidence: `gateway/main.py`)
- Gateway Loop → Anomaly Check: checks payload (evidence: `gateway/main.py`)
- Gateway Loop → Gateway MQTT: publishes readings (evidence: `gateway/main.py`)
- Gateway MQTT → MQTT Broker: publishes and subscribes (evidence: `README.md`)
- MQTT Broker → MQTT Ingestion: delivers sensor data (evidence: `README.md`)
- API App → MQTT Ingestion: starts subscriber (evidence: `server/fastapi/main.py`)
- MQTT Ingestion → Database Access: stores readings (evidence: `server/fastapi/mqtt_client.py`)
- MQTT Ingestion → Slack: sends threshold alerts (evidence: `server/fastapi/mqtt_client.py`)
- API App → Sensor API: registers routes (evidence: `server/fastapi/main.py`)
- API App → Relay API: registers routes (evidence: `server/fastapi/main.py`)
- API App → Slack API: registers routes (evidence: `server/fastapi/main.py`)
- Sensor API → Database Access: queries readings (evidence: `server/fastapi/routers/sensor.py`)
- Relay API → Database Access: records commands (evidence: `server/fastapi/routers/control.py`)
- Database Access → PostgreSQL: connects to (evidence: `server/fastapi/database.py`)
- MQTT Ingestion → Data Models: creates sensor record (evidence: `server/fastapi/mqtt_client.py`)
- Sensor API → Data Models: queries sensor records (evidence: `server/fastapi/routers/sensor.py`)
- Relay API → Data Models: creates relay log (evidence: `server/fastapi/routers/control.py`)
- Web Dashboard → Dashboard Config: uses configuration
- Web Dashboard → Sensor API: requests readings (evidence: `README.md`)
- Web Dashboard → Relay API: sends controls (evidence: `README.md`)
- Relay API → MQTT Broker: publishes relay command (evidence: `server/fastapi/routers/control.py`)
- MQTT Broker → Gateway MQTT: delivers relay command (evidence: `gateway/mqtt_client.py`)
- Gateway MQTT → Modbus I/O: controls relay (evidence: `gateway/mqtt_client.py`)
- Web Dashboard → Slack API: requests alert
- Slack API → Slack: posts alert (evidence: `server/fastapi/routers/slack.py`)
