# hinmq21/object-detection-app architecture

> Architecture diagram of the GitHub repository hinmq21/object-detection-app, 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/hinmq21/object-detection-app
- Repository: https://github.com/hinmq21/object-detection-app

## Overview

##### High-Level Architecture Components
a. Client (Web Browser)
- UI built with HTML/CSS/JS (template/index.html, static/js and static/css).
- Upload form and model-selector dropdown.
b. Flask Application Server
- Entry point: app.py
- Configuration: config.py
- Blueprints:
- main_routes.py serves HTML pages and status polling endpoints
- api_routes.py handles image upload and result retrieval
c. Task Processing
- tasks/task_manager.py uses ThreadPoolExecutor for asynchronous jobs
- detection tasks are queued, status tracked in memory or lightweight store
d. Model Management
- models/model_manager.py loads, caches, and provides YOLO models on demand
e. Image & Detection Utilities
- utils/image_utils.py pre-processes (resize, format conversion)
f. Storage
- static/uploads (or configured folder) holds original and processed images
g. External Dependencies
- Ultralytics YOLO (model files auto-downloaded)
- OpenCV, Pillow, NumPy

##### Important Architectural Patterns
- Blueprint separation (main vs. API routes)
- Asynchronous, non-blocking processing with ThreadPoolExecutor
- Lazy loading and caching of heavyweight models
- Modular utilities to isolate image I/O and detection logic

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser UI"
        UI_HTML["index.html"]:::client
        CSS["style.css"]:::client
        JS["main.js"]:::client
    end

    subgraph "Flask API"
        APP["app.py"]:::server
        CONFIG["config.py"]:::server
        subgraph "Routes"
            MR["main_routes.py"]:::server
            AR["api_routes.py"]:::server
        end
    end

    subgraph "Async Task Queue"
        TASK["Task Manager"]:::async
    end

    subgraph "Processing Service"
        MM["model_manager.py"]:::processing
        IU["image_utils.py"]:::processing
        DU["detection_utils.py"]:::processing
    end

    Storage["Uploads Folder"]:::storage

    UI_HTML -->|"upload & select model"| AR
    CSS --> AR
    JS --> AR
    AR -->|"enqueue job"| TASK
    TASK -->|"pre-process"| IU
    IU -->|"load & cache model"| MM
    MM -->|"run inference"| DU
    DU -->|"save results"| Storage
    Storage -->|"provide URLs & JSON"| AR
    AR -->|"return response"| UI_HTML

    click UI_HTML "https://github.com/hinmq21/object-detection-app/blob/main/template/index.html"
    click CSS "https://github.com/hinmq21/object-detection-app/blob/main/static/css/style.css"
    click JS "https://github.com/hinmq21/object-detection-app/blob/main/static/js/main.js"
    click APP "https://github.com/hinmq21/object-detection-app/blob/main/app.py"
    click CONFIG "https://github.com/hinmq21/object-detection-app/blob/main/config.py"
    click MR "https://github.com/hinmq21/object-detection-app/blob/main/routes/main_routes.py"
    click AR "https://github.com/hinmq21/object-detection-app/blob/main/routes/api_routes.py"
    click TASK "https://github.com/hinmq21/object-detection-app/blob/main/tasks/task_manager.py"
    click MM "https://github.com/hinmq21/object-detection-app/blob/main/models/model_manager.py"
    click IU "https://github.com/hinmq21/object-detection-app/blob/main/utils/image_utils.py"
    click DU "https://github.com/hinmq21/object-detection-app/blob/main/utils/detection_utils.py"

    classDef client fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef server fill:#d4edda,stroke:#333,stroke-width:1px
    classDef async fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef processing fill:#ffeeba,stroke:#333,stroke-width:1px
    classDef storage fill:#e2e3e5,stroke:#333,stroke-width:1px
```
