# sebdelsol/sfvip-all architecture

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

- Interactive diagram: https://gitdiagram.com/sebdelsol/sfvip-all
- Repository: https://github.com/sebdelsol/sfvip-all

## Overview

##### Project type and purpose
- This is a Python-based Windows desktop application (“Sfvip All”) that wraps and extends an existing third-party app (Sfvip Player).
- It consists of two cooperating runtime processes: a GUI/main process and an embedded HTTP proxy (mitmproxy) that intercepts and patches Sfvip Player network calls.
- It also includes a companion CLI tool (user_proxy_cmd) for managing system-wide proxy settings in the Sfvip Player database.

##### File structure
- Top-level folders:
- dev/      → build, test, publish, translate scripts (PyInstaller, Nuitka, NSIS workflows)
- src/      → runtime code under three domains: mitm (proxy logic), sfvip (business/UI logic), winapi (Windows API helpers)
- shared/   → cross-domain utilities (versioning, job runner, caching, updates)
- resources/→ static templates, readme assets
- translations/ → localization JSON + Python bindings
- user_proxy_cmd/ → separate small CLI wrapper for global proxy management
- Configuration build scripts: build_config.py, requirements.txt, requirements.dev.txt
- Deployment artifacts: build/* (changelog, update manifests)

##### README for additional insights
- Describes features: “All” category injection, MPV and Sfvip auto-update, EPG support, caching.
- Runtime: two processes write logs side-by-side (main & mitmproxy).
- Build toolchain: Rust + Python envs, dev.create, dev.build, dev.publish, dev.upgrade, dev.scan, dev.translate.
- Packaging: PyInstaller or Nuitka → NSIS installer

##### Main components
a. Frontend/UI layer
- src/sfvip/ui/… : window management, widgets, splash, progress bar
- MPV integration via libmpv_dll
b. Business logic layer
- src/sfvip/*.py: account management, updates, caching, exceptions, scheduler
- shared/: config loader, update logic, job runner, md5, version
c. MitM proxy layer
- src/mitm/: custom addon for mitmproxy, cache cleaner, EPG server handler, proxy rules
d. External applications & services
- Third-party Sfvip Player executable
- MPV player binary
- External EPG data source (HTTP feed)
- GitHub API & DeepL API (build-time used by dev.publish, dev.translate)
e. Local storage
- Cache files, logs, config files under %LocalAppData% and application folder
f. Build and packaging pipeline (optional overlay)
- dev/ scripts → virtual envs → PyInstaller/Nuitka → NSIS → installer

##### Relationships and interactions
- Main App UI launches and manages both: the GUI event loop & embedded mitmproxy subprocess.
- Sfvip Player configured to use 127.0.0.1:port → all HTTP calls routed through mitmproxy.
- Mitmproxy intercepts JSON responses, applies “All” category injection, EPG merging.
- Main App caches categories & EPG data on disk for faster access.
- When user clicks Play, main app spawns MPV via libmpv_dll.
- Update logic: main app or dev.publish interacts with GitHub/DeepL to fetch new versions/localizations.
- user_proxy_cmd tool modifies Windows registry or Sfvip Player DB to set/remove proxy for all users.

##### Architectural patterns and design principles
- Layered architecture: UI → business logic → proxy → external services
- Process isolation: separate GUI and network-patching proxies
- Plugin/Add-On model: mitmproxy addons for extensibility
- Shared utilities to avoid duplication (shared/)
- Build pipeline as code (dev/ directory)

##### Diagramming recommendations
- Use clear labels for each component (e.g., “Main App Process”, “MitM Proxy”, “Sfvip Player”)
- App → Proxy → Internet
- Proxy → App (patched responses)
- App → MPV (playback)
- App ↔ Local FS (cache/log)
- Blue for internal components (src/, shared/)
- Green for external binaries/services (Sfvip Player, MPV, EPG feed)
- Orange for build pipeline (dev/)
- Ports (e.g., localhost:8080) and protocols (HTTP/HTTPS) if helpful

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main App Process
    subgraph "Main App Process" 
        direction TB
        subgraph "UI Layer"
            direction TB
            Window["Window Management"]:::internal
            Widgets["Widgets"]:::internal
            Splash["Splash Screen"]:::internal
            Progress["Progress Bar"]:::internal
            Style["Style Definitions"]:::internal
        end
        subgraph "MPV Integration"
            direction TB
            libmpv_dll["libmpv_dll"]:::internal
            libmpv_updater["libmpv_updater"]:::internal
            find_exe["find_exe"]:::internal
        end
        subgraph "Business Logic"
            direction TB
            Accounts["accounts.py"]:::internal
            AppUpdater["app_updater.py"]:::internal
            CacheLogic["cache.py"]:::internal
            EPGLogic["epg.py"]:::internal
            Exceptions["exceptions.py"]:::internal
            PlayerUpdater["player/updater.py"]:::internal
            Scheduler["utils/scheduler.py"]:::internal
            SharedMain["shared.py"]:::internal
        end
    end

    %% MitM Proxy Process
    subgraph "MitM Proxy Process"
        direction TB
        AddonAll["all.py"]:::internal
        CacheCleaner["cache_cleaner.py"]:::internal
        EPGServer["epg/server.py"]:::internal
        EPGUpdate["epg/update.py"]:::internal
        Proxies["proxies.py"]:::internal
        MitmUtils["utils.py"]:::internal
    end

    %% CLI Proxy Tool
    subgraph "CLI Proxy Management Tool" 
        direction TB
        CmdMain["cmd.py"]:::pipeline
        CmdConfig["cmd_build_config.py"]:::pipeline
        DevBuildCLI["dev/build.py"]:::pipeline
        DevPublishCLI["dev/publish.py"]:::pipeline
    end

    %% Shared Utilities
    SharedVersion["shared/version.py"]:::internal
    SharedUpdate["shared/update.py"]:::internal
    JobRunner["shared/job_runner.py"]:::internal
    MD5["shared/md5.py"]:::internal

    %% Windows API Helpers
    Registry["registry.py"]:::internal
    ProcessAPI["process.py"]:::internal
    MutexAPI["mutex.py"]:::internal

    %% Configuration Loader
    ConfigLoader["config_loader"]:::internal

    %% Storage
    LocalFS(("Local FS<br/>(Cache, Logs, Config)")):::storage

    %% External Services
    subgraph "External Services"
        direction TB
        SfvipPlayer["Sfvip Player Executable"]:::external
        MPVBinary["MPV Player Binary"]:::external
        EPGFeed["EPG HTTP Feed"]:::external
        GitHubAPI["GitHub API"]:::external
        DeepLAPI["DeepL API"]:::external
    end

    %% Build & Packaging Pipeline
    subgraph "Build & Packaging Pipeline"
        direction TB
        DevCreate["dev/create.py"]:::pipeline
        DevBuild["dev/build.py"]:::pipeline
        DevPublish["dev/publish.py"]:::pipeline
        DevTranslate["dev/translate.py"]:::pipeline
        DevUpgrade["dev/upgrade.py"]:::pipeline
        PyInstaller["tools/builder/pyinstaller.py"]:::pipeline
        Nuitka["tools/builder/nuitka.py"]:::pipeline
        NSISInstaller["tools/nsis/installer.py"]:::pipeline
    end

    %% Relationships
    Window -->|uses| Widgets
    Splash -->|initializes| Progress
    libmpv_dll -->|invoked by| libmpv_updater
    find_exe -->|locates| MPVBinary
    Accounts -->|manages| CacheLogic
    AppUpdater -->|updates via| GitHubAPI
    EPGLogic -->|fetches| EPGFeed
    CacheLogic -->|stores to| LocalFS
    SharedMain -->|utilizes| SharedVersion
    SharedMain -->|utilizes| SharedUpdate
    SharedMain -->|utilizes| JobRunner
    SharedMain -->|utilizes| MD5
    Scheduler -->|schedules jobs| JobRunner
    MainAppProcessSubgraph -->|spawns| MitMProxyProcessSubgraph

    subgraph invisible
        MainAppProcessSubgraph([ ])
        MitMProxyProcessSubgraph([ ])
    end

    SfvipPlayer -->|HTTP via 127.0.0.1:8080| Proxies
    Proxies -->|intercepts| EPGServer
    Proxies -->|passes patched| MainAppProcessSubgraph
    MainAppProcessSubgraph -->|spawns| MPVBinary
    MainAppProcessSubgraph -->|reads/writes| LocalFS
    CmdMain -->|modifies proxy| Registry
    CmdMain -->|modifies proxy| SharedMain
    DevCreate -->|triggers| DevBuild
    DevBuild -->|builds| PyInstaller
    DevBuild -->|builds| Nuitka
    DevPublish -->|publishes via| GitHubAPI
    DevTranslate -->|translates via| DeepLAPI
    DevUpgrade -->|upgrades manifests| LocalFS
    NSISInstaller -->|packages| LocalFS

    %% Click Events
    click Window "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/ui/window.py"
    click Widgets "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/ui/widgets.py"
    click Splash "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/ui/splash.py"
    click Progress "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/ui/progress.py"
    click Style "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/ui/style.py"
    click libmpv_dll "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/player/libmpv_dll.py"
    click libmpv_updater "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/player/libmpv_updater.py"
    click find_exe "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/player/find_exe.py"
    click Accounts "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/accounts.py"
    click AppUpdater "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/app_updater.py"
    click CacheLogic "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/cache.py"
    click EPGLogic "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/epg.py"
    click Exceptions "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/exceptions.py"
    click PlayerUpdater "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/player/updater.py"
    click Scheduler "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/utils/scheduler.py"
    click SharedMain "https://github.com/sebdelsol/sfvip-all/blob/master/src/sfvip/shared.py"
    click AddonAll "https://github.com/sebdelsol/sfvip-all/blob/master/src/mitm/addon/all.py"
    click CacheCleaner "https://github.com/sebdelsol/sfvip-all/blob/master/src/mitm/cache_cleaner.py"
    click EPGServer "https://github.com/sebdelsol/sfvip-all/blob/master/src/mitm/epg/server.py"
    click EPGUpdate "https://github.com/sebdelsol/sfvip-all/blob/master/src/mitm/epg/update.py"
    click Proxies "https://github.com/sebdelsol/sfvip-all/blob/master/src/mitm/proxies.py"
    click MitmUtils "https://github.com/sebdelsol/sfvip-all/blob/master/src/mitm/utils.py"
    click Registry "https://github.com/sebdelsol/sfvip-all/blob/master/src/winapi/registry.py"
    click ProcessAPI "https://github.com/sebdelsol/sfvip-all/blob/master/src/winapi/process.py"
    click MutexAPI "https://github.com/sebdelsol/sfvip-all/blob/master/src/winapi/mutex.py"
    click ConfigLoader "https://github.com/sebdelsol/sfvip-all/blob/master/src/config_loader/__init__.py"
    click SharedVersion "https://github.com/sebdelsol/sfvip-all/blob/master/shared/version.py"
    click SharedUpdate "https://github.com/sebdelsol/sfvip-all/blob/master/shared/update.py"
    click JobRunner "https://github.com/sebdelsol/sfvip-all/blob/master/shared/job_runner.py"
    click MD5 "https://github.com/sebdelsol/sfvip-all/blob/master/shared/md5.py"
    click CmdMain "https://github.com/sebdelsol/sfvip-all/blob/master/user_proxy_cmd/cmd.py"
    click CmdConfig "https://github.com/sebdelsol/sfvip-all/blob/master/user_proxy_cmd/cmd_build_config.py"
    click DevBuildCLI "https://github.com/sebdelsol/sfvip-all/blob/master/user_proxy_cmd/dev/build.py"
    click DevPublishCLI "https://github.com/sebdelsol/sfvip-all/blob/master/user_proxy_cmd/dev/publish.py"
    click DevCreate "https://github.com/sebdelsol/sfvip-all/blob/master/dev/create.py"
    click DevBuild "https://github.com/sebdelsol/sfvip-all/blob/master/dev/build.py"
    click DevPublish "https://github.com/sebdelsol/sfvip-all/blob/master/dev/publish.py"
    click DevTranslate "https://github.com/sebdelsol/sfvip-all/blob/master/dev/translate.py"
    click DevUpgrade "https://github.com/sebdelsol/sfvip-all/blob/master/dev/upgrade.py"
    click PyInstaller "https://github.com/sebdelsol/sfvip-all/blob/master/dev/tools/builder/pyinstaller.py"
    click Nuitka "https://github.com/sebdelsol/sfvip-all/blob/master/dev/tools/builder/nuitka.py"
    click NSISInstaller "https://github.com/sebdelsol/sfvip-all/blob/master/dev/tools/nsis/installer.py"

    %% Styles
    classDef internal fill:#AEDFF7,stroke:#036BC0,color:#000
    classDef external fill:#C8E6C9,stroke:#2E7D32,color:#000
    classDef pipeline fill:#FFE0B2,stroke:#EF6C00,color:#000
    classDef storage fill:#FFF9C4,stroke:#F9A825,color:#000
```
