# hackabit19/devsena architecture

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

- Interactive diagram: https://gitdiagram.com/hackabit19/devsena
- Repository: https://github.com/hackabit19/devsena

## Overview

##### Project type and purpose
- ACCIDetect is a hybrid AI‐based accident detection system combining:
- A machine‐learning pipeline (data preprocessing, model training, real‐time inference)
- A real‐time detection service (Python scripts using OpenCV, TensorFlow, Twilio)
- A mobile client (Android app bundling a frozen TensorFlow graph for on‐device inference)
- The goal is to ingest CCTV video, detect accidents in real time, and notify emergency services.

##### File structure
- Top‐level files:
- ACCIDetect.ipynb / ACCIDetect.py – exploration & orchestration of experiments or inference
- ACCIdetect.pptx – presentation of the approach
- final.mp4 – demo video
- Readme.md – project description and workflow
- help.txt – miscellaneous notes
- ML directory:
- preprocessing.py – image‐to‐vector conversion and normalization
- trainV2.py – model training (ResNet‐based CNN)
- realtimeV2.py – server‐side real‐time inference on video streams
- hack directory: an Android client
- assets/frozen_inference_graph.pb + label_strings.txt – exported model and labels
- java/com/.../TensorFlowImageClassifier.java – Android wrapper for inference
- MainActivity.java – UI & camera feed capture
- AndroidManifest.xml, res/ – standard Android project layout

##### README for additional insights
- Workflow section describes:
a. Preprocessing of frames
b. Training a ResNet‐based model
c. Real‐time video inference and threshold‐based accident decision
d. Twilio SMS notifications to nearest services
- Technology stack: TensorFlow, Keras, OpenCV, scikit‐learn, Twilio

##### Main components
a. Data Capture Layer
- CCTV Cameras (live RTSP or HTTP video streams)
- Android Mobile Camera (optional client)
b. ML Training Pipeline (Offline)
- Raw Image Dataset (Kaggle) → preprocessing.py → Feature Vectors
- trainV2.py → ResNet CNN → Trained Model → Export to TensorFlow SavedModel / .pb
c. Inference Service (Online/Server)
- realtimeV2.py / ACCIDetect.py
- Video Frame Grabber (OpenCV)
- Model Loader (TensorFlow)
- Inference Engine → Probability Threshold
- Twilio API Client → SMS Notifications
d. Mobile Client (Android App)
- Local Camera Feed → TensorFlowImageClassifier
- On‐device inference (frozen_inference_graph.pb)
- Local Alert UI
e. External Services
- Twilio SMS Gateway
- Emergency Services Endpoints (Police, Ambulance, Fire Brigade)

##### Relationships and interactions
- CCTV Cameras → Inference Service (video frames over network)
- Inference Service loads model from Training Pipeline artifacts
- Inference Service → Twilio → Emergency Services (REST call)
- Mobile App uses same model artifacts for on‐device inference
- Optionally: Inference Service logs detections to a database or dashboard (if added later)

