# shashanknalkande1/fire-detection architecture

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

- Interactive diagram: https://gitdiagram.com/shashanknalkande1/fire-detection
- Repository: https://github.com/shashanknalkande1/fire-detection

## Overview

1. **System shape**
   This repo is a small, self-contained **Flask web application** for fire detection. The main runtime appears to live under `fire webapp/`, with a browser-based UI, server-side image handling, and YOLO-based inference.

2. **Primary entry point**
   `fire webapp/app.py` is the core application boundary. It likely hosts the Flask routes, accepts uploads, calls the detection pipeline, and returns rendered results to the browser.

3. **UI layer**
   `templates/index.html` is the only visible template, so the front end is probably a **single-page server-rendered form/result view** rather than a separate SPA. The browser submits an image and receives a results page back from Flask.

4. **Upload and output flow**
   The app uses the local filesystem as its working store:
   - `uploads/` holds incoming images
   - `detected_outputs/` holds images after inference and annotation  
   This means the request flow is likely: **browser upload → save to disk → run model → write annotated output → display/download result**.

5. **Detection pipeline**
   The repository is built around **YOLO via Ultralytics**, plus `torch`, `torchvision`, `opencv-python`, and `Pillow`. That implies the detection step is image-based object detection/annotation, with OpenCV/Pillow handling image I/O and Ultralytics/Torch handling model execution.

6. **Configuration boundary**
   `fire webapp/.env` suggests the app is configured through environment variables rather than hardcoded paths. Based on the README, these likely include the YOLO model path and folder locations for uploads and outputs. That makes model selection and storage paths runtime-configurable.

7. **Secondary execution path**
   `fire webapp/detect_fire_terminal.py` indicates a **non-web/CLI detection path** exists alongside the Flask app. Architecturally, this is likely a shared inference utility or alternate entry point for running detection from the terminal without the web UI.

8. **Observability**
   `fire webapp/debug.log` shows the app writes runtime logs to a local file. This is the main observability artifact in the repo; there is no evidence of external logging, monitoring, or telemetry services.

9. **Data assets**
   `fire_dataset.zip` appears to be an offline dataset artifact, probably used for training or testing the fire detector rather than live inference. It is not part of the request/response runtime path, but it matters for model development.

10. **Dependency stack**
    `requirements.txt` and the README point to a Python stack centered on Flask + Ultralytics + PyTorch. There is no sign of a database, queue, cache, or separate backend service, so the architecture is mostly **monolithic and local-process**.

11. **Key architectural boundary**
    The important boundary for a diagram is between:
    - **Browser/UI**: uploads image and shows results
    - **Flask app / inference layer**: receives request, stores files, runs YOLO, formats response
    - **Local filesystem**: persists uploads, outputs, and logs

12. **What is not present**
    There is no visible sign of:
    - a relational database
    - user authentication
    - async job processing
    - cloud storage
    - external APIs  
    So the system is best represented as a **single-server image inference web app** with filesystem-backed intermediate storage.

