# ertis-research/kafka-ml architecture

> Architecture diagram of the GitHub repository ertis-research/kafka-ml, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ertis-research/kafka-ml
- Repository: https://github.com/ertis-research/kafka-ml

## Overview

#### Purpose and Entry Points
Kafka-ML is a Kubernetes-based ML pipeline platform for defining, training, deploying, and monitoring TensorFlow/Keras and PyTorch models over Apache Kafka streams, including distributed, incremental, semi-supervised, and federated TensorFlow training. Users enter through the Angular UI; workloads run as containerized Kubernetes services.
- `frontend/src/main.ts`
- `backend/manage.py`
- `kustomize/local/kustomization.yaml`

#### UI and API Control Plane
The Angular frontend manages models, configurations, deployments, inference endpoints, IoT devices, results, and visualization. It calls the Django backend REST API and consumes visualization updates through WebSockets.
- `frontend/src/app/app-routing.module.ts`
- `frontend/src/app/services/visualization-ws.service.ts`
- `backend/automl/urls.py`
- `backend/automl/websockets.py`

#### Backend Orchestration and Persistent Domain
Django is the system’s control plane: it persists ML/domain entities, exposes APIs, converts configuration and deployment requests into Kubernetes job/deployment manifests, and records training/inference state. ASGI supports HTTP plus real-time updates; nginx is packaged as a separate backend-facing proxy.
- `backend/autoweb/settings.py`
- `backend/automl/models.py`
- `backend/automl/views/deployments.py`
- `backend/automl/views/utils/job_manifest_generator.py`

#### Stream Ingestion and Control Signaling
Apache Kafka is the primary data boundary: external producers write raw or Avro training/inference records keyed by deployment/topic configuration; workers consume them and publish model outputs, metrics, and control events. Datasource sink libraries are the producer-facing integration boundary. A control logger monitors Kafka-side lifecycle/control messages.
- `datasources/sink.py`
- `datasources/raw_sink.py`
- `datasources/avro_sink.py`
- `kafka_control_logger/logger.py`

#### ML Code Execution and Training Workers
User-provided model code is executed outside the backend in dedicated TensorFlow or PyTorch executor services, keeping framework/runtime dependencies and arbitrary ML code isolated from the control plane. Training containers consume Kafka datasets, execute single or distributed training, and emit trained artifacts/results. TensorFlow contains the richer training modes: classic, edge/cloud distributed, incremental, semi-supervised, and blockchain/federated-related paths.
- `mlcode_executor/tfexecutor/app.py`
- `mlcode_executor/pthexecutor/app.py`
- `model_training/tensorflow/mainTraining.py`
- `model_training/pytorch/training.py`

#### Inference and Visualization Flow
A trained model is deployed as a framework-specific inference service. It consumes input records from configured Kafka topics, emits predictions to output topics, and supports chained distributed-model inference through upper-model topics and confidence thresholds. The UI visualization layer subscribes to backend WebSocket output for classification or regression displays.
- `model_inference/tensorflow/inference.py`
- `model_inference/pytorch/inference.py`
- `backend/automl/views/inferences.py`
- `frontend/src/app/visualization/visualization.component.ts`

#### Federated Learning Subsystem
Federated learning is a separate TensorFlow-only deployment slice. A federated backend and Kafka control loggers coordinate device data/model control events; federated training aggregates client model updates rather than centralizing raw data. It has its own Kustomize base and master/GPU overlays, distinct from the standard pipeline.
- `federated-module/federated_backend/automl/views.py`
- `federated-module/federated_model_training/tensorflow/federated_mainTraining.py`
- `federated-module/federated_model_training/tensorflow/FederatedKafkaMLAggregationSink.py`
- `federated-module/kustomize/base/kustomization.yaml`

#### Runtime and Infrastructure Boundaries
Services are Dockerized Python (Django, TensorFlow, PyTorch, Kafka clients) and Angular/Node-built frontend artifacts, deployed through Kustomize overlays. Kubernetes is both the workload scheduler and backend orchestration target; Kafka is externally addressable/configured through manifests. CPU is default, while GPU-specific overlays and resource configuration support NVIDIA/GPU-sharing deployments.
- `kustomize/base/resources/backend-deployment.yaml`
- `kustomize/base/resources/tf-executor-deployment.yaml`
- `kustomize/base/resources/kafkaml-configmap.yaml`
- `kustomize/master-gpu/kustomization.yaml`

