# ganeshmohane/safteycheck architecture

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

- Interactive diagram: https://gitdiagram.com/ganeshmohane/safteycheck
- Repository: https://github.com/ganeshmohane/safteycheck

## Overview

##### Project type and purpose
- Project Type: Standalone deep-learning pipeline for real-time PPE detection.
- Purpose: Inference service that ingests camera feed, runs a CNN model (ppe_honors.h5), and flags missing PPE.  Training components sit alongside for offline model development.

##### File structure
- Top-level artifacts:
– honors_app.py – the main inference script
– requirements.txt – Python dependencies (e.g., OpenCV, TensorFlow/Keras)
– trained_model(CNN)/ppe_honors.h5 – serialized CNN model
– dataset/ppe_equipments – organized train/valid/test splits and class mappings
– kaggle notebook.txt – training notebook (Keras)
– outputs-ss/ – screenshot outputs for validation
– Report - SafetyCheck.pdf – design/analysis doc
- No separate “frontend” or “backend” folders: the entire system is a Python‐based monolith that can be later refactored into microservices if needed.

##### README for additional insights
- Confirms real-time camera input and CNN-based inference.
- Emphasizes “AI-Powered PPE Detection for Healthcare Safety.”

##### Main components
a. Data & Training Subsystem
– Dataset (ppe_equipments/train, valid, test + class CSVs)
– Training Notebook / Script (kaggle notebook.txt)
– Model Registry / Artifacts (ppe_honors.h5)
b. Inference Subsystem
– Camera / Video Feed (OpenCV capture)
– honors_app.py business logic
- Preprocessing (resize, normalization)
- Model Loader (loads ppe_honors.h5 via Keras)
- Inference Engine (runs CNN forward pass)
- Alert Module (console/UI overlay; could be extended to send notifications)
– Output Display (live annotated stream + optional logging)
c. External / Future Extensions
– Storage (e.g., database or file system for logs)
– Alerting Service (SMS/email/webhook)
– Web Dashboard / REST API

##### Relationships and interactions
- Training flow (one-time or periodic): Dataset → Training Notebook/Script → Trained Model → Model Registry
- Inference flow (continuous): Camera Feed → honors_app.py → Model Loader → CNN Inference → Post-processing → Display/Alerts → (Optional) Logging/DB

##### Architectural patterns & design principles
- Separation of Concerns: clearly separate data ingestion, model inference, and output handling.
- Modularization: group preprocessing, model loading, inference, and post-processing into distinct modules (even if currently in one script).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Training Subsystem
    subgraph "Training Subsystem"
        direction TB
        Dataset["Dataset"]:::training
        TrainSplit["Train Split (_classes.csv)"]:::training
        ValidSplit["Valid Split (_classes.csv)"]:::training
        TestSplit["Test Split (_classes.csv)"]:::training
        Notebook["Training Notebook / Script"]:::training
        ModelArtifact["Trained Model Artifact"]:::training
    end

    Dataset -->|"provides data"| TrainSplit
    Dataset -->|"provides data"| ValidSplit
    Dataset -->|"provides data"| TestSplit
    TrainSplit -->|"used by"| Notebook
    ValidSplit -->|"used by"| Notebook
    TestSplit -->|"used by"| Notebook
    Notebook -->|"trains model"| ModelArtifact

    %% Inference Subsystem
    subgraph "Inference Subsystem"
        direction TB
        Camera["Camera / Video Feed"]:::inference
        Preprocess["Preprocessing Module"]:::inference
        ModelLoader["Model Loader"]:::inference
        InferenceEngine["Inference Engine"]:::inference
        Postprocess["Post-processing Module"]:::inference
        AlertModule["Alert Module"]:::inference
        OutputDisplay["Output Display"]:::inference
        HonorsApp["Inference Entry Point\n(honors_app.py)"]:::inference
        Requirements["Dependencies\n(requirements.txt)"]:::inference
    end

    Camera -->|"raw frames"| Preprocess
    Preprocess -->|"tensors"| ModelLoader
    ModelLoader -->|"model loaded"| InferenceEngine
    InferenceEngine -->|"detections"| Postprocess
    Postprocess -->|"annotated frames"| AlertModule
    AlertModule -->|"alerts/logs"| OutputDisplay
    Camera -->|"entry point"| HonorsApp
    Preprocess --> HonorsApp
    ModelLoader --> HonorsApp
    InferenceEngine --> HonorsApp
    Postprocess --> HonorsApp
    AlertModule --> HonorsApp
    HonorsApp --> Requirements

    %% External / Future Extensions
    subgraph "External & Future Extensions"
        direction TB
        Storage["Storage / Logs"]:::external
        AlertService["Alerting Service"]:::external
        WebDashboard["Web Dashboard / REST API"]:::external
        Report["Design / Analysis Document"]:::external
        README["Project Overview / README"]:::external
        Screenshots["Validation Screenshots"]:::external
    end

    OutputDisplay -->|"log outputs"| Storage
    AlertModule -->|"send alert"| AlertService
    AlertService --> WebDashboard
    Report --> README

    %% Click Events
    click Dataset "https://github.com/ganeshmohane/safteycheck/tree/main/dataset/ppe_equipments"
    click TrainSplit "https://github.com/ganeshmohane/safteycheck/blob/main/dataset/ppe_equipments/train/_classes.csv"
    click ValidSplit "https://github.com/ganeshmohane/safteycheck/blob/main/dataset/ppe_equipments/valid/_classes.csv"
    click TestSplit "https://github.com/ganeshmohane/safteycheck/blob/main/dataset/ppe_equipments/test/_classes.csv"
    click Notebook "https://github.com/ganeshmohane/safteycheck/blob/main/kaggle notebook.txt"
    click ModelArtifact "https://github.com/ganeshmohane/safteycheck/blob/main/trained_model(CNN)/ppe_honors.h5"
    click HonorsApp "https://github.com/ganeshmohane/safteycheck/blob/main/honors_app.py"
    click Requirements "https://github.com/ganeshmohane/safteycheck/blob/main/requirements.txt"
    click Screenshots "https://github.com/ganeshmohane/safteycheck/tree/main/outputs-ss/"
    click Report "https://github.com/ganeshmohane/safteycheck/blob/main/Report - SafteyCheck.pdf"
    click README "https://github.com/ganeshmohane/safteycheck/blob/main/README.md"

    %% Styles
    classDef training fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef inference fill:#D0FFD8,stroke:#22863a,color:#22863a;
    classDef external fill:#EEEEEE,stroke:#6a737d,color:#6a737d;
```