##### Architectural patterns & design principles
- Separation of Concerns:
- Offline Training vs. Online Inference vs. Mobile Client
- Modularization:
- ML preprocessing, training, real‐time inference each in separate scripts
- Portability:
- Exported .pb model for both server and mobile use
- Scalability (future):
- Inference Service could be containerized or broken into microservices per camera feed

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Capture Layer
    subgraph "Data Capture Layer"
        direction TB
        CCTV["CCTV Cameras"]:::external
        MobileCam["Android Mobile Camera"]:::external
    end

    %% Offline ML Pipeline
    subgraph "Offline ML Pipeline"
        direction TB
        RawData["Raw Image Dataset (Kaggle)"]:::ml
        Preprocess["preprocessing.py"]:::ml
        TrainModule["trainV2.py"]:::ml
        TrainedModel["Model Artifacts (.pb, SavedModel)"]:::ml
    end

    %% Orchestration & Documentation
    subgraph "Orchestration & Documentation"
        direction TB
        Notebook["ACCIDetect.ipynb"]:::ml
        ScriptOrch["ACCIDetect.py"]:::ml
        README["Readme.md"]:::docs
        PPT["ACCIdetect.pptx"]:::docs
        DemoVideo["final.mp4"]:::docs
    end

    %% Online Inference Service
    subgraph "Inference Service"
        direction TB
        InferenceScript["realtimeV2.py"]:::inference
        FrameGrabber["Video Frame Grabber (OpenCV)"]:::inference
        ModelLoader["Model Loader (TensorFlow)"]:::inference
        InferenceEngine["Inference Engine\n(if P(accident)>θ)"]:::inference
        TwilioClient["Twilio API Client"]:::inference
    end

    %% Mobile Client
    subgraph "Mobile Client"
        direction TB
        MainAct["hack/MainActivity.java"]:::mobile
        TFClassifier["TensorFlowImageClassifier.java"]:::mobile
        ClassifierUtil["Classifier.java"]:::mobile
        FrozenGraph["frozen_inference_graph.pb"]:::mobile
        Labels["label_strings.txt"]:::mobile
        Layout["activity_main.xml"]:::mobile
        Styles["colors.xml, strings.xml,\nstyles.xml"]:::mobile
        Drawables["ic_launcher*.xml,\nic_launcher_background.xml"]:::mobile
        LocalAlert["Local Alert UI"]:::mobile
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Twilio["Twilio SMS Gateway"]:::external
        Emergency["Emergency Services\n(Police, Ambulance, Fire)"]:::external
    end

    %% Connections
    CCTV -->|RTSP/HTTP frames| InferenceScript
    MobileCam -->|camera feed| MainAct
    RawData -->|images| Preprocess
    Preprocess -->|feature vectors| TrainModule
    TrainModule -->|export| TrainedModel
    TrainedModel -->|load artifacts| ModelLoader
    Notebook --> ScriptOrch
    ScriptOrch --> InferenceScript
    InferenceScript --> FrameGrabber
    FrameGrabber --> InferenceEngine
    ModelLoader --> InferenceEngine
    InferenceEngine -->|threshold logic| TwilioClient
    TwilioClient -->|REST API| Twilio
    Twilio --> Emergency
    FrozenGraph --> TFClassifier
    Labels --> TFClassifier
    MainAct --> TFClassifier
    TFClassifier --> LocalAlert

    %% Click Events
    click Preprocess "https://github.com/hackabit19/devsena/blob/master/ML/preprocessing.py"
    click TrainModule "https://github.com/hackabit19/devsena/blob/master/ML/trainV2.py"
    click InferenceScript "https://github.com/hackabit19/devsena/blob/master/ML/realtimeV2.py"
    click Notebook "https://github.com/hackabit19/devsena/blob/master/ACCIDetect.ipynb"
    click ScriptOrch "https://github.com/hackabit19/devsena/blob/master/ACCIDetect.py"
    click README "https://github.com/hackabit19/devsena/blob/master/Readme.md"
    click PPT "https://github.com/hackabit19/devsena/blob/master/ACCIdetect.pptx"
    click DemoVideo "https://github.com/hackabit19/devsena/blob/master/final.mp4"
    click MainAct "https://github.com/hackabit19/devsena/blob/master/hack/MainActivity.java"
    click TFClassifier "https://github.com/hackabit19/devsena/blob/master/hack/java/com/example/hackabit/TensorFlowImageClassifier.java"
    click ClassifierUtil "https://github.com/hackabit19/devsena/blob/master/hack/java/com/example/hackabit/Classifier.java"
    click FrozenGraph "https://github.com/hackabit19/devsena/blob/master/hack/assets/frozen_inference_graph.pb"
    click Labels "https://github.com/hackabit19/devsena/blob/master/hack/assets/label_strings.txt"
    click Layout "https://github.com/hackabit19/devsena/blob/master/hack/res/layout/activity_main.xml"
    click Styles "https://github.com/hackabit19/devsena/blob/master/hack/res/values/colors.xml"
    click Drawables "https://github.com/hackabit19/devsena/blob/master/hack/res/mipmap-anydpi-v26/ic_launcher.xml"

    %% Styles
    classDef ml fill:#BBE0FF,stroke:#3182CE
    classDef inference fill:#C6F6D5,stroke:#2F855A
    classDef mobile fill:#FED7C3,stroke:#DD6B20
    classDef external fill:#E2E8F0,stroke:#4A5568
    classDef docs fill:#E9D8FD,stroke:#9F7AEA
```
