# mounseflit/salamtyai architecture

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

- Interactive diagram: https://gitdiagram.com/mounseflit/salamtyai
- Repository: https://github.com/mounseflit/salamtyai

## Overview

##### Project type and purpose
- This is a full-stack real-time video analytics application for industrial safety.
- Frontend: React web dashboard & monitoring UI.
- Backend/API: Flask services for video processing, model inference, and data persistence.
- ML components: YOLOv8-based safety-gear detection & hand-gesture detection.
- Database: Firebase Firestore for incident logs and statistics.
- Edge integration: Raspberry Pi or camera feed for live video input.

##### File structure
- Top-level directories:
- Backend (legacy or auxiliary Flask code under Backend/)
- flask_api (primary Flask app: app.py, credentials, model.json)
- Frontend (React app: package.json, src/, public/)
- models (Python scripts & model artifacts for detection)
- Docs & images (project docs and assets)
- Configuration: requirements.txt, package.json, Firebase admin SDK JSON
- Patterns: Monolithic Flask API hosting multiple ML modules, React single-page app, integration via REST & WebSocket.

##### Key README insights
- Live video feed ingestion → ML inference → alerts & dashboard updates
- Tech stack: Python, OpenCV, TensorFlow, YOLOv8, Flask, React, Firebase, RaspberryPi
- Features: real-time detection, proactive alerts, historical statistics

a. Main components:
1. Video Source (Industrial cameras / Raspberry Pi sensor agent)
2. Edge Agent (optional Pi service sending frames to backend)
3. Flask API Server (flask_api/app.py)
– Authentication & Authorization (via Firebase Admin SDK)
– REST endpoints (e.g., /detect, /stats)
– WebSocket or Server-Sent Events for real-time updates
4. Model Inference Layer
– Safety Gear Detection (YOLOv8 model under models/)
– Hand Gesture Detection (hand_gesture scripts & saved_model)
5. Data Store
– Firebase Firestore (NoSQL) for incident logs, user data, statistics
6. Frontend React App
– Components: LoginPage, Dashboard (EventCard, GestureCard, Statistics, etc.), WebSocket client, UserContext
– Firebase SDK for auth & data sync
7. Notification Service (could be integrated in Flask API or a separate microservice)
– Push alerts (email, SMS, on-screen)

b. Relationships & interactions:
- Video Source → (HTTP or gRPC) → Flask API → Inference Layer →
- Results → Firestore (persist)
- Results → WebSocket → React UI (Dashboard)
- React UI ↔ REST API for user operations (login, fetch historical stats)
- Flask API ↔ Firebase Admin SDK for data writes/reads & auth
- Models loaded at API startup, invoked per frame/request

c. Architectural patterns & design principles:
- Layered architecture: Presentation (React), API (Flask), Business/Inference (ML models), Data (Firestore)
- Single-page application (SPA) frontend
- Monolithic service for inference; consider splitting inference into microservices if scaling needed
- Real-time data propagation via WebSocket or SSE
- External service integration (Firebase, camera hardware)

d. Key technologies & libraries:
- Flask (flask_api/app.py)
- TensorFlow / YOLOv8 (models/fire_detection_script.py, hand_gesture_detection.py)
- OpenCV (video frame capture/processing)
- React & react-scripts (Frontend/src)
- Firebase Admin SDK (Backend/ibm-safety-net-firebase-adminsdk.json)
- WebSocket client in React (Frontend/src/components/WebSocket.js)

- Frontend (blue)
- Backend/API (green)
- ML modules (orange)
- External services (grey)