Main entry points: [`kustomize/local/kustomization.yaml`](https://github.com/ertis-research/kafka-ml/blob/master/kustomize/local/kustomization.yaml) (Kubernetes + Kustomize), [`backend/manage.py`](https://github.com/ertis-research/kafka-ml/blob/master/backend/manage.py) (Django API / ASGI), [`frontend/src/main.ts`](https://github.com/ertis-research/kafka-ml/blob/master/frontend/src/main.ts) (Angular UI), [`frontend/src/app/services/visualization-ws.service.ts`](https://github.com/ertis-research/kafka-ml/blob/master/frontend/src/app/services/visualization-ws.service.ts) (Visualization WebSocket)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Control Plane"]
  node_ui["Angular UI<br/>frontend<br/>[main.ts]"]
  node_ui_routes["UI routes<br/>routing"]
  node_visualization_ws["Visualization WebSocket<br/>websocket client"]
  node_django_api["Django API / ASGI<br/>control API<br/>[manage.py]"]
  node_domain[("Domain state<br/>Django models<br/>[models.py]")]
  node_deployment_orchestrator["Deployment orchestrator<br/>API views<br/>[deployments.py]"]
  node_manifest_generator["Job manifest generator<br/>Kubernetes manifests"]
  node_inference_api["Inference API<br/>API views<br/>[inferences.py]"]
end

subgraph group_stream["Streaming ML"]
  node_kafka["Apache Kafka<br/>stream boundary"]
  node_datasource_sinks["Datasource sinks<br/>producer library<br/>[sink.py]"]
  node_control_logger["Kafka control logger<br/>lifecycle monitor<br/>[logger.py]"]
  node_tf_executor["TensorFlow executor<br/>ML code runtime<br/>[app.py]"]
  node_pytorch_executor["PyTorch executor<br/>ML code runtime<br/>[app.py]"]
  node_tf_training["TensorFlow training<br/>training worker<br/>[mainTraining.py]"]
  node_pytorch_training["PyTorch training<br/>training worker<br/>[training.py]"]
  node_tf_inference["TensorFlow inference<br/>inference worker<br/>[inference.py]"]
  node_pytorch_inference["PyTorch inference<br/>inference worker<br/>[inference.py]"]
end

subgraph group_federated["Federated Learning"]
  node_federated_backend["Federated backend<br/>federated control API<br/>[views.py]"]
  node_federated_training["Federated TF training<br/>aggregation worker"]
end

subgraph group_platform["Runtime Platform"]
  node_kubernetes{{"Kubernetes + Kustomize<br/>workload platform<br/>[kustomization.yaml]"}}
end

node_ui -->|"navigates"| node_ui_routes
node_ui -->|"REST requests"| node_django_api
node_ui -->|"visualizes through"| node_visualization_ws
node_visualization_ws -->|"WebSocket updates"| node_django_api
node_django_api -->|"reads and records state"| node_domain
node_django_api -->|"deployment requests"| node_deployment_orchestrator
node_django_api -->|"inference state"| node_inference_api
node_deployment_orchestrator -->|"generates"| node_manifest_generator
node_manifest_generator -->|"applies workloads"| node_kubernetes
node_kubernetes -->|"runs"| node_tf_executor
node_kubernetes -->|"runs"| node_pytorch_executor
node_kubernetes -->|"runs"| node_tf_training
node_kubernetes -->|"runs"| node_pytorch_training
node_kubernetes -->|"runs"| node_tf_inference
node_kubernetes -->|"runs"| node_pytorch_inference
node_datasource_sinks -->|"publishes records"| node_kafka
node_tf_training -->|"consumes data; publishes results"| node_kafka
node_pytorch_training -->|"consumes data; publishes results"| node_kafka
node_tf_inference -->|"consumes inputs; publishes predictions"| node_kafka
node_pytorch_inference -->|"consumes inputs; publishes predictions"| node_kafka
node_control_logger -->|"monitors control events"| node_kafka
node_federated_backend -->|"coordinates control events"| node_kafka
node_federated_training -->|"aggregates client updates"| node_kafka
node_kubernetes -.->|"deploys"| node_federated_backend
node_kubernetes -.->|"deploys"| node_federated_training

click node_ui "https://github.com/ertis-research/kafka-ml/blob/master/frontend/src/main.ts"
click node_ui_routes "https://github.com/ertis-research/kafka-ml/blob/master/frontend/src/app/app-routing.module.ts"
click node_visualization_ws "https://github.com/ertis-research/kafka-ml/blob/master/frontend/src/app/services/visualization-ws.service.ts"
click node_django_api "https://github.com/ertis-research/kafka-ml/blob/master/backend/manage.py"
click node_domain "https://github.com/ertis-research/kafka-ml/blob/master/backend/automl/models.py"
click node_deployment_orchestrator "https://github.com/ertis-research/kafka-ml/blob/master/backend/automl/views/deployments.py"
click node_manifest_generator "https://github.com/ertis-research/kafka-ml/blob/master/backend/automl/views/utils/job_manifest_generator.py"
click node_inference_api "https://github.com/ertis-research/kafka-ml/blob/master/backend/automl/views/inferences.py"
click node_datasource_sinks "https://github.com/ertis-research/kafka-ml/blob/master/datasources/sink.py"
click node_control_logger "https://github.com/ertis-research/kafka-ml/blob/master/kafka_control_logger/logger.py"
click node_tf_executor "https://github.com/ertis-research/kafka-ml/blob/master/mlcode_executor/tfexecutor/app.py"
click node_pytorch_executor "https://github.com/ertis-research/kafka-ml/blob/master/mlcode_executor/pthexecutor/app.py"
click node_tf_training "https://github.com/ertis-research/kafka-ml/blob/master/model_training/tensorflow/mainTraining.py"
click node_pytorch_training "https://github.com/ertis-research/kafka-ml/blob/master/model_training/pytorch/training.py"
click node_tf_inference "https://github.com/ertis-research/kafka-ml/blob/master/model_inference/tensorflow/inference.py"
click node_pytorch_inference "https://github.com/ertis-research/kafka-ml/blob/master/model_inference/pytorch/inference.py"
click node_federated_backend "https://github.com/ertis-research/kafka-ml/blob/master/federated-module/federated_backend/automl/views.py"
click node_federated_training "https://github.com/ertis-research/kafka-ml/blob/master/federated-module/federated_model_training/tensorflow/federated_mainTraining.py"
click node_kubernetes "https://github.com/ertis-research/kafka-ml/blob/master/kustomize/local/kustomization.yaml"

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_ui,node_ui_routes,node_visualization_ws,node_django_api,node_domain,node_deployment_orchestrator,node_manifest_generator,node_inference_api toneBlue
class node_kafka,node_datasource_sinks,node_control_logger,node_tf_executor,node_pytorch_executor,node_tf_training,node_pytorch_training,node_tf_inference,node_pytorch_inference toneAmber
class node_federated_backend,node_federated_training toneMint
class node_kubernetes toneRose
```

## Components

### Control Plane

- [Angular UI](https://github.com/ertis-research/kafka-ml/blob/master/frontend/src/main.ts): frontend · Manages models, deployments, devices, results, and visualization. · `frontend/src/main.ts`
- [UI routes](https://github.com/ertis-research/kafka-ml/blob/master/frontend/src/app/app-routing.module.ts): routing · `frontend/src/app/app-routing.module.ts`
- [Visualization WebSocket](https://github.com/ertis-research/kafka-ml/blob/master/frontend/src/app/services/visualization-ws.service.ts): websocket client · `frontend/src/app/services/visualization-ws.service.ts`
- [Django API / ASGI](https://github.com/ertis-research/kafka-ml/blob/master/backend/manage.py): control API · HTTP and real-time control-plane entry point. · `backend/manage.py`
- [Domain state](https://github.com/ertis-research/kafka-ml/blob/master/backend/automl/models.py): Django models · Persists configurations, deployments, training, and inference state. · `backend/automl/models.py`
- [Deployment orchestrator](https://github.com/ertis-research/kafka-ml/blob/master/backend/automl/views/deployments.py): API views · Turns deployment requests into Kubernetes workloads. · `backend/automl/views/deployments.py`
- [Job manifest generator](https://github.com/ertis-research/kafka-ml/blob/master/backend/automl/views/utils/job_manifest_generator.py): Kubernetes manifests · `backend/automl/views/utils/job_manifest_generator.py`
- [Inference API](https://github.com/ertis-research/kafka-ml/blob/master/backend/automl/views/inferences.py): API views · `backend/automl/views/inferences.py`

### Streaming ML

- **Apache Kafka**: stream boundary · Carries records, predictions, metrics, and control events.
- [Datasource sinks](https://github.com/ertis-research/kafka-ml/blob/master/datasources/sink.py): producer library · External raw and Avro producer integration boundary. · `datasources/sink.py`
- [Kafka control logger](https://github.com/ertis-research/kafka-ml/blob/master/kafka_control_logger/logger.py): lifecycle monitor · `kafka_control_logger/logger.py`
- [TensorFlow executor](https://github.com/ertis-research/kafka-ml/blob/master/mlcode_executor/tfexecutor/app.py): ML code runtime · Isolates user TensorFlow/Keras code from the backend. · `mlcode_executor/tfexecutor/app.py`
- [PyTorch executor](https://github.com/ertis-research/kafka-ml/blob/master/mlcode_executor/pthexecutor/app.py): ML code runtime · Isolates user PyTorch code from the backend. · `mlcode_executor/pthexecutor/app.py`
- [TensorFlow training](https://github.com/ertis-research/kafka-ml/blob/master/model_training/tensorflow/mainTraining.py): training worker · Runs classic, distributed, incremental, semi-supervised, and related modes. · `model_training/tensorflow/mainTraining.py`
- [PyTorch training](https://github.com/ertis-research/kafka-ml/blob/master/model_training/pytorch/training.py): training worker · `model_training/pytorch/training.py`
- [TensorFlow inference](https://github.com/ertis-research/kafka-ml/blob/master/model_inference/tensorflow/inference.py): inference worker · Consumes input topics and publishes predictions. · `model_inference/tensorflow/inference.py`
- [PyTorch inference](https://github.com/ertis-research/kafka-ml/blob/master/model_inference/pytorch/inference.py): inference worker · `model_inference/pytorch/inference.py`

### Federated Learning

Separate TensorFlow deployment slice.

- [Federated backend](https://github.com/ertis-research/kafka-ml/blob/master/federated-module/federated_backend/automl/views.py): federated control API · Coordinates federated device and model control events. · `federated-module/federated_backend/automl/views.py`
- [Federated TF training](https://github.com/ertis-research/kafka-ml/blob/master/federated-module/federated_model_training/tensorflow/federated_mainTraining.py): aggregation worker · Aggregates client model updates without centralizing raw data. · `federated-module/federated_model_training/tensorflow/federated_mainTraining.py`

### Runtime Platform

- [Kubernetes + Kustomize](https://github.com/ertis-research/kafka-ml/blob/master/kustomize/local/kustomization.yaml): workload platform · Schedules containerized services with CPU and GPU overlays. · `kustomize/local/kustomization.yaml`

## Connections

- Angular UI → UI routes: navigates
- Angular UI → Django API / ASGI: REST requests
- Angular UI → Visualization WebSocket: visualizes through
- Visualization WebSocket → Django API / ASGI: WebSocket updates
- Django API / ASGI → Domain state: reads and records state
- Django API / ASGI → Deployment orchestrator: deployment requests
- Django API / ASGI → Inference API: inference state
- Deployment orchestrator → Job manifest generator: generates
- Job manifest generator → Kubernetes + Kustomize: applies workloads
- Kubernetes + Kustomize → TensorFlow executor: runs
- Kubernetes + Kustomize → PyTorch executor: runs
- Kubernetes + Kustomize → TensorFlow training: runs
- Kubernetes + Kustomize → PyTorch training: runs
- Kubernetes + Kustomize → TensorFlow inference: runs
- Kubernetes + Kustomize → PyTorch inference: runs
- Datasource sinks → Apache Kafka: publishes records
- TensorFlow training → Apache Kafka: consumes data; publishes results
- PyTorch training → Apache Kafka: consumes data; publishes results
- TensorFlow inference → Apache Kafka: consumes inputs; publishes predictions
- PyTorch inference → Apache Kafka: consumes inputs; publishes predictions
- Kafka control logger → Apache Kafka: monitors control events
- Federated backend → Apache Kafka: coordinates control events
- Federated TF training → Apache Kafka: aggregates client updates
- Kubernetes + Kustomize → Federated backend: deploys
- Kubernetes + Kustomize → Federated TF training: deploys
