# taherfattahi/dnn-distance-line-protection-zone architecture

> Architecture diagram of the GitHub repository taherfattahi/dnn-distance-line-protection-zone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/taherfattahi/dnn-distance-line-protection-zone
- Repository: https://github.com/taherfattahi/dnn-distance-line-protection-zone

## Overview

1. **Repository purpose**
   - This repo is a small ML-to-embedded deployment pipeline for **distance relay protection zone classification**.
   - The core business goal is to reproduce the **Micom P543 distance relay curve** from measured test data, then run the resulting classifier on an embedded target.

2. **Data generation layer**
   - The source data is stored in **`DistanceDataset.csv`**.
   - Per the README, the dataset was created by testing a **Schneider Electric Micom P543 relay** with a **Vebko AMT105 relay tester**.
   - This is the only clearly identified external hardware/data-acquisition boundary in the project.

3. **Offline model development subsystem**
   - Training and experimentation happen outside the runtime application in:
     - **`DistanceLineProtectionZone_DNN.ipynb`**
     - **`DistanceLineProtectionZone_RandomForest.ipynb`**
     - **`distancelineprotectionzone_DNN.py`**
     - **`DistanceLineProtectionZone_randomforest.py`**
   - These files represent two alternative model paths:
     - a **TensorFlow deep neural network**
     - a **scikit-learn random forest**
   - The README indicates the DNN is the primary path for deployment because it reaches the embedded runtime via TFLite.

4. **Model artifact layer**
   - Trained artifacts are checked into **`model/`**:
     - **`model/model.h5`**: the TensorFlow/Keras model checkpoint/export
     - **`model/tfliteModel.tflite`**: the converted TensorFlow Lite model used at runtime
   - This is the key boundary between training and deployment: the training stack produces the `.h5`, and deployment consumes the `.tflite`.

5. **Conversion step**
   - The architecture includes a model conversion stage from TensorFlow/Keras to **TensorFlow Lite**.
   - That conversion is what makes the model suitable for constrained or embedded environments such as ARM boards.
   - In practice, this creates a portability boundary: full TensorFlow for training, TFLite for inference.

6. **Runtime inference application**
   - The executable entrypoint is **`main.go`**.
   - It is a **Go application** that calls into the **TensorFlow Lite C API** via CGO.
   - The app is the deployment-time inference wrapper: it loads the TFLite model and runs prediction, rather than retraining or doing offline analysis.

7. **Native ML runtime dependency**
   - The repo vendors the TensorFlow Lite C headers under **`include/tensorflow/lite/c/`**.
   - It also includes platform-specific native libraries:
     - **`amd64/`**
     - **`arm/`**
     - **`macosx/libtensorflowlite_c.dylib`**
   - This indicates the runtime is intentionally split across platforms and relies on native shared libraries outside the Go code.

8. **Target deployment environments**
   - The README explicitly targets:
     - **Linux/macOS amd64**
     - **ARM-based embedded boards**, especially **Xilinx Zynq-7020**
   - The runtime boundary is therefore not a cloud service or web app; it is an **embedded inference application** that must be built per architecture.

9. **Containerization**
   - **`Dockerfile`** provides a containerized execution path.
   - Docker is used to package the runtime environment, likely including the Go binary and native TFLite dependencies.
   - This is a deployment convenience layer, not part of the ML pipeline itself.

10. **Build/tooling model**
    - The README shows two distinct build concerns:
      - building TensorFlow Lite C from source externally
      - building this repo’s Go binary against that native library
    - So the repo depends on a **system-level native ML runtime** rather than pure-Go inference.

11. **Architecture summary for diagramming**
    - A good diagram would show:
      - **hardware test setup** → generates **CSV dataset**
      - **training notebooks/scripts** → produce **TensorFlow model**
      - **TFLite conversion** → produces **deployment model**
      - **Go/TFLite runtime** → loads model and performs inference
      - **platform-specific native libs** → support execution on amd64 / ARM / macOS
      - **Docker** as an optional packaging layer around the runtime

12. **Important boundary to preserve**
    - The project is split cleanly into **offline ML development** and **online embedded inference**.
    - The training side is Python/TensorFlow/scikit-learn; the runtime side is Go + TFLite C.
    - That separation is the central architectural feature of the repository.

Main entry points: [`main.go`](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/main.go) (Go app), [`DistanceDataset.csv`](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/DistanceDataset.csv) (Dataset), [`include/tensorflow/lite/c/c_api.h`](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/include/tensorflow/lite/c/c_api.h) (TFLite C API), [`README.md`](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/README.md) (README)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data acquisition"]
  node_dataset["Dataset<br/>relay data"]
end

