# bhavishyasingla1/drone_detection_webapp architecture

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

- Interactive diagram: https://gitdiagram.com/bhavishyasingla1/drone_detection_webapp
- Repository: https://github.com/bhavishyasingla1/drone_detection_webapp

## Overview

##### Main Components
a. Client (Web Browser)
b. Flask Web Server (app.py)
c. Model Inference Engine
- YOLOv8 model file (yolov8n_trained.pt)
- OpenCV + PyTorch libraries
d. Webcam Input (local hardware)
e. HTML/CSS/JS Frontend (templates/index.html)
f. External Dependencies (Flask, OpenCV)

##### Relationships and Data Flows
- The browser loads the HTML page (GET /) served by Flask.
- JavaScript in the page captures webcam frames and sends them (via WebSocket/AJAX/Fetch) to the Flask server for processing.
- Flask receives a frame, passes it to the Model Inference Engine.
- The Model Inference Engine (OpenCV + PyTorch) loads yolov8n_trained.pt, runs detection, returns annotated frames or detection metadata.
- The front-end renders the returned data in real time.

##### Architectural Patterns and Principles
- Separation of concerns:
- Presentation layer (templates + JS)
- Business logic + routing (Flask app.py)
- Inference layer (model + CV code)
- Stateless HTTP or WebSocket interactions for each frame
- Model as a backend service component (could be extracted into its own microservice if the app grows)

##### Relevant Technologies
- Flask for routing and templating
- OpenCV for image capture/preprocessing
- PyTorch (via ultralytics/yolov8) for model inference
- HTML/CSS/JavaScript for UI and real-time streaming
- requirements.txt lists all Python deps

##### Checklist
- Title (“Drone Detection Web App Architecture”) and date/version

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Web Browser"]:::frontend
    Index["templates/index.html"]:::frontend
    JS["JavaScript UI\n(capture & display)"]:::frontend
    Webcam["Webcam (Hardware)"]:::external
    Flask["Flask Server\napp.py"]:::backend
    Inference["Model Inference Engine\n(OpenCV + PyTorch)"]:::model
    ModelFile[("yolov8n_trained.pt")]:::modelfile
    Requirements["requirements.txt"]:::external

    Browser -->|"HTTP GET /"| Flask
    Flask -->|"Serves index.html"| Browser
    Browser -->|"getUserMedia"| Webcam
    Webcam -->|"video frames"| Browser
    Browser -->|"WebSocket/POST frame/jpeg"| Flask
    Flask -->|"in-process call"| Inference
    Inference -->|"loads model"| ModelFile
    ModelFile -->|"model data"| Inference
    Inference -->|"JSON/image response"| Flask
    Flask -->|"JSON/image response"| Browser

    click Index "https://github.com/bhavishyasingla1/drone_detection_webapp/blob/main/templates/index.html"
    click Browser "https://github.com/bhavishyasingla1/drone_detection_webapp/blob/main/templates/index.html"
    click Flask "https://github.com/bhavishyasingla1/drone_detection_webapp/blob/main/app.py"
    click Inference "https://github.com/bhavishyasingla1/drone_detection_webapp/blob/main/yolov8n_trained.pt"
    click ModelFile "https://github.com/bhavishyasingla1/drone_detection_webapp/blob/main/yolov8n_trained.pt"
    click Requirements "https://github.com/bhavishyasingla1/drone_detection_webapp/blob/main/requirements.txt"

    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef model fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef modelfile fill:#FFD700,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
