# anuza08/violencedetection architecture

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

- Interactive diagram: https://gitdiagram.com/anuza08/violencedetection
- Repository: https://github.com/anuza08/violencedetection

## Overview

##### Main Components

- Web Interface (Frontend):
- Represents the UI layer: the HTML templates (e.g., templates/index.html) and static assets (CSS, uploaded files, processed media).
- That static files are divided into directories for uploads (raw data) and processed (annotated output).

- Application Server (Backend):
- The main Flask app (app.py) provides endpoints such as the root page “/”, and routes like “/predict_image” and “/predict_video”, which handle media uploads and responses.
- The run.py file (if used as an alternative entry point) should be noted as part of the application startup workflow.

- Model Processing Component:
- The model.py file contains the Model class that initializes the CLIP model (using a deep learning framework such as PyTorch) and carries out image/video predictions.
- Its methods include image pre-processing and video processing (batching frames for efficiency).

- Configuration and Utilities:
- The settings.yaml file holds configuration parameters (e.g., model device settings, prediction thresholds, and label definitions).
- The utils.py file likely includes helper functions for common tasks (such as processing media files, reading configurations, etc.).

##### Relationships and Data Flow

- User Interaction:
- Users interact with the Web Interface to upload images/videos via the main page.

- Request Processing:
- Once a file is uploaded, the Flask application routes the request to the appropriate endpoint.
- The endpoint then invokes the Model Processing Component (via functions in model.py) to perform the violence detection using the CLIP model.

- Interaction with Configuration:

##### Architectural Patterns and Important Technologies

- Use an MVC-like (Model-View-Controller) structure:
- The “View” corresponds to templates and static assets.
- The “Controller” is implemented by the Flask routing in app.py.
- The “Model” layer handles the deep learning prediction logic in model.py.

- Technologies and Libraries:
- Flask (for web framework)
- PyTorch and CLIP (for the deep learning model)
- OpenCV (for processing video and image frames)
- NumPy and Pillow (for numerical operations and image manipulation)
- YAML configuration (via settings.yaml)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    Client("Client Browser"):::external

    %% Frontend Layer
    subgraph "Frontend Layer (Web UI)"
        Template("HTML Template"):::frontend
        CSS("CSS Styles"):::frontend
        Uploads("Uploads Directory"):::storage
        Processed("Processed Output"):::storage
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Flask("Flask Application (app.py)"):::backend
        Entry("Entry Point (run.py)"):::backend
        Config("Configuration (settings.yaml)"):::config
        Utils("Utilities (utils.py)"):::config
        Model("Deep Learning Model (model.py)"):::model
    end

    %% Data Flow
    Client -->|"HTTP_POST"| Flask
    Flask -->|"RenderHTML"| Template
    Flask -->|"FileUpload"| Model
    Model -->|"PredictionResults"| Flask
    Flask -->|"StoreProcessed"| Processed
    Config -.->|"Configures"| Flask
    Config -.->|"Configures"| Model
    Utils -.->|"Helps"| Flask
    Utils -.->|"Helps"| Model
    Flask -->|"RespondsWithMedia"| Client

    %% Styles
    classDef external fill:#f9c,stroke:#333,stroke-width:2px;
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef backend fill:#C2F0C2,stroke:#333,stroke-width:2px;
    classDef model fill:#F7D6AD,stroke:#333,stroke-width:2px;
    classDef config fill:#FFE5A0,stroke:#333,stroke-width:2px;
    classDef storage fill:#E6E6FA,stroke:#333,stroke-width:2px;

    %% Click Events
    click Template "https://github.com/anuza08/violencedetection/blob/main/templates/index.html"
    click CSS "https://github.com/anuza08/violencedetection/blob/main/static/css/style.css"
    click Uploads "https://github.com/anuza08/violencedetection/tree/main/static/uploads"
    click Processed "https://github.com/anuza08/violencedetection/tree/main/static/processed"
    click Flask "https://github.com/anuza08/violencedetection/blob/main/app.py"
    click Entry "https://github.com/anuza08/violencedetection/blob/main/run.py"
    click Model "https://github.com/anuza08/violencedetection/blob/main/model.py"
    click Config "https://github.com/anuza08/violencedetection/blob/main/settings.yaml"
    click Utils "https://github.com/anuza08/violencedetection/blob/main/utils.py"
```