Main entry points: [`fire webapp/app.py`](https://github.com/shashanknalkande1/fire-detection/blob/HEAD/fire%20webapp/app.py) (Flask App), [`fire webapp/detected_outputs`](https://github.com/shashanknalkande1/fire-detection/tree/HEAD/fire%20webapp/detected_outputs) (Outputs), [`fire webapp/detect_fire_terminal.py`](https://github.com/shashanknalkande1/fire-detection/blob/HEAD/fire%20webapp/detect_fire_terminal.py) (Terminal Run), [`fire webapp/requirements.txt`](https://github.com/shashanknalkande1/fire-detection/blob/HEAD/fire%20webapp/requirements.txt) (Deps)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_app["Web App"]
  node_node_env["Env<br/>runtime config<br/>[.env]"]
  node_node_app["Flask App<br/>web server<br/>[app.py]"]
  node_node_template["Index View<br/>server template<br/>[index.html]"]
  node_node_cli["Terminal Run<br/>cli entrypoint"]
end

subgraph group_group_storage["Local Storage"]
  node_node_uploads[("Uploads<br/>input folder")]
  node_node_outputs[("Outputs<br/>output folder")]
  node_node_logs["Debug Log<br/>runtime log<br/>[debug.log]"]
end

subgraph group_group_assets["Data Assets"]
  node_node_readme["README<br/>docs<br/>[README.md]"]
  node_node_requirements["Deps<br/>python requirements<br/>[requirements.txt]"]
  node_node_dataset[("Dataset<br/>data archive<br/>[fire_dataset.zip]")]
end

node_node_browser(("Browser<br/>client"))
node_node_fs[("Filesystem<br/>local storage")]
node_node_yolo{{"YOLO Model<br/>ultralytics inference"}}
node_node_cv["Image I/O<br/>opencv pillow"]
node_node_torch{{"Torch Stack<br/>ml runtime"}}

node_node_browser -->|"open form"| node_node_template
node_node_browser -->|"submit image"| node_node_app
node_node_app -->|"read config"| node_node_env
node_node_app -->|"save upload"| node_node_uploads
node_node_app -->|"run detection"| node_node_yolo
node_node_yolo -->|"execute model"| node_node_torch
node_node_yolo -->|"annotate image"| node_node_cv
node_node_cv -->|"write result"| node_node_outputs
node_node_app -->|"render result"| node_node_outputs
node_node_app -->|"log events"| node_node_logs
node_node_cli -->|"run detection"| node_node_yolo
node_node_cli -->|"write result"| node_node_outputs
node_node_dataset -.->|"train/eval source"| node_node_yolo
node_node_requirements -.->|"install deps"| node_node_app
node_node_requirements -.->|"model stack"| node_node_yolo
node_node_fs -->|"hosts"| node_node_uploads
node_node_fs -->|"hosts"| node_node_outputs
node_node_fs -->|"hosts"| node_node_logs
node_node_fs -->|"stores"| node_node_dataset

click node_node_readme "https://github.com/shashanknalkande1/fire-detection/blob/main/README.md"
click node_node_requirements "https://github.com/shashanknalkande1/fire-detection/blob/main/fire webapp/requirements.txt"
click node_node_env "https://github.com/shashanknalkande1/fire-detection/blob/main/fire webapp/.env"
click node_node_app "https://github.com/shashanknalkande1/fire-detection/blob/main/fire webapp/app.py"
click node_node_template "https://github.com/shashanknalkande1/fire-detection/blob/main/fire webapp/templates/index.html"
click node_node_cli "https://github.com/shashanknalkande1/fire-detection/blob/main/fire webapp/detect_fire_terminal.py"
click node_node_uploads "https://github.com/shashanknalkande1/fire-detection/tree/main/fire webapp/uploads"
click node_node_outputs "https://github.com/shashanknalkande1/fire-detection/tree/main/fire webapp/detected_outputs"
click node_node_logs "https://github.com/shashanknalkande1/fire-detection/blob/main/fire webapp/debug.log"
click node_node_dataset "https://github.com/shashanknalkande1/fire-detection/blob/main/fire_dataset.zip"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_env,node_node_app,node_node_template,node_node_cli toneBlue
class node_node_uploads,node_node_outputs,node_node_logs toneAmber
class node_node_readme,node_node_requirements,node_node_dataset toneMint
class node_node_browser,node_node_fs,node_node_yolo,node_node_cv,node_node_torch toneNeutral
```

## Components

### Web App

Flask runtime, UI, and inference entry points.

- [Env](https://github.com/shashanknalkande1/fire-detection/blob/HEAD/fire%20webapp/.env): runtime config · Environment-based configuration for paths and model settings. · `fire webapp/.env`
- [Flask App](https://github.com/shashanknalkande1/fire-detection/blob/HEAD/fire%20webapp/app.py): web server · Main application boundary that handles requests and responses. · `fire webapp/app.py`
- [Index View](https://github.com/shashanknalkande1/fire-detection/blob/HEAD/fire%20webapp/templates/index.html): server template · Browser-facing upload and results page. · `fire webapp/templates/index.html`
- [Terminal Run](https://github.com/shashanknalkande1/fire-detection/blob/HEAD/fire%20webapp/detect_fire_terminal.py): cli entrypoint · Command-line detection path outside the web UI. · `fire webapp/detect_fire_terminal.py`

### Local Storage

Filesystem-backed inputs, outputs, and logs used at runtime.

- [Uploads](https://github.com/shashanknalkande1/fire-detection/tree/HEAD/fire%20webapp/uploads): input folder · Incoming images saved before inference. · `fire webapp/uploads`
- [Outputs](https://github.com/shashanknalkande1/fire-detection/tree/HEAD/fire%20webapp/detected_outputs): output folder · Annotated detection results written after inference. · `fire webapp/detected_outputs`
- [Debug Log](https://github.com/shashanknalkande1/fire-detection/blob/HEAD/fire%20webapp/debug.log): runtime log · Local application log for debugging and trace output. · `fire webapp/debug.log`

### Data Assets

Project data and package metadata.

- [README](https://github.com/shashanknalkande1/fire-detection/blob/main/README.md): docs · Project overview and usage notes. · `README.md`
- [Deps](https://github.com/shashanknalkande1/fire-detection/blob/HEAD/fire%20webapp/requirements.txt): python requirements · Python package dependencies for the app and model stack. · `fire webapp/requirements.txt`
- [Dataset](https://github.com/shashanknalkande1/fire-detection/blob/main/fire_dataset.zip): data archive · Offline dataset artifact for training or evaluation. · `fire_dataset.zip`

### Other components

- **Browser**: client · User submits an image and views detection results.
- **Filesystem**: local storage · Host filesystem used for uploads, outputs, logs, and assets.
- **YOLO Model**: ultralytics inference · Fire detection model executed through Ultralytics and PyTorch.
- **Image I/O**: opencv pillow · Image loading, saving, and annotation helpers.
- **Torch Stack**: ml runtime · PyTorch and related runtime used for model execution.

## Connections

- Browser → Index View: open form · User loads the upload/result page.
- Browser → Flask App: submit image · Browser sends an uploaded image to Flask.
- Flask App → Env: read config · Flask reads runtime paths and model settings.
- Flask App → Uploads: save upload · Incoming image is persisted to the uploads folder.
- Flask App → YOLO Model: run detection · Application invokes the fire detector on the image.
- YOLO Model → Torch Stack: execute model · YOLO inference runs on the Torch runtime.
- YOLO Model → Image I/O: annotate image · Detection results are drawn onto the image.
- Image I/O → Outputs: write result · Annotated output image is written to disk.
- Flask App → Outputs: render result · Flask returns or links the generated detection output.
- Flask App → Debug Log: log events · Application writes debug information locally.
- Terminal Run → YOLO Model: run detection · Terminal entry point reuses the detection pipeline.
- Terminal Run → Outputs: write result · CLI path can persist annotated output images.
- Dataset → YOLO Model: train/eval source · Dataset supports model development rather than live requests.
- Deps → Flask App: install deps · Declared packages support the web app runtime.
- Deps → YOLO Model: model stack · Dependencies include the Ultralytics and Torch inference stack.
- Filesystem → Uploads: hosts · Uploads directory lives on the local filesystem.
- Filesystem → Outputs: hosts · Detected outputs are stored on the local filesystem.
- Filesystem → Debug Log: hosts · Debug log is written to the local filesystem.
- Filesystem → Dataset: stores · Dataset archive is a repository-local file artifact.
