# kushdoshi07/accident-detection-and-alert-system architecture

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

- Interactive diagram: https://gitdiagram.com/kushdoshi07/accident-detection-and-alert-system
- Repository: https://github.com/kushdoshi07/accident-detection-and-alert-system

## Overview

##### Project Type and Purpose
- This is an IoT edge-to-cloud application running on an Arduino/ESP-class microcontroller.
- Purpose: Continuously monitor motion (MPU6050), gas concentration, and vibration; detect accident or hazardous conditions; log data in real time to ThingSpeak; and send SMS alerts via Twilio when thresholds are exceeded.

##### File Structure Analysis
- Only one source file: Final_Code.ino
- Contains all sensor-reading logic, accident-detection algorithms, cloud-communication routines, and alert-triggering code.
- No separate frontend/backend folders—everything lives in embedded firmware.

##### README Insights
- Lists four feature areas: Sensor Integration, Data Transmission, Accident Detection, Alert System.
- Specifies technologies: MPU6050, gas & vibration sensors, Wi-Fi + TLS 1.2, ThingSpeak, Twilio API.

##### Main Components
a. Edge Device (Arduino/ESP MCU)
– Sensor Interfaces: I²C for MPU6050 (accel + gyro), analog or digital input for gas sensor, digital input for vibration sensor.
– Local Processing: accident-detection logic (threshold checks, state machine).
– Networking: Wi-Fi radio + TLS 1.2 stack.
b. Cloud Services
– ThingSpeak API endpoint for data ingestion & real-time dashboards.
– Twilio REST API endpoint for SMS alerts.
c. End User
– Receives SMS notifications on mobile device.
– (Optional) Monitors dashboards on ThingSpeak web interface.

##### Relationships and Data Flow
- Sensors → MCU reads raw data.
- MCU → Local accident-detection module processes sensor values.
- MCU → Periodically pushes sensor readings (HTTP POST over TLS) to ThingSpeak.
- MCU → On detection of hazardous condition, invokes Twilio SMS API (HTTP POST over TLS) to send alerts.
- ThingSpeak → Web dashboards for remote monitoring.
- Twilio → SMS delivery to predefined phone numbers.

##### Architectural Patterns & Design Principles
- Edge Computing: preliminary processing and decision-making happens on the device to minimize latency.
- Event-Driven Alerts: accident triggers immediate API call for SMS.
- Publish–Subscribe (kind of): device publishes data to cloud channel (ThingSpeak).
- Secure Communication: all cloud interactions use TLS 1.2.

##### Technologies / Frameworks
- Arduino C++ (Final_Code.ino)
- Sensor libraries: MPU6050, gas sensor driver, vibration sensor read routines
- WiFi + TLS library (e.g., WiFiClientSecure)
- HTTP client for ThingSpeak and Twilio APIs

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Sensors Layer
    subgraph "Sensors" 
        direction TB
        MPU6050["MPU6050\n(Accel + Gyro)"]:::sensor
        GasSensor["Gas Sensor"]:::sensor
        VibrationSensor["Vibration Sensor"]:::sensor
    end

    %% Edge Device / MCU Layer
    subgraph "Microcontroller / IoT Edge" 
        direction TB
        MCU["Final_Code.ino\nFirmware Modules:\n- SensorManager\n- AccidentDetector\n- CloudClient\n- AlertManager"]:::edge
    end

    %% Cloud Services Layer
    subgraph "Cloud Services"
        direction TB
        ThingSpeak["ThingSpeak API\nHTTPS POST (TLS 1.2)\nPort 443"]:::cloud
        Twilio["Twilio SMS Service\nHTTPS POST (TLS 1.2)"]:::cloud
    end

    %% End User
    EndUser["End User (Mobile)\n- SMS Alerts\n- Dashboard View"]:::user

    %% Documentation
    Docs["Project Documentation\n(README.md)"]:::doc

    %% Connections
    MPU6050 -->|"I²C"| MCU
    GasSensor -->|"Analog / Digital Read"| MCU
    VibrationSensor -->|"Digital Read"| MCU
    MCU -->|"HTTPS POST (TLS 1.2)"| ThingSpeak
    MCU -->|"HTTPS POST (TLS 1.2)"| Twilio
    EndUser -->|"HTTP GET / Dashboard"| ThingSpeak
    Twilio -->|"SMS"| EndUser

    %% Click Events
    click MCU "https://github.com/kushdoshi07/accident-detection-and-alert-system/blob/main/Final_Code.ino"
    click Docs "https://github.com/kushdoshi07/accident-detection-and-alert-system/blob/main/README.md"

    %% Styles
    classDef sensor fill:#B3DFFF,stroke:#0366D6,color:#000
    classDef edge fill:#CAE7B9,stroke:#2E8B57,color:#000
    classDef cloud fill:#D1F2A5,stroke:#229954,color:#000
    classDef user fill:#FDEBD0,stroke:#E67E22,color:#000
    classDef doc fill:#E8E8E8,stroke:#777,color:#000
```
