# xenoswarlocks/video-processing-tool architecture

> Architecture diagram of the GitHub repository xenoswarlocks/video-processing-tool, 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/xenoswarlocks/video-processing-tool
- Repository: https://github.com/xenoswarlocks/video-processing-tool

## Overview

##### Project Overview and Type
- This project is a full-stack Python application geared toward processing videos using AI. It handles chunked video uploads, frame extraction, AI-powered analysis (using the Gemini model and text enrichment), and an interactive chat user interface built with Streamlit. There’s also a payment integration module for donations.
- The README clearly lays out the different stages—from video upload through processing and AI analysis to the final UI interaction—plus support configurations and deployment tools (like Docker and docker-compose).

##### Main Components
- Frontend/UI Layer:
- Streamlit-based UI (src/ui/streamlit.py and src/ui/chat_ui.py)
- Custom UI elements under src/ui/ai_integration (such as inputs, cards, buttons, theme)
- API Layer:
- Video chunk management and assembly (src/api/vid_api.py, src/api/chunk_api.py, and src/api/vid_upload.py)
- Chat API for AI interaction (src/api/chat_api.py)
- Core Processing Layer:
- Video Processing: Components in src/video_processing (video_handler.py, frame_extractor.py, video_compressor.py)
- AI Integration: Components in src/ai_integration (gemini_processor.py, text_enrichment.py)
- Base functionalities like config management, token counting in src/core (base_processor.py, config_manager.py, token_counter.py)
- Payment Integration:
- Payment processing logic (src/payment/payment_processor.py)
- Supporting Components:
- Configuration files (configs/app_config.yaml and configs/ai_config.yaml)
- Logging (logs directory)
- Testing modules (tests directory)
- Deployment and Environment:
- Dockerfile, docker-compose.yml, .env example, and setup scripts for environment management

##### Relationships and Interaction Flow
- Users start at the UI layer (Streamlit application) to upload video content.
- The uploaded video is split into chunks by the ChunkedUploadManager (in src/api/chunk_api.py and vid_upload.py).
- The API layer then reassembles these chunks into a full video (in src/api/vid_api.py).
- Once assembled, the video is processed by the VideoProcessor module (src/video_processing/video_handler.py), which handles frame extraction and video compression.
- Each extracted frame is passed to the AI Integration layer where GeminiProcessor (src/ai_integration/gemini_processor.py) returns summaries, key concepts, and sentiment analysis.
- The processed video and AI analysis results are stored (as indicated, for example, in the uploads/processed area per the README).
- Results are communicated back to the user via the Streamlit UI. Additionally, a Chat UI component (src/ui/chat_ui.py along with chat_api.py interactions) enables users to query the analysis.
- Finally, the Payment module (src/payment/payment_processor.py) provides a mechanism for donations through integrated platforms.

