# azizamari/electrical_schema_recognition architecture

> Architecture diagram of the GitHub repository azizamari/electrical_schema_recognition, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azizamari/electrical_schema_recognition
- Repository: https://github.com/azizamari/electrical_schema_recognition

## Overview

##### Project Type & Purpose
- This project is a specialized computer vision and machine learning system designed to detect and interpret handwritten electrical circuits. It applies image preprocessing, data augmentation, object detection (using YOLOv5), and image processing techniques for terminal detection. Additionally, there is a backend API (via FastAPI) for inference and a Dockerized deployment for use as a microservice.
- The project appears to be a full-stack application in its own right (with its own ML pipelines, API endpoints, and deployment support), though its main focus is on ML/Computer Vision tasks.

##### File Structure
- At the top level, the project includes files like Dockerfile, .gitignore, main.py, model (with a trained model file), requirements.txt, and several Python scripts.
- Supporting files like “adaptive_thresholding.py”, “augmentation_pipeline.py”, and “utils_functions.py” suggest standalone processing modules.
- The “yolov5” directory indicates that either the repository is using YOLOv5 as a library or directly referencing its implementation for object detection.

##### Components & Their Relationships
- Data Preprocessing & Augmentation:
- adaptive_thresholding.py — applies adaptive thresholding with OpenCV.
- augmentation_pipeline.py — augments images using the albumentations library.
- Model Training & Inference:
- main.py — likely the entry point coordinating the ingestion of an image, preprocessing, object detection using the pre-trained YOLOv5 model (model/modelv1.pt), and further processing.
- yolov5 directory — contains the YOLOv5 implementation for model training/inference.
- Terminal Recognition:
- Node Recognition:
- node_recognition/ — holds experimental scripts for future expansion regarding node/component connectivity or circuit topology analysis.
- Backend API & Deployment:
- The README mentions simple endpoints built using FastAPI; while explicit API code isn’t present in this file tree, it is referenced in the README and might be integrated within main.py or another module.
- Dockerfile — containerization for deployment as a microservice.
- Utility Functions:
- utils_functions.py — common helper methods supporting various processes.

##### Architectural Patterns & Technologies
- Modular design to separate responsibilities: preprocessing, data augmentation, ML model inference, and image processing based terminal recognition.
- Use of external libraries (OpenCV, albumentations, FastAPI, and YOLOv5) which are important to highlight.
- Containerization with Docker facilitates microservice deployment.
- The workflow exhibits a pipeline design where output from one stage is directly used by the next.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Input Layer
    input["Image Input"]:::input

    %% Preprocessing Module
    subgraph "Preprocessing Module"
        adaptive["Adaptive Thresholding (OpenCV)"]:::preprocessing
        augmentation["Data Augmentation (Albumentations)"]:::preprocessing
    end

    %% ML Object Detection Module
    subgraph "ML Object Detection Module"
        main["Main Module (FastAPI & ML Controller)"]:::ml
        yolo["YOLOv5 Object Detection (PyTorch)"]:::ml
        model["Pre-trained Model"]:::ml
    end

    %% Terminal Recognition Module
    subgraph "Terminal Recognition Module"
        terminal["Terminal Recognition (Bounding Boxes, Intersection, KMeans)"]:::terminal
    end

    %% Node Recognition Module (Experimental)
    subgraph "Node Recognition Module (Experimental)"
        node["Node Recognition (Experimental Scripts)"]:::node
    end

    %% API Response
    apiresponse["API Response (FastAPI)"]:::api

    %% Deployment Container
    docker["Dockerized Deployment Container"]:::docker

    %% Utility Functions
    utility["Utility Functions"]:::utility

    %% Data Flow Connections
    input --> adaptive
    input --> augmentation
    adaptive --> main
    augmentation --> main
    yolo --> main
    model --> main
    main --> terminal
    main --> apiresponse
    main --> docker
    main -->|"uses"| utility
    %% Optional Experimental Branch
    main -->|"optional"| node

    %% Class Definitions for Color Coding
    classDef input fill:#A3E4D7,stroke:#333,stroke-width:2px;
    classDef preprocessing fill:#FAD7A0,stroke:#333,stroke-width:2px;
    classDef ml fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef terminal fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef node fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef api fill:#D2B4DE,stroke:#333,stroke-width:2px;
    classDef docker fill:#D5DBDB,stroke:#333,stroke-width:2px;
    classDef utility fill:#F5B7B1,stroke:#333,stroke-width:2px;

    %% Assign style to API Response node explicitly
    class apiresponse api

    %% Click Events
    click adaptive "https://github.com/azizamari/electrical_schema_recognition/blob/master/adaptive_thresholding.py"
    click augmentation "https://github.com/azizamari/electrical_schema_recognition/blob/master/augmentation_pipeline.py"
    click main "https://github.com/azizamari/electrical_schema_recognition/blob/master/main.py"
    click model "https://github.com/azizamari/electrical_schema_recognition/blob/master/model/modelv1.pt"
    click yolo "https://github.com/azizamari/electrical_schema_recognition/tree/master/yolov5"
    click terminal "https://github.com/azizamari/electrical_schema_recognition/tree/master/terminal_recognition"
    click node "https://github.com/azizamari/electrical_schema_recognition/tree/master/node_recognition"
    click docker "https://github.com/azizamari/electrical_schema_recognition/tree/master/Dockerfile"
    click utility "https://github.com/azizamari/electrical_schema_recognition/blob/master/utils_functions.py"
```
