# arsentievalex/safewatch architecture

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

- Interactive diagram: https://gitdiagram.com/arsentievalex/safewatch
- Repository: https://github.com/arsentievalex/safewatch

## Overview

##### Main Components
- Frontend (User Interface):
- Represented by the Streamlit app (app.py) that drives the entire UI.
- It provides pages for user profile selection, trigger preference configuration, and displaying analyzed results.
- Backend & Processing Modules:
- Video Download: The yt_download.py handles fetching video content directly from YouTube URLs.
- Video Analysis: The video_analysis directory stores JSON files with analysis results, signifying processed data.
- Content Understanding: The content_understanding.py integrates with Azure’s AI Content Understanding service.
- AI Response Generation: The llm_inference.py module acts as the LLM-based module for personalized insights.
- Azure Storage: The azure_storage.py module interacts with Azure Blob Storage, managing file persistence.
- Utility Functions: The utils.py module contains common helper routines.
- External Services:
- Azure AI Foundry & Content Understanding: Identified by the integration in content_understanding.py.
- Azure Blob Storage: Supported by the azure_storage.py integration.

##### Relationships and Interactions
- The User Interface (app.py) collects user inputs (e.g., YouTube video URLs, trigger preferences) and forwards these inputs to backend modules.
- The yt_download.py module downloads video content based on user-provided YouTube URLs.
- After downloading, the content is analyzed either via:
- The content_understanding.py which calls Azure AI Content Understanding.
- The llm_inference.py that utilizes AI models to generate explanations and warnings.
- Processed video analysis results are stored in the video_analysis folder for persistence or further review.
- The azure_storage.py module ensures that data (like processed video analyses or configurations) is stored and retrieved from Azure Blob Storage.
- Utility functions (from utils.py) support common functions across modules.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each module maintains a specific responsibility (UI, downloading, analysis, storage, AI inference).
- Modular Design: The clear division into modules (e.g., content understanding, LLM inference) makes the system extensible and maintainable.
- External API Integration: The project design emphasizes integration with external Azure services, which should be depicted clearly.

##### Relevant Technologies
- Streamlit for the frontend.
- Python for backend operations.
- Azure AI and Azure Blob Storage for cloud services.
- Integration with YouTube for video processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        UI["Streamlit UI (app.py)"]:::frontend
    end

    subgraph "Backend Processing"
        YT["YouTube Downloader (yt_download.py)"]:::backend
        CA["Content Analysis (content_understanding.py)"]:::backend
        AI["AI Inference Engine (llm_inference.py)"]:::backend
        AZ["Azure Storage (azure_storage.py)"]:::backend
        UT["Utilities (utils.py)"]:::backend
        VA["Video Analysis Data (video_analysis/)"]:::backend
    end

    subgraph "External Services"
        EA["Azure AI Services"]:::external
        EB["Azure Blob Storage"]:::external
    end

    %% Connections
    UI -->|"DownloadRequest"| YT
    UI -->|"AnalysisRequest"| CA
    UI -->|"TriggerAnalysis"| AI

    YT -->|"PassVideoContent"| CA
    CA -->|"CallAzureAI"| EA
    EA -->|"AnalysisResponse"| CA

    CA -->|"StoreAnalysis"| AZ
    AI -->|"StoreInferenceData"| AZ
    AZ -->|"PersistedResults"| VA
    AZ -->|"SaveToBlob"| EB

    %% Utility functions support various modules (not direct flow but shared dependency)
    UT ---|"ProvidesHelpersTo"| CA
    UT ---|"ProvidesHelpersTo"| AI
    UT ---|"ProvidesHelpersTo"| AZ

    %% Click Events
    click UI "https://github.com/arsentievalex/safewatch/blob/main/app.py"
    click YT "https://github.com/arsentievalex/safewatch/blob/main/yt_download.py"
    click CA "https://github.com/arsentievalex/safewatch/blob/main/content_understanding.py"
    click AI "https://github.com/arsentievalex/safewatch/blob/main/llm_inference.py"
    click AZ "https://github.com/arsentievalex/safewatch/blob/main/azure_storage.py"
    click UT "https://github.com/arsentievalex/safewatch/blob/main/utils.py"
    click VA "https://github.com/arsentievalex/safewatch/tree/main/video_analysis/"

    %% Styles
    classDef frontend fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef backend fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef external fill:#fadbd8,stroke:#c0392b,stroke-width:2px;
```
