# mluna030/turinganomalydetection architecture

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

- Interactive diagram: https://gitdiagram.com/mluna030/turinganomalydetection
- Repository: https://github.com/mluna030/turinganomalydetection

## Overview

The repository describes an IoT gateway whose principal workflow is packet inspection and filtering, with flow and statistics reporting over MQTT; a separate anomaly-detection branch prepares and trains modality-specific autoencoders for deployment. Firewall rule management and packet processing are visible in sampled Rust source. The README also documents anomaly alerts and a live dashboard, but no dashboard implementation appears in the supplied tree. Anomaly-runtime and daemon connections are therefore shown only where documented, or omitted where source evidence is unavailable.

Main entry points: [`src/router/firewall/firewall-core/src/domain/rule.rs`](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/rule.rs) (Rule Model), [`src/router/firewall/firewall-core/src/application/engine.rs`](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/application/engine.rs) (Packet Processor), [`src/router/firewall/firewall-core/src/infrastructure/mqtt/mqtt.rs`](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/infrastructure/mqtt/mqtt.rs) (MQTT Publisher), [`src/anomaly-detection/dae/modular_dae.py`](https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/dae/modular_dae.py) (Modular Autoencoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firewall["Firewall"]
  node_daemon["Firewall Daemon<br/>[main.rs]"]
  node_processor["Packet Processor<br/>[engine.rs]"]
  node_packet["Packet Model<br/>[packet.rs]"]
  node_backend["Firewall Backend<br/>[backends.rs]"]
end

subgraph group_rules["Filtering Rules"]
  node_manager["Rule Manager<br/>[rule_manager.rs]"]
  node_rulemodel["Rule Model<br/>[rule.rs]"]
  node_port["Port Rules<br/>[port_rules.rs]"]
  node_time["Time Rules<br/>[time_rules.rs]"]
  node_ipgeo["IP and Geo Rules<br/>[ip_rules.rs]"]
  node_ratelimitrules["Rate Limit Rules"]
  node_timeratelimit["Timed Rate Rules"]
  node_limiter["Per-Key Limiter<br/>[rate_limiter.rs]"]
  node_bucket["Token Bucket<br/>[token_bucket.rs]"]
  node_limitconfig["Rate Limit Config"]
end

subgraph group_telemetry["Telemetry"]
  node_flows["Flow Tracker<br/>[flow.rs]"]
  node_stats["Firewall Statistics<br/>[stats.rs]"]
  node_mqtt["MQTT Publisher<br/>[mqtt.rs]"]
end

subgraph group_anomaly["Anomaly Detection"]
  node_preprocess["Modality Preprocessing"]
  node_dae["Modular Autoencoder<br/>[modular_dae.py]"]
  node_training["DAE Training<br/>[train_dae.py]"]
  node_detection["Anomaly Detection"]
  node_integration["Inference Integration<br/>[pipeline.py]"]
  node_inference["Model Inference<br/>[inference.py]"]
  node_export["TFLite Export"]
  node_sparse["Sparse Autoencoder<br/>[train_sparse_ae.py]"]
  node_sparseexport["Sparse TFLite Export"]
end

node_traffic(("Network Traffic"))
node_broker(("MQTT Broker"))
node_dashboard["Monitoring Dashboard"]

node_processor -->|"reads"| node_packet
node_processor -->|"records flows"| node_flows
node_processor -->|"records packets"| node_stats
node_processor -->|"evaluates filters"| node_rulemodel
node_manager -->|"creates entries"| node_rulemodel
node_port -->|"implements filter"| node_rulemodel
node_time -->|"implements filter"| node_rulemodel
node_ipgeo -->|"implements filter"| node_rulemodel
node_ratelimitrules -->|"implements filter"| node_rulemodel
node_timeratelimit -->|"implements filter"| node_rulemodel
node_limiter -->|"uses buckets"| node_bucket
node_mqtt -->|"reads snapshots"| node_flows
node_mqtt -->|"reads statistics"| node_stats
node_mqtt -->|"publishes reports"| node_broker
node_broker -.->|"feeds monitoring"| node_dashboard
node_traffic -.->|"enters gateway"| node_daemon
node_daemon -.->|"dispatches packets"| node_processor
node_preprocess -.->|"prepares inputs"| node_dae
node_training -->|"uses model"| node_dae
node_dae -.->|"exports model"| node_export
node_integration -.->|"runs inference"| node_inference
node_inference -.->|"supports detection"| node_detection
node_sparse -.->|"exports model"| node_sparseexport
node_mqtt -.->|"shares telemetry"| node_integration
node_detection -.->|"alerts dashboard"| node_dashboard

click node_daemon "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-daemon/src/main.rs"
click node_processor "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/application/engine.rs"
click node_packet "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/packet.rs"
click node_flows "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/flow.rs"
click node_stats "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/stats.rs"
click node_manager "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/application/rule_manager.rs"
click node_rulemodel "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/rule.rs"
click node_port "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/rules/port_rules.rs"
click node_time "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/rules/time_rules.rs"
click node_ipgeo "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/rules/ip_rules.rs"
click node_ratelimitrules "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/rules/rate_limit_rules/rate_limit_rules.rs"
click node_timeratelimit "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/rules/rate_limit_rules/time_based_limit_rule.rs"
click node_limiter "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/rate_limiter/rate_limiter.rs"
click node_bucket "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/rate_limiter/token_bucket.rs"
click node_limitconfig "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/rate_limiter/rate_limit_config.rs"
click node_backend "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/infrastructure/backends/backends.rs"
click node_mqtt "https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/infrastructure/mqtt/mqtt.rs"
click node_preprocess "https://github.com/mluna030/turinganomalydetection/tree/main/src/anomaly-detection/dae/preprocessing"
click node_dae "https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/dae/modular_dae.py"
click node_training "https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/dae/train_dae.py"
click node_detection "https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/detection/detect_anomalies.py"
click node_integration "https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/integration/pipeline.py"
click node_inference "https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/inference/inference.py"
click node_export "https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/dae/export_dae_tflite.py"
click node_sparse "https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/sparse-autoencoder/train_sparse_ae.py"
click node_sparseexport "https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/sparse-autoencoder/export_sparse_tflite.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_daemon,node_processor,node_packet,node_backend toneBlue
class node_manager,node_rulemodel,node_port,node_time,node_ipgeo,node_ratelimitrules,node_timeratelimit,node_limiter,node_bucket,node_limitconfig toneAmber
class node_flows,node_stats,node_mqtt toneMint
class node_preprocess,node_dae,node_training,node_detection,node_integration,node_inference,node_export,node_sparse,node_sparseexport toneRose
class node_traffic,node_broker,node_dashboard toneIndigo
```

## Components

### Firewall

- [Firewall Daemon](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-daemon/src/main.rs): `src/router/firewall/firewall-daemon/src/main.rs`
- [Packet Processor](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/application/engine.rs): `src/router/firewall/firewall-core/src/application/engine.rs`
- [Packet Model](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/packet.rs): `src/router/firewall/firewall-core/src/domain/packet.rs`
- [Firewall Backend](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/infrastructure/backends/backends.rs): `src/router/firewall/firewall-core/src/infrastructure/backends/backends.rs`

### Filtering Rules

- [Rule Manager](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/application/rule_manager.rs): `src/router/firewall/firewall-core/src/application/rule_manager.rs`
- [Rule Model](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/rule.rs): `src/router/firewall/firewall-core/src/domain/rule.rs`
- [Port Rules](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/rules/port_rules.rs): `src/router/firewall/firewall-core/src/rules/port_rules.rs`
- [Time Rules](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/rules/time_rules.rs): `src/router/firewall/firewall-core/src/rules/time_rules.rs`
- [IP and Geo Rules](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/rules/ip_rules.rs): `src/router/firewall/firewall-core/src/rules/ip_rules.rs`
- [Rate Limit Rules](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/rules/rate_limit_rules/rate_limit_rules.rs): `src/router/firewall/firewall-core/src/rules/rate_limit_rules/rate_limit_rules.rs`
- [Timed Rate Rules](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/rules/rate_limit_rules/time_based_limit_rule.rs): `src/router/firewall/firewall-core/src/rules/rate_limit_rules/time_based_limit_rule.rs`
- [Per-Key Limiter](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/rate_limiter/rate_limiter.rs): `src/router/firewall/firewall-core/src/domain/rate_limiter/rate_limiter.rs`
- [Token Bucket](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/rate_limiter/token_bucket.rs): `src/router/firewall/firewall-core/src/domain/rate_limiter/token_bucket.rs`
- [Rate Limit Config](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/rate_limiter/rate_limit_config.rs): `src/router/firewall/firewall-core/src/domain/rate_limiter/rate_limit_config.rs`

### Telemetry

- [Flow Tracker](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/flow.rs): `src/router/firewall/firewall-core/src/domain/flow.rs`
- [Firewall Statistics](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/domain/stats.rs): `src/router/firewall/firewall-core/src/domain/stats.rs`
- [MQTT Publisher](https://github.com/mluna030/turinganomalydetection/blob/main/src/router/firewall/firewall-core/src/infrastructure/mqtt/mqtt.rs): `src/router/firewall/firewall-core/src/infrastructure/mqtt/mqtt.rs`

### Anomaly Detection

- [Modality Preprocessing](https://github.com/mluna030/turinganomalydetection/tree/main/src/anomaly-detection/dae/preprocessing): `src/anomaly-detection/dae/preprocessing`
- [Modular Autoencoder](https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/dae/modular_dae.py): `src/anomaly-detection/dae/modular_dae.py`
- [DAE Training](https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/dae/train_dae.py): `src/anomaly-detection/dae/train_dae.py`
- [Anomaly Detection](https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/detection/detect_anomalies.py): `src/anomaly-detection/detection/detect_anomalies.py`
- [Inference Integration](https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/integration/pipeline.py): `src/anomaly-detection/integration/pipeline.py`
- [Model Inference](https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/inference/inference.py): `src/anomaly-detection/inference/inference.py`
- [TFLite Export](https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/dae/export_dae_tflite.py): `src/anomaly-detection/dae/export_dae_tflite.py`
- [Sparse Autoencoder](https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/sparse-autoencoder/train_sparse_ae.py): `src/anomaly-detection/sparse-autoencoder/train_sparse_ae.py`
- [Sparse TFLite Export](https://github.com/mluna030/turinganomalydetection/blob/main/src/anomaly-detection/sparse-autoencoder/export_sparse_tflite.py): `src/anomaly-detection/sparse-autoencoder/export_sparse_tflite.py`

### Other components

- **Network Traffic**
- **MQTT Broker**
- **Monitoring Dashboard**

## Connections

- Packet Processor → Packet Model: reads (evidence: `src/router/firewall/firewall-core/src/application/engine.rs`)
- Packet Processor → Flow Tracker: records flows (evidence: `src/router/firewall/firewall-core/src/application/engine.rs`)
- Packet Processor → Firewall Statistics: records packets (evidence: `src/router/firewall/firewall-core/src/application/engine.rs`)
- Packet Processor → Rule Model: evaluates filters (evidence: `src/router/firewall/firewall-core/src/application/engine.rs`)
- Rule Manager → Rule Model: creates entries (evidence: `src/router/firewall/firewall-core/src/application/rule_manager.rs`)
- Port Rules → Rule Model: implements filter (evidence: `src/router/firewall/firewall-core/src/rules/port_rules.rs`)
- Time Rules → Rule Model: implements filter (evidence: `src/router/firewall/firewall-core/src/rules/time_rules.rs`)
- IP and Geo Rules → Rule Model: implements filter (evidence: `src/router/firewall/firewall-core/src/rules/ip_rules.rs`)
- Rate Limit Rules → Rule Model: implements filter (evidence: `src/router/firewall/firewall-core/src/rules/rate_limit_rules/rate_limit_rules.rs`)
- Timed Rate Rules → Rule Model: implements filter (evidence: `src/router/firewall/firewall-core/src/rules/rate_limit_rules/time_based_limit_rule.rs`)
- Per-Key Limiter → Token Bucket: uses buckets (evidence: `src/router/firewall/firewall-core/src/domain/rate_limiter/rate_limiter.rs`)
- MQTT Publisher → Flow Tracker: reads snapshots (evidence: `src/router/firewall/firewall-core/src/infrastructure/mqtt/mqtt.rs`)
- MQTT Publisher → Firewall Statistics: reads statistics (evidence: `src/router/firewall/firewall-core/src/infrastructure/mqtt/mqtt.rs`)
- MQTT Publisher → MQTT Broker: publishes reports (evidence: `src/router/firewall/firewall-core/src/infrastructure/mqtt/mqtt.rs`)
- MQTT Broker → Monitoring Dashboard: feeds monitoring
- Network Traffic → Firewall Daemon: enters gateway
- Firewall Daemon → Packet Processor: dispatches packets
- Modality Preprocessing → Modular Autoencoder: prepares inputs
- DAE Training → Modular Autoencoder: uses model (evidence: `src/anomaly-detection/dae/train_dae.py`)
- Modular Autoencoder → TFLite Export: exports model
- Inference Integration → Model Inference: runs inference
- Model Inference → Anomaly Detection: supports detection
- Sparse Autoencoder → Sparse TFLite Export: exports model
- MQTT Publisher → Inference Integration: shares telemetry
- Anomaly Detection → Monitoring Dashboard: alerts dashboard