##### Architectural Patterns & Design Principles
- Modularity: The project is organized into well-defined modules (core, api, video_processing, ai_integration, ui) that promote scalability and maintainability.
- Separation of Concerns: There’s a clear division between video processing, AI analysis, user interface, and payment processing.
- API-Driven Interaction: The separation between API endpoints and UI allows for clear data flow and improved testing (as evidenced by the “tests” directory).
- Use of Configuration Management: Centralized config_manager and YAML configurations provide consistency across components.
- Containerization: Presence of Dockerfile and docker-compose.yml indicates containerized deployment for easier environment replication and scaling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External entities
    User["User"]:::external

    %% UI Layer
    subgraph "UI Layer"
        streamlit["Streamlit UI (streamlit.py)"]:::frontend
        chat["Chat UI (chat_ui.py)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        vidAPI["Video API (vid_api.py)"]:::api
        chunkAPI["Chunk API (chunk_api.py)"]:::api
        vidUpload["Video Upload API (vid_upload.py)"]:::api
        chatAPI["Chat API (chat_api.py)"]:::api
    end

    %% Video Processing Module
    subgraph "Video Processing"
        videoHandler["Video Handler (video_handler.py)"]:::processing
        frameExtr["Frame Extractor (frame_extractor.py)"]:::processing
        videoCompress["Video Compressor (video_compressor.py)"]:::processing
    end

    %% AI Integration Module
    subgraph "AI Integration"
        geminiProc["Gemini Processor (gemini_processor.py)"]:::ai
        textEnrich["Text Enrichment (text_enrichment.py)"]:::ai
    end

    %% Core Processing & Configuration
    subgraph "Core & Config"
        baseProc["Base Processor (base_processor.py)"]:::core
        configMan["Config Manager (config_manager.py)"]:::core
        tokenCounter["Token Counter (token_counter.py)"]:::core
        configApp["App Config (app_config.yaml)"]:::config
        configAI["AI Config (ai_config.yaml)"]:::config
    end

    %% Payment Integration Module
    subgraph "Payment Integration"
        payment["Payment Processor (payment_processor.py)"]:::payment
    end

    %% Deployment & Environment Setup
    subgraph "Deployment & Environment"
        dockerfile["Dockerfile"]:::deploy
        dockerCompose["docker-compose.yml"]:::deploy
        envFile[".env.example"]:::deploy
        setup["Setup Script (setup.py)"]:::deploy
    end

    %% Logging
    subgraph "Logs"
        logs["Logs Directory"]:::logging
    end

    %% Storage for Processed Outputs
    subgraph "Storage"
        storage["Processed Video & AI Results Storage"]:::storage
    end

    %% Data Flow
    User -->|"upload_video"| streamlit

    %% UI to API interactions
    streamlit -->|"submit_video"| vidUpload
    streamlit -->|"chat_query"| chatAPI

    %% API internal flow
    vidUpload -->|"handle_chunks"| chunkAPI
    vidUpload -->|"assemble_video"| vidAPI
    vidAPI -->|"initiate_processing"| videoHandler

    %% Video Processing flow
    videoHandler -->|"extract_frames"| frameExtr
    videoHandler -->|"compress_video"| videoCompress
    videoHandler -->|"load_config"| configMan

    %% AI Integration flow
    frameExtr -->|"analyze_frame"| geminiProc
    geminiProc -->|"enrich_analysis"| textEnrich
    geminiProc -->|"store_analysis"| storage
    textEnrich -->|"store_text"| storage

    %% Chat flow
    geminiProc -->|"return_response"| chatAPI
    chatAPI -->|"display_chat"| chat

    %% Payment flow
    User -->|"donate"| payment
    payment -->|"payment_status"| streamlit

    %% Core interactions
    baseProc -->|"token_count"| tokenCounter
    configMan -->|"provide_config"| baseProc

    %% Logging
    videoHandler -->|"log_activity"| logs
    geminiProc -->|"log_AI_activity"| logs

    %% Click Events
    click streamlit "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/ui/streamlit.py"
    click chat "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/ui/chat_ui.py"
    click vidAPI "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/api/vid_api.py"
    click chunkAPI "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/api/chunk_api.py"
    click vidUpload "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/api/vid_upload.py"
    click chatAPI "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/api/chat_api.py"
    click videoHandler "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/video_processing/video_handler.py"
    click frameExtr "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/video_processing/frame_extractor.py"
    click videoCompress "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/video_processing/video_compressor.py"
    click geminiProc "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/ai_integration/gemini_processor.py"
    click textEnrich "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/ai_integration/text_enrichment.py"
    click baseProc "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/core/base_processor.py"
    click configMan "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/core/config_manager.py"
    click tokenCounter "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/core/token_counter.py"
    click payment "https://github.com/xenoswarlocks/video-processing-tool/blob/main/src/payment/payment_processor.py"
    click configApp "https://github.com/xenoswarlocks/video-processing-tool/blob/main/configs/app_config.yaml"
    click configAI "https://github.com/xenoswarlocks/video-processing-tool/blob/main/configs/ai_config.yaml"
    click dockerfile "https://github.com/xenoswarlocks/video-processing-tool/tree/main/Dockerfile"
    click dockerCompose "https://github.com/xenoswarlocks/video-processing-tool/blob/main/docker-compose.yml"
    click envFile "https://github.com/xenoswarlocks/video-processing-tool/blob/main/.env.example"
    click setup "https://github.com/xenoswarlocks/video-processing-tool/blob/main/setup.py"
    click logs "https://github.com/xenoswarlocks/video-processing-tool/tree/main/logs/"

    %% Styles
    classDef frontend fill:#a3d5ff,stroke:#333,stroke-width:2px;
    classDef api fill:#ffd588,stroke:#333,stroke-width:2px;
    classDef processing fill:#ffb3b3,stroke:#333,stroke-width:2px;
    classDef ai fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef core fill:#d3f8d3,stroke:#333,stroke-width:2px;
    classDef payment fill:#ffff99,stroke:#333,stroke-width:2px;
    classDef config fill:#e6e6e6,stroke:#333,stroke-width:2px;
    classDef deploy fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef logging fill:#f0e68c,stroke:#333,stroke-width:2px;
    classDef storage fill:#d9d2e9,stroke:#333,stroke-width:2px;
    classDef external fill:#fff2b2,stroke:#333,stroke-width:2px;
```
