# igli333/ppe-detection-solution architecture

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

- Interactive diagram: https://gitdiagram.com/igli333/ppe-detection-solution
- Repository: https://github.com/igli333/ppe-detection-solution

## Overview

##### Main Components
- Frontend: The “ppe-frontend” directory contains a ReactJS application. This serves as the user interface to show live video streaming, dashboards, notifications, and statistics.
- Microservices: There are several microservices, each in its own directory:
- ms-ml: Implements the YOLO-based detection model (YoloRecognitionModel.py) and encapsulates the AI/ML aspects.
- ms-data-processing: Responsible for pre-processing or segmenting data frames (DataProcessingService.py) before sending them for analysis downstream.
- ms-gateway: Acts as the central communication hub with components such as KafkaConsumer, NotificationPropagator, User modules, and UsersService.
- ms-notification: Manages alert distribution and notifications (app.py in ms-notification).
- ms-streaming: Likely handles the streaming portion where incoming video feeds are processed and transmitted (app.py in ms-streaming).
- ms-validation: Provides additional checks or post-processing on detected PPE (ValidationService.py).
- Messaging/Integration: Though not a node on its own in the file tree, the README clearly states the use of a Kafka cluster as the message broker to which real-time video frames are published and consumed.
- Datasets & Training: The “preprocessed_dataset” directory and “training.ipynb” hint that there is an offline dataset and model training facility contributing to the ML aspects.

##### Relationships and Interactions
- Data Flow:
- Video frames captured at the edge (external cameras) are sent into a Kafka cluster.
- The ms-ml service consumes frames from Kafka for PPE detection.
- The resulting detections are routed through ms-data-processing and ms-validation for further processing or verification.
- ms-gateway acts as the integration point; it reads from Kafka (as indicated by KafkaConsumer) and directs notifications via the ms-notification service.
- ms-streaming then provides processed frames/data to the frontend for live streaming.
- API/Service Calls:
- The ms-gateway service might also handle user management and expose APIs to the frontend.
- Communication between services will be managed over network protocols (REST, messaging via Kafka, etc.), and container deployments are managed via Docker/Docker Compose.

##### Architectural Patterns & Technologies
- Microservice Architecture: Each service is separately containerized (each has its own Dockerfile) and encapsulates domain-specific functionality.
- Event-Driven Architecture: The use of Kafka indicates an event-driven or messaging-based system for real-time data flow.
- Frontend/Backend Separation: Clear separation between the ReactJS frontend and several backend microservices.
- Containerization and Orchestration: Deployment via Docker and Docker Compose.

- Clearly label interactions (synchronous API calls vs. asynchronous messaging).
- Incorporate any dependencies depicted in the README (for example, the screenshots indicate key UI components and the overall pipeline).

Happy designing!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Layer
    subgraph "External Layer"
        cameras["External Cameras"]:::external
        kafka["Kafka Cluster"]:::external
    end

    cameras -->|"sends_frames"| kafka

    %% Backend Microservices Layer (Docker Containers)
    subgraph "Backend Microservices"
        msMl["ms-ml (AI/ML)"]:::service
        msDataProcessing["ms-data-processing (Pre-processing)"]:::service
        msValidation["ms-validation (Validation)"]:::service
        msGateway["ms-gateway (API_&_Integration)"]:::service
        msNotification["ms-notification (Notification)"]:::service
        msStreaming["ms-streaming (Streaming)"]:::service
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        ppeFrontend["ReactJS Application"]:::frontend
    end

    %% Support Layer
    subgraph "Support Layer"
        training["Training Notebook"]:::support
        dataset["Preprocessed Dataset"]:::support
    end

    %% Data Flow Connections
    kafka -->|"frame_data"| msMl
    kafka -->|"api_data"| msGateway

    msMl -->|"detection_results"| msDataProcessing
    msMl -->|"detection_results"| msValidation

    msDataProcessing -->|"processed_data"| msGateway
    msValidation -->|"verified_data"| msGateway

    msGateway -->|"notification_trigger"| msNotification
    msGateway -->|"streaming_data"| msStreaming

    msStreaming -->|"live_stream"| ppeFrontend

    training -->|"model_updates"| msMl
    dataset -->|"training_data"| msMl

    %% Click Events for Component Mapping
    click ppeFrontend "https://github.com/igli333/ppe-detection-solution/tree/main/ppe-frontend/"
    click msMl "https://github.com/igli333/ppe-detection-solution/tree/main/ms-ml/"
    click msDataProcessing "https://github.com/igli333/ppe-detection-solution/tree/main/ms-data-processing/"
    click msGateway "https://github.com/igli333/ppe-detection-solution/tree/main/ms-gateway/"
    click msNotification "https://github.com/igli333/ppe-detection-solution/blob/main/ms-notification/app.py"
    click msStreaming "https://github.com/igli333/ppe-detection-solution/blob/main/ms-streaming/app.py"
    click msValidation "https://github.com/igli333/ppe-detection-solution/tree/main/ms-validation/"
    click training "https://github.com/igli333/ppe-detection-solution/blob/main/training.ipynb"
    click dataset "https://github.com/igli333/ppe-detection-solution/tree/main/preprocessed_dataset/"

    %% Styles
    classDef external fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef service fill:#87CEFA,stroke:#1E90FF,stroke-width:2px;
    classDef frontend fill:#90EE90,stroke:#32CD32,stroke-width:2px;
    classDef support fill:#DDA0DD,stroke:#FF69B4,stroke-width:2px;
```