##### Detail
- CRUD endpoint or WebSocket channel name if known (e.g., /api/detect, /api/stats).
- Model loading at API startup (e.g., “load_model('models/hand_gest/...')”).
- If using Raspberry Pi code for sensor integration, note that as an edge service.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Video Source
    VideoSource["Video Source / Edge Agent"]:::external

    %% Client Zone
    subgraph "Client (Browser)"
        direction TB
        ReactApp["React App"]:::frontend
        FirebaseClient["Firebase Client Config"]:::frontend
        WebSocketClient["WebSocket Client"]:::frontend
        Login["Login Page"]:::frontend
        subgraph "Dashboard UI"
            direction TB
            AppRoutes["AppRoutes"]:::frontend
            Dashboard["Dashboard"]:::frontend
            EventCard["EventCard"]:::frontend
            GestureCard["GestureCard"]:::frontend
            SafetyCard["SafetyCard"]:::frontend
            SensorCard["SensorCard"]:::frontend
            subgraph "Statistics Charts"
                BarChart["BarChart"]:::frontend
                LineChart["LineChart"]:::frontend
                SingleBarChart["SingleBarChart"]:::frontend
            end
            SideBar["SideBar"]:::frontend
            Home["Home"]:::frontend
        end
    end

    %% Server Zone
    subgraph "Server (API)"
        direction TB
        LegacyAPI["Legacy Flask API"]:::backend
        FlaskAPI["Flask API Server"]:::backend
        FirebaseAdmin["Firebase Admin SDK Config"]:::external
        subgraph "ML Inference Layer"
            direction TB
            ModelLoader["Model Loader Utility"]:::ml
            SafetyGear["Safety Gear Detection"]:::ml
            FireDetection["Fire Detection Script"]:::ml
            subgraph "Hand Gesture Detection"
                direction TB
                HandGestureScript["Hand Gesture Detection"]:::ml
                SavedModel["Saved Model"]:::ml
                GestureMeta["Gesture Metadata"]:::ml
            end
        end
        Firestore["Firebase Firestore (NoSQL DB)"]:::external
    end

    %% Interactions
    VideoSource --> FlaskAPI
    VideoSource --> LegacyAPI
    LegacyAPI --> FlaskAPI
    FlaskAPI --> ModelLoader
    ModelLoader --> SafetyGear
    ModelLoader --> FireDetection
    ModelLoader --> HandGestureScript
    HandGestureScript --> SavedModel
    HandGestureScript --> GestureMeta
    FlaskAPI --> FirebaseAdmin
    FlaskAPI --> Firestore
    FlaskAPI --> WebSocketClient
    ReactApp -->|REST API| FlaskAPI
    ReactApp -->|WebSocket| WebSocketClient
    ReactApp --> FirebaseClient
    ReactApp --> Firestore

    %% Click Events
    click FlaskAPI "https://github.com/mounseflit/salamtyai/blob/main/flask_api/app.py"
    click LegacyAPI "https://github.com/mounseflit/salamtyai/blob/main/Backend/api/app.py"
    click FirebaseAdmin "https://github.com/mounseflit/salamtyai/blob/main/flask_api/ibm-safety-net-firebase-adminsdk.json"
    click ModelLoader "https://github.com/mounseflit/salamtyai/blob/main/models/load_models.py"
    click SafetyGear "https://github.com/mounseflit/salamtyai/blob/main/models/safety_gear_detection_script.py"
    click FireDetection "https://github.com/mounseflit/salamtyai/blob/main/models/fire_detection_script.py"
    click HandGestureScript "https://github.com/mounseflit/salamtyai/blob/main/models/hand_gest/hand_gesture_detection.py"
    click SavedModel "https://github.com/mounseflit/salamtyai/blob/main/models/hand_gest/mp_hand_gesture/saved_model.pb"
    click GestureMeta "https://github.com/mounseflit/salamtyai/blob/main/models/hand_gest/gesture.names"
    click GestureMeta "https://github.com/mounseflit/salamtyai/blob/main/models/hand_gest/data.pickle"
    click VideoSource "https://github.com/mounseflit/salamtyai/blob/main/Backend/app.py"
    click ReactApp "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/index.js"
    click FirebaseClient "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/Firebase.js"
    click WebSocketClient "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/WebSocket.js"
    click AppRoutes "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/Dashboard/AppRoutes.js"
    click Dashboard "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/Dashboard/Dashboard.js"
    click EventCard "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/Dashboard/EventCard.js"
    click GestureCard "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/Dashboard/GestureCard.js"
    click SafetyCard "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/Dashboard/SafetyCard.js"
    click SensorCard "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/Dashboard/SensorCard.js"
    click BarChart "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/Dashboard/Statistics/BarChart.js"
    click LineChart "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/Dashboard/Statistics/LineChart.js"
    click SingleBarChart "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/Dashboard/Statistics/SingleBarChart.js"
    click SideBar "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/Dashboard/SideBar.js"
    click Home "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/Dashboard/Home.js"
    click Login "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/components/LoginPage/Login.js"
    click ReactApp "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/App.js"
    click ReactApp "https://github.com/mounseflit/salamtyai/blob/main/Frontend/src/App.css"
    click ReactApp "https://github.com/mounseflit/salamtyai/blob/main/Frontend/public/index.html"
    click ReactApp "https://github.com/mounseflit/salamtyai/blob/main/Frontend/public/manifest.json"
    click ReactApp "https://github.com/mounseflit/salamtyai/blob/main/Frontend/public/robots.txt"
    click FrontendDeps "https://github.com/mounseflit/salamtyai/blob/main/Frontend/package.json"
    click FrontendDeps "https://github.com/mounseflit/salamtyai/blob/main/Frontend/package-lock.json"
    click PyReqs "https://github.com/mounseflit/salamtyai/blob/main/requirements.txt"
    click Docs "https://github.com/mounseflit/salamtyai/tree/main/Docs/"
    click Docs "https://github.com/mounseflit/salamtyai/tree/main/Docs/Others/"

    %% Styles
    classDef frontend fill:#B3DDF2,stroke:#1E90FF,color:#000;
    classDef backend fill:#C6E2B3,stroke:#228B22,color:#000;
    classDef ml fill:#FBE5B5,stroke:#FF8C00,color:#000;
    classDef external fill:#D3D3D3,stroke:#696969,color:#000;
    class FrontendDeps,PyReqs,Docs external
```
