# avfl4028/sparkle_bot architecture

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

- Interactive diagram: https://gitdiagram.com/avfl4028/sparkle_bot
- Repository: https://github.com/avfl4028/sparkle_bot

## Overview

##### Project type and purpose
- From the README (“Sparkle Bot”) and file structure, this project is a full-stack automation bot for generating social media videos (YouTube, TikTok) based on “Reddit-style” story content.
- Key purpose: fetch or generate story prompts, synthesize audio narration, download or generate video footage, compose/edit the final video, and upload or prepare it for YouTube/TikTok.

##### File structure
- Top‐level:
- src/ – main application code
- src/api/ – wrappers for external services (audio, Gemini model, YouTube, TikTok) and prompt/history management
- src/video_edition/ – video generation and editing scripts
- src/media/ – static assets: fonts, intermediate audio files, subtitles
- src/config/ – JSON configuration
- src/keys.py – credential loader
- src/main.py – orchestrator/entry point
- src/tests/ – unit tests for each major module
- Config & build:
- requirements.txt – Python dependencies
- .gitignore, .vscode/ – IDE and ignore settings

##### README for additional insights
- Features listed in TODO: code documentation, video editing, font customization, translation
- Mentions “keys.json” that will hold API credentials

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Configuration & Credentials
    subgraph "Configuration & Credentials"
        ConfigLoader["Config Loader\n(config.json)"]:::storage
        CredsLoader["Credentials Loader\n(keys.py)"]:::storage
    end

    %% Orchestrator
    Orchestrator["Orchestrator\n(main.py)"]:::orchestrator

    %% API Services
    subgraph "API Services"
        PromptLogic["Prompt Generator\n(promps.py)"]:::api
        PromptsData[/"Prompts Data\n(promps.json)"/]:::storage
        HistoryManager[/"History Manager\n(history_test.json)"/]:::storage
        GeminiClient["LLM Client\n(gemini.py)"]:::api
        ExternalLLM(["External LLM Service"]):::external
        TTSModule["TTS Module\n(audio.py)"]:::api
        ExternalTTS(["External TTS Service"]):::external
        YouTubeClient["YouTube Client\n(youtube.py)"]:::api
        ExternalYouTube(["YouTube Data API"]):::external
        TikTokClient["TikTok Client\n(tiktok.py)"]:::api
        ExternalTikTok(["TikTok API"]):::external
    end

    %% Media Storage
    subgraph "Media Storage"
        AudioTempStorage(("Audio Temp Storage")):::storage
        SubtitlesStorage(("Subtitles Storage")):::storage
        FontAssets(("Font Assets")):::storage
    end

    %% Video Processing Pipeline
    subgraph "Video Processing"
        BgGenerator["Background Generator\n(BgGenerator.py)"]:::processing
        YtDownloader["YouTube Downloader\n(YtVideosDownload.py)"]:::processing
        VideoAssembly["Video Assembly & Overlay\n(video.py)"]:::processing
        FinalVideo["Final Video"]:::artifact
    end

    %% Tests
    subgraph "Unit Tests"
        AudioTests["Audio Tests\n(audio_test.py)"]:::test
        GeminiTests["Gemini Tests\n(gemini_test.py)"]:::test
        VideoTests["Video Tests\n(video_test.py)"]:::test
    end

    %% Connections
    ConfigLoader --> Orchestrator
    CredsLoader --> Orchestrator

    Orchestrator --> PromptLogic
    Orchestrator --> HistoryManager
    PromptLogic --> PromptsData
    PromptLogic --> GeminiClient
    GeminiClient --> ExternalLLM
    ExternalLLM --> GeminiClient
    GeminiClient --> Orchestrator

    Orchestrator --> TTSModule
    TTSModule --> ExternalTTS
    ExternalTTS --> TTSModule
    TTSModule --> AudioTempStorage
    TTSModule --> SubtitlesStorage

    Orchestrator --> BgGenerator
    Orchestrator --> YtDownloader
    BgGenerator --> VideoAssembly
    YtDownloader --> VideoAssembly
    VideoAssembly --> FinalVideo

    FinalVideo --> YouTubeClient
    YouTubeClient --> ExternalYouTube
    FinalVideo --> TikTokClient
    TikTokClient --> ExternalTikTok

    %% Test covers
    AudioTests --> TTSModule
    GeminiTests --> GeminiClient
    VideoTests --> VideoAssembly

    %% Click Events
    click Orchestrator "https://github.com/avfl4028/sparkle_bot/blob/master/src/main.py"
    click PromptLogic "https://github.com/avfl4028/sparkle_bot/blob/master/src/api/promps.py"
    click PromptsData "https://github.com/avfl4028/sparkle_bot/blob/master/src/api/promps.json"
    click HistoryManager "https://github.com/avfl4028/sparkle_bot/blob/master/src/api/history_test.json"
    click GeminiClient "https://github.com/avfl4028/sparkle_bot/blob/master/src/api/gemini.py"
    click TTSModule "https://github.com/avfl4028/sparkle_bot/blob/master/src/api/audio.py"
    click YouTubeClient "https://github.com/avfl4028/sparkle_bot/blob/master/src/api/youtube.py"
    click TikTokClient "https://github.com/avfl4028/sparkle_bot/blob/master/src/api/tiktok.py"
    click ConfigLoader "https://github.com/avfl4028/sparkle_bot/blob/master/src/config/config.json"
    click CredsLoader "https://github.com/avfl4028/sparkle_bot/blob/master/src/keys.py"
    click AudioTempStorage "https://github.com/avfl4028/sparkle_bot/tree/master/src/media/audio/temp"
    click SubtitlesStorage "https://github.com/avfl4028/sparkle_bot/tree/master/src/media/audio/subtitles"
    click FontAssets "https://github.com/avfl4028/sparkle_bot/tree/master/src/media/fonts"
    click BgGenerator "https://github.com/avfl4028/sparkle_bot/blob/master/src/video_edition/BgGenerator.py"
    click YtDownloader "https://github.com/avfl4028/sparkle_bot/blob/master/src/video_edition/YtVideosDownload.py"
    click VideoAssembly "https://github.com/avfl4028/sparkle_bot/blob/master/src/video_edition/video.py"
    click AudioTests "https://github.com/avfl4028/sparkle_bot/blob/master/src/tests/audio_test.py"
    click GeminiTests "https://github.com/avfl4028/sparkle_bot/blob/master/src/tests/gemini_test.py"
    click VideoTests "https://github.com/avfl4028/sparkle_bot/blob/master/src/tests/video_test.py"

    %% Styles
    classDef orchestrator fill:#f9f,stroke:#333,stroke-width:2px
    classDef api fill:#bbf,stroke:#333,stroke-width:1px
    classDef storage fill:#bfb,stroke:#333,stroke-width:1px
    classDef processing fill:#ffb,stroke:#333,stroke-width:1px
    classDef external fill:#eee,stroke:#666,stroke-width:1px,stroke-dasharray: 5 5
    classDef artifact fill:#fbf,stroke:#333,stroke-width:1px
    classDef test fill:#fbb,stroke:#333,stroke-width:1px
```