subgraph group_offline["Offline ML"]
  node_dnn_nb["DNN notebook<br/>training notebook"]
  node_rf_nb["RF notebook<br/>training notebook"]
  node_dnn_py["DNN script<br/>training script"]
  node_rf_py["RF script<br/>training script"]
end

subgraph group_artifacts["Model artifacts"]
  node_tf_train[("TensorFlow model<br/>keras model<br/>[model.h5]")]
  node_tflite_model[("TFLite model<br/>deployment model<br/>[tfliteModel.tflite]")]
end

subgraph group_runtime["Embedded runtime"]
  node_main_go["Go app<br/>inference service<br/>[main.go]"]
  node_main_dir["main package<br/>go package"]
  node_go_mod["Go module<br/>module config<br/>[go.mod]"]
end

subgraph group_native["Native TFLite"]
  node_tflite_c["TFLite C API<br/>native api<br/>[c_api.h]"]
  node_tflite_common["TFLite common<br/>native headers<br/>[common.h]"]
  node_amd64_lib["amd64 lib<br/>native library"]
  node_arm_lib["arm lib<br/>native library"]
  node_mac_lib["macOS lib<br/>native library"]
end

subgraph group_deploy["Packaging"]
  node_dockerfile["Dockerfile<br/>container build"]
  node_readme["README<br/>docs<br/>[README.md]"]
end

node_dataset -->|"trains"| node_dnn_nb
node_dataset -->|"trains"| node_rf_nb
node_dataset -->|"trains"| node_dnn_py
node_dataset -->|"trains"| node_rf_py
node_dnn_nb -->|"produces"| node_tf_train
node_dnn_py -->|"produces"| node_tf_train
node_rf_nb -.->|"matches"| node_rf_py
node_tf_train -->|"converts"| node_tflite_model
node_tflite_model -->|"loads"| node_main_go
node_main_go -->|"calls"| node_tflite_c
node_main_go -->|"calls"| node_tflite_common
node_tflite_c -->|"links"| node_amd64_lib
node_tflite_c -->|"links"| node_arm_lib
node_tflite_c -->|"links"| node_mac_lib
node_go_mod -->|"builds"| node_main_go
node_main_dir -->|"packages"| node_main_go
node_dockerfile -->|"packages"| node_main_go
node_dockerfile -.->|"bundles"| node_amd64_lib
node_readme -.->|"documents"| node_dataset
node_readme -.->|"documents"| node_main_go
node_readme -.->|"documents"| node_tflite_model

