# snpl-glicth/iot_machine_learning architecture

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

- Interactive diagram: https://gitdiagram.com/snpl-glicth/iot_machine_learning
- Repository: https://github.com/snpl-glicth/iot_machine_learning

## Overview

ZENIN is presented as an ML platform for analyzing dynamic data and producing predictions, anomaly decisions, and explanations; the tree also contains market-data, replay, and execution capabilities. The clearest sampled user workflow is the chat query: a user submits text, the query route assembles analysis inputs, performs best-effort recall, invokes a cognitive engine, and returns text with metadata. The README describes a Hopf-based sovereign inference model, but its cited master-engine files are absent from this tree, so that implementation is not mapped here. Several broader capabilities are represented by their enclosing source directories because their wiring was not sampled.

Main entry points: [`ml_service/api/routes_query.py`](https://github.com/snpl-glicth/iot_machine_learning/blob/master/ml_service/api/routes_query.py) (Query route), [`infrastructure/adapters/cognitive/cognitive_storage_decorator.py`](https://github.com/snpl-glicth/iot_machine_learning/blob/master/infrastructure/adapters/cognitive/cognitive_storage_decorator.py) (Cognitive dual-write), [`application/use_cases`](https://github.com/snpl-glicth/iot_machine_learning/tree/master/application/use_cases) (Prediction workflows), [`infrastructure/persistence/sql/zenin_ml_storage.py`](https://github.com/snpl-glicth/iot_machine_learning/blob/master/infrastructure/persistence/sql/zenin_ml_storage.py) (SQL prediction storage)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_query["Text query"]
  node_query_route["Query route<br/>[routes_query.py]"]
  node_text_analysis["Text analyzers"]
  node_semantic_recall["Semantic recall<br/>[text_recall.py]"]
  node_cognitive_engine["Text cognitive engine"]
  node_query_response["Query response<br/>[routes_query.py]"]
end

subgraph group_iot["IoT inference"]
  node_prediction_use_cases["Prediction workflows"]
  node_engine_selection["Engine selection<br/>[select_engine.py]"]
  node_prediction_domain["Prediction domain"]
  node_anomaly_domain["Anomaly and patterns"]
  node_decision_engine["Contextual decisions"]
  node_explanations["Contextual explanations"]
end

subgraph group_market["Market systems"]
  node_market_observations["Market observations"]
  node_market_models["Market inference"]
  node_market_replay["Replay evaluation"]
  node_market_execution["Broker execution"]
end

subgraph group_persistence["Memory and storage"]
  node_storage_port["Storage contract<br/>[storage_port.py]"]
  node_sql_storage[("SQL prediction storage")]
  node_storage_decorator["Cognitive dual-write"]
  node_cognitive_memory["Cognitive memory"]
end

node_user(("Query user"))
node_sensor_source(("Sensor or series"))

node_user -->|"submits query"| node_query_route
node_query_route -->|"builds analysis input"| node_text_analysis
node_query_route -->|"recalls documents"| node_semantic_recall
node_query_route -->|"requests answer"| node_cognitive_engine
node_query_route -->|"returns response"| node_query_response
node_sensor_source -->|"provides series"| node_prediction_use_cases
node_prediction_use_cases -->|"selects engine"| node_engine_selection
node_storage_port -->|"implemented by"| node_sql_storage
node_storage_decorator -->|"writes first"| node_sql_storage
node_storage_decorator -->|"dual-writes"| node_cognitive_memory

click node_query_route "https://github.com/snpl-glicth/iot_machine_learning/blob/master/ml_service/api/routes_query.py"
click node_text_analysis "https://github.com/snpl-glicth/iot_machine_learning/tree/master/infrastructure/ml/cognitive/text"
click node_semantic_recall "https://github.com/snpl-glicth/iot_machine_learning/blob/master/ml_service/api/services/analyzers/text_recall.py"
click node_cognitive_engine "https://github.com/snpl-glicth/iot_machine_learning/tree/master/infrastructure/ml/cognitive/text"
click node_query_response "https://github.com/snpl-glicth/iot_machine_learning/blob/master/ml_service/api/routes_query.py"
click node_prediction_use_cases "https://github.com/snpl-glicth/iot_machine_learning/tree/master/application/use_cases"
click node_engine_selection "https://github.com/snpl-glicth/iot_machine_learning/blob/master/application/use_cases/select_engine.py"
click node_prediction_domain "https://github.com/snpl-glicth/iot_machine_learning/tree/master/domain/services/prediction"
click node_anomaly_domain "https://github.com/snpl-glicth/iot_machine_learning/tree/master/domain/services/anomaly"
click node_decision_engine "https://github.com/snpl-glicth/iot_machine_learning/blob/master/infrastructure/ml/cognitive/decision/contextual_decision_engine.py"
click node_explanations "https://github.com/snpl-glicth/iot_machine_learning/blob/master/infrastructure/ml/cognitive/explainability/contextual_explainability_engine.py"
click node_market_observations "https://github.com/snpl-glicth/iot_machine_learning/tree/master/domain/entities/market/observations"
click node_market_models "https://github.com/snpl-glicth/iot_machine_learning/tree/master/domain/entities/market"
click node_market_replay "https://github.com/snpl-glicth/iot_machine_learning/tree/master/domain/entities/market/replay"
click node_market_execution "https://github.com/snpl-glicth/iot_machine_learning/tree/master/infrastructure/adapters/market/zephyr"
click node_storage_port "https://github.com/snpl-glicth/iot_machine_learning/blob/master/domain/ports/storage_port.py"
click node_sql_storage "https://github.com/snpl-glicth/iot_machine_learning/blob/master/infrastructure/persistence/sql/zenin_ml_storage.py"
click node_storage_decorator "https://github.com/snpl-glicth/iot_machine_learning/blob/master/infrastructure/adapters/cognitive/cognitive_storage_decorator.py"
click node_cognitive_memory "https://github.com/snpl-glicth/iot_machine_learning/tree/master/infrastructure/adapters/cognitive"

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_query_route,node_text_analysis,node_semantic_recall,node_cognitive_engine,node_query_response,node_user toneBlue
class node_prediction_use_cases,node_engine_selection,node_prediction_domain,node_anomaly_domain,node_decision_engine,node_explanations toneAmber
class node_market_observations,node_market_models,node_market_replay,node_market_execution toneMint
class node_storage_port,node_sql_storage,node_storage_decorator,node_cognitive_memory toneRose
class node_sensor_source toneIndigo
```

## Components

### Text query

- [Query route](https://github.com/snpl-glicth/iot_machine_learning/blob/master/ml_service/api/routes_query.py): `ml_service/api/routes_query.py`
- [Text analyzers](https://github.com/snpl-glicth/iot_machine_learning/tree/master/infrastructure/ml/cognitive/text): `infrastructure/ml/cognitive/text`
- [Semantic recall](https://github.com/snpl-glicth/iot_machine_learning/blob/master/ml_service/api/services/analyzers/text_recall.py): `ml_service/api/services/analyzers/text_recall.py`
- [Text cognitive engine](https://github.com/snpl-glicth/iot_machine_learning/tree/master/infrastructure/ml/cognitive/text): `infrastructure/ml/cognitive/text`
- [Query response](https://github.com/snpl-glicth/iot_machine_learning/blob/master/ml_service/api/routes_query.py): `ml_service/api/routes_query.py`

### IoT inference

- [Prediction workflows](https://github.com/snpl-glicth/iot_machine_learning/tree/master/application/use_cases): `application/use_cases`
- [Engine selection](https://github.com/snpl-glicth/iot_machine_learning/blob/master/application/use_cases/select_engine.py): `application/use_cases/select_engine.py`
- [Prediction domain](https://github.com/snpl-glicth/iot_machine_learning/tree/master/domain/services/prediction): `domain/services/prediction`
- [Anomaly and patterns](https://github.com/snpl-glicth/iot_machine_learning/tree/master/domain/services/anomaly): `domain/services/anomaly`
- [Contextual decisions](https://github.com/snpl-glicth/iot_machine_learning/blob/master/infrastructure/ml/cognitive/decision/contextual_decision_engine.py): `infrastructure/ml/cognitive/decision/contextual_decision_engine.py`
- [Contextual explanations](https://github.com/snpl-glicth/iot_machine_learning/blob/master/infrastructure/ml/cognitive/explainability/contextual_explainability_engine.py): `infrastructure/ml/cognitive/explainability/contextual_explainability_engine.py`

### Market systems

- [Market observations](https://github.com/snpl-glicth/iot_machine_learning/tree/master/domain/entities/market/observations): `domain/entities/market/observations`
- [Market inference](https://github.com/snpl-glicth/iot_machine_learning/tree/master/domain/entities/market): `domain/entities/market`
- [Replay evaluation](https://github.com/snpl-glicth/iot_machine_learning/tree/master/domain/entities/market/replay): `domain/entities/market/replay`
- [Broker execution](https://github.com/snpl-glicth/iot_machine_learning/tree/master/infrastructure/adapters/market/zephyr): `infrastructure/adapters/market/zephyr`

### Memory and storage

- [Storage contract](https://github.com/snpl-glicth/iot_machine_learning/blob/master/domain/ports/storage_port.py): `domain/ports/storage_port.py`
- [SQL prediction storage](https://github.com/snpl-glicth/iot_machine_learning/blob/master/infrastructure/persistence/sql/zenin_ml_storage.py): `infrastructure/persistence/sql/zenin_ml_storage.py`
- [Cognitive dual-write](https://github.com/snpl-glicth/iot_machine_learning/blob/master/infrastructure/adapters/cognitive/cognitive_storage_decorator.py): `infrastructure/adapters/cognitive/cognitive_storage_decorator.py`
- [Cognitive memory](https://github.com/snpl-glicth/iot_machine_learning/tree/master/infrastructure/adapters/cognitive): `infrastructure/adapters/cognitive`

### Other components

- **Query user**
- **Sensor or series**

## Connections

- Query user → Query route: submits query
- Query route → Text analyzers: builds analysis input
- Query route → Semantic recall: recalls documents
- Query route → Text cognitive engine: requests answer
- Query route → Query response: returns response
- Sensor or series → Prediction workflows: provides series
- Prediction workflows → Engine selection: selects engine
- Storage contract → SQL prediction storage: implemented by
- Cognitive dual-write → SQL prediction storage: writes first
- Cognitive dual-write → Cognitive memory: dual-writes
