# spiral023/plexport architecture

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

- Interactive diagram: https://gitdiagram.com/spiral023/plexport
- Repository: https://github.com/spiral023/plexport

## Overview

##### Main Components
- Installation Module: Represented by the install.bat script, which performs environment checks, downloads the main PLEXport.py script, installs dependencies (pandas, plexapi, openpyxl), and finally starts the application.
- Core Application Module: The main PLEXport.py script, which encapsulates all primary functionalities.
- Data Sources:
- Local Mode: A Plex database file (e.g., .db) that contains historical Plex data.
- Live Mode: A Plex server accessed via the plexapi, using Base URL and token for authentication.
- Data Processing & Export:
- Data Extraction: Functions within PLEXport.py that extract and possibly transform data from either the local database or live API responses.
- Excel Creation: Use of pandas and openpyxl to generate Excel files from the extracted data.
- Excel Comparison: Module or functions that compare two Excel exports to report differences.
- User Interface: The GUI window that opens after installation and script execution. This interface guides the user through selecting mediatheks, choosing between film or series data, and performing comparisons or statistical analyses.

##### Relationships and Data Flow
- The process starts with the Installation Module. It verifies Python is installed, then automatically downloads and prepares the environment.
- Once initiated, the Core Application Module (PLEXport.py) handles both the extraction and the export procedures.
- Depending on the mode selected, data will flow:
- In DB Mode, data is read from a local Plex database.
- In Live Mode, a connection is made to a Plex server via the plexapi and then related data is fetched.
- Extracted data is processed using pandas, then passed to the Excel export component via openpyxl.
- If the Excel Comparison feature is triggered, the application takes two Excel files as input, compares them, and outputs the differences and statistics to the user.
- The User Interface serves as both the control panel for these processes and the visualization point for statistics and help guides.

##### Design Patterns & Technologies
- Although the project is "monolithic" (a single main Python script orchestrating all functions), there is a logical separation of concerns:
- Installation and environment setup are handled externally.
- Data Access (local DB and live API interaction) is clearly delineated.
- Data transformation and output (Excel generation and comparison) is managed in dedicated code segments.
- Technologies and libraries include Python along with pandas for data manipulation, plexapi for live API interaction with Plex, and openpyxl for creating Excel files.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Initialization Layer
    subgraph "Initialization"
        A["Installation Module (install.bat)"]:::installation
        B["Core Application (PLEXport.py)"]:::core
        A -->|"initiates"| B
    end

    %% Data Acquisition Layer
    subgraph "Data Acquisition"
        C["Local Plex Database"]:::external
        D["Plex Server (via plexapi)"]:::external
    end

    %% Processing Layer
    subgraph "Processing"
        E["Data Extraction & Transformation"]:::processing
        F["Excel Export (pandas+openpyxl)"]:::processing
        G["Excel Comparison"]:::processing
    end

    %% Presentation Layer
    subgraph "Presentation"
        H["User Interface / GUI"]:::ui
    end

    %% Relationships
    B -->|"triggers"| E
    C -->|"provides_data"| E
    D -->|"provides_data"| E
    E -->|"exports"| F
    E -->|"compares"| G
    F -->|"updates"| H
    G -->|"updates"| H

    %% Click Events
    click A "https://github.com/spiral023/plexport/blob/main//install.bat"
    click B "https://github.com/spiral023/plexport/blob/main//PLEXport.py"
    click E "https://github.com/spiral023/plexport/blob/main//PLEXport.py"
    click F "https://github.com/spiral023/plexport/blob/main//PLEXport.py"
    click G "https://github.com/spiral023/plexport/blob/main//PLEXport.py"
    click H "https://github.com/spiral023/plexport/blob/main//PLEXport.py"

    %% Styles
    classDef installation fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef core fill:#ADFF2F,stroke:#333,stroke-width:2px;
    classDef external fill:#87CEFA,stroke:#333,stroke-width:2px;
    classDef processing fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef ui fill:#90EE90,stroke:#333,stroke-width:2px;
```