click node_dataset "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/DistanceDataset.csv"
click node_dnn_nb "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/DistanceLineProtectionZone_DNN.ipynb"
click node_rf_nb "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/DistanceLineProtectionZone_RandomForest.ipynb"
click node_dnn_py "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/distancelineprotectionzone_DNN.py"
click node_rf_py "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/DistanceLineProtectionZone_randomforest.py"
click node_tf_train "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/model/model.h5"
click node_tflite_model "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/model/tfliteModel.tflite"
click node_main_go "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/main.go"
click node_main_dir "https://github.com/taherfattahi/dnn-distance-line-protection-zone/tree/master/main"
click node_go_mod "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/go.mod"
click node_tflite_c "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/include/tensorflow/lite/c/c_api.h"
click node_tflite_common "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/include/tensorflow/lite/c/common.h"
click node_amd64_lib "https://github.com/taherfattahi/dnn-distance-line-protection-zone/tree/master/amd64"
click node_arm_lib "https://github.com/taherfattahi/dnn-distance-line-protection-zone/tree/master/arm"
click node_mac_lib "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/macosx/libtensorflowlite_c.dylib"
click node_dockerfile "https://github.com/taherfattahi/dnn-distance-line-protection-zone/tree/master/Dockerfile"
click node_readme "https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/README.md"

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_dataset toneBlue
class node_dnn_nb,node_rf_nb,node_dnn_py,node_rf_py toneAmber
class node_tf_train,node_tflite_model toneMint
class node_main_go,node_main_dir,node_go_mod toneRose
class node_tflite_c,node_tflite_common,node_amd64_lib,node_arm_lib,node_mac_lib toneIndigo
class node_dockerfile,node_readme toneTeal
```

## Components

### Data acquisition

External relay test data captured from protection hardware and stored for model development.

- [Dataset](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/DistanceDataset.csv): relay data · Measured relay test data used to learn the distance protection zones. · `DistanceDataset.csv`

### Offline ML

Python and notebook workflows for training and comparing zone classifiers.

- [DNN notebook](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/DistanceLineProtectionZone_DNN.ipynb): training notebook · Interactive TensorFlow workflow for the deep neural network path. · `DistanceLineProtectionZone_DNN.ipynb`
- [RF notebook](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/DistanceLineProtectionZone_RandomForest.ipynb): training notebook · Interactive scikit-learn workflow for the random forest path. · `DistanceLineProtectionZone_RandomForest.ipynb`
- [DNN script](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/distancelineprotectionzone_DNN.py): training script · Scripted TensorFlow/Keras training and experimentation entrypoint. · `distancelineprotectionzone_DNN.py`
- [RF script](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/DistanceLineProtectionZone_randomforest.py): training script · Scripted random forest training and evaluation path. · `DistanceLineProtectionZone_randomforest.py`

### Model artifacts

Persisted trained model outputs used as deployment inputs.

- [TensorFlow model](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/model/model.h5): keras model · Primary learned classifier before conversion to embedded format. · `model/model.h5`
- [TFLite model](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/model/tfliteModel.tflite): deployment model · Converted model consumed by the runtime inference app. · `model/tfliteModel.tflite`

### Embedded runtime

Go-based inference application that executes the deployed classifier.

- [Go app](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/main.go): inference service · Deployment-time application that loads the TFLite model and runs predictions. · `main.go`
- [main package](https://github.com/taherfattahi/dnn-distance-line-protection-zone/tree/master/main): go package · Go entry package wiring the executable runtime. · `main`
- [Go module](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/go.mod): module config · Module definition for building the Go inference binary. · `go.mod`

### Native TFLite

Platform-specific TensorFlow Lite C runtime and vendored headers.

- [TFLite C API](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/include/tensorflow/lite/c/c_api.h): native api · Vendored TensorFlow Lite C headers used through CGO. · `include/tensorflow/lite/c/c_api.h`
- [TFLite common](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/include/tensorflow/lite/c/common.h): native headers · Additional TensorFlow Lite C interface headers. · `include/tensorflow/lite/c/common.h`
- [amd64 lib](https://github.com/taherfattahi/dnn-distance-line-protection-zone/tree/master/amd64): native library · Platform-specific TensorFlow Lite shared library for amd64 builds. · `amd64`
- [arm lib](https://github.com/taherfattahi/dnn-distance-line-protection-zone/tree/master/arm): native library · Platform-specific TensorFlow Lite shared library for ARM builds. · `arm`
- [macOS lib](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/macosx/libtensorflowlite_c.dylib): native library · macOS TensorFlow Lite shared library for local builds. · `macosx/libtensorflowlite_c.dylib`

### Packaging

Container and repo-level build packaging for deployment.

- [Dockerfile](https://github.com/taherfattahi/dnn-distance-line-protection-zone/tree/master/Dockerfile): container build · Container recipe packaging the runtime and native dependencies. · `Dockerfile`
- [README](https://github.com/taherfattahi/dnn-distance-line-protection-zone/blob/master/README.md): docs · Project documentation describing dataset, training, conversion, and deployment. · `README.md`

## Connections

- Dataset → DNN notebook: trains · Dataset feeds the DNN experimentation notebook.
- Dataset → RF notebook: trains · Dataset feeds the random forest experimentation notebook.
- Dataset → DNN script: trains · Dataset feeds scripted TensorFlow training.
- Dataset → RF script: trains · Dataset feeds scripted random forest training.
- DNN notebook → TensorFlow model: produces · Notebook workflow produces the TensorFlow/Keras model artifact.
- DNN script → TensorFlow model: produces · Scripted DNN training produces the Keras model artifact.
- RF notebook → RF script: matches · Notebook and script represent the same random forest path.
- TensorFlow model → TFLite model: converts · TensorFlow model is converted to TensorFlow Lite for deployment.
- TFLite model → Go app: loads · Runtime loads the embedded inference model.
- Go app → TFLite C API: calls · Go runtime uses the TensorFlow Lite C API via CGO.
- Go app → TFLite common: calls · Runtime depends on additional vendored TFLite headers.
- TFLite C API → amd64 lib: links · amd64 builds resolve against the native TFLite shared library.
- TFLite C API → arm lib: links · ARM builds resolve against the native TFLite shared library.
- TFLite C API → macOS lib: links · macOS builds resolve against the native TFLite shared library.
- Go module → Go app: builds · Go module defines the executable build.
- main package → Go app: packages · Main package contains the program entry wiring.
- Dockerfile → Go app: packages · Container image packages the Go inference binary.
- Dockerfile → amd64 lib: bundles · Container may include platform-specific native runtime support.
- README → Dataset: documents · README describes the measured relay dataset source.
- README → Go app: documents · README describes the deployment runtime and targets.
- README → TFLite model: documents · README explains the TFLite deployment artifact.
