# criticalsession/magic-episode-sort-v2 architecture

> Architecture diagram of the GitHub repository criticalsession/magic-episode-sort-v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/criticalsession/magic-episode-sort-v2
- Repository: https://github.com/criticalsession/magic-episode-sort-v2

## Overview

##### Main Components

a. User Interface Layer (WPF Application)
- XAML-based UI components (MainWindow, Preferences, EditSources, etc.)
- MVVM pattern implementation

b. Core Business Logic Layer ("TheMagic" directory)
- File Processing Components
- Series Management
- Settings Management
- External API Integration

c. Data Persistence Layer
- SQLite Database (MESDB.db)
- Settings Storage

##### Key Relationships to Illustrate

**[UI Layer (WPF)] ↔ [Business Logic Layer] ↔ [Data Layer]**

UI Layer Components:
**MainWindow → EditSources**
- → Preferences
- → EditCustomSeriesTitles
- → EditSkipDirectories
- → SortFailed
- → About

Business Logic Components:
**SeriesTitleExtractor ↔ TVMazeAPI**
**EpisodeMover ↔ Directree/Targetree**
**SettingsManager ↔ Models**

Data Layer Components:
**MESDBHandler ← Models**
**Settings Storage ← SettingsManager**

##### Important Elements

- Blue: UI Components
- Green: Business Logic
- Yellow: Data Storage
- Purple: External Services (TVMaze API)

b. Component Relationships:

##### Specific Implementation Details

- File processing flow (VideoFile → SeriesTitleExtractor → EpisodeMover)
- Settings management (SettingsManager interaction with Models)
- External API integration (TVMazeAPI)
- Database operations (MESDBHandler)

##### Key Architectural Patterns

- MVVM Pattern (WPF implementation)
- Repository Pattern (for database access)
- Service Layer Pattern (TVMazeAPI integration)

##### Technical Stack Indicators

Technology badges or labels:
- .NET (WPF)
- SQLite
- TVMaze API
- Windows Installer

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef ui fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef logic fill:#90EE90,stroke:#333,stroke-width:2px
    classDef data fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:2px
    
    %% UI Layer
    subgraph UI
        MW["Main Window"]
        PREF["Preferences"]
        ES["Edit Sources"]
        ECST["Edit Custom Series"]
        ESD["Edit Skip Directories"]
        SF["Sort Failed"]
        AB["About"]
    end
    
    %% Business Logic Layer
    subgraph Logic
        VF["Video File Processor"]
        STE["Series Title Extractor"]
        EM["Episode Mover"]
        DT["Directory Tree"]
        TT["Target Tree"]
        SM["Settings Manager"]
        SDM["Source Directories Manager"]
        TVAPI["TVMaze API"]
    end
    
    %% Data Models
    subgraph Models
        STM["Series Title Model"]
        SetM["Settings Model"]
        SkipM["Skip Directory Model"]
        SrcM["Source Model"]
    end
    
    %% Data Layer
    subgraph Data
        DB["MESDB.db"]
        DBH["Database Handler"]
        V1["v1 Settings"]
        OSM["Old Settings Migrator"]
    end
    
    %% Relationships
    MW --> PREF
    MW --> ES
    MW --> ECST
    MW --> ESD
    MW --> SF
    MW --> AB
    
    MW --> VF
    VF --> STE
    STE --> TVAPI
    STE --> EM
    EM --> DT
    EM --> TT
    
    SM --> SetM
    SDM --> SrcM
    DBH --> DB
    OSM --> V1
    
    %% Click Events
    click MW "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/Magic Episode Sort v2/MainWindow.xaml"
    click PREF "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/Magic Episode Sort v2/Preferences.xaml"
    click ES "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/Magic Episode Sort v2/EditSources.xaml"
    click ECST "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/Magic Episode Sort v2/EditCustomSeriesTitles.xaml"
    click ESD "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/Magic Episode Sort v2/EditSkipDirectories.xaml"
    click SF "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/Magic Episode Sort v2/SortFailed.xaml"
    click AB "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/Magic Episode Sort v2/About.xaml"
    click VF "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/VideoFile.cs"
    click STE "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/SeriesTitleExtractor.cs"
    click EM "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/EpisodeMover.cs"
    click DT "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/Directree.cs"
    click TT "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/Targetree.cs"
    click TVAPI "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/TVMazeAPI.cs"
    click SM "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/SettingsManager.cs"
    click SDM "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/SourceDirectoriesManager.cs"
    click STM "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/Models/SeriesTitleModel.cs"
    click SetM "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/Models/SettingsModel.cs"
    click SkipM "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/Models/SkipDirectoryModel.cs"
    click SrcM "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/Models/SourceModel.cs"
    click DB "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/MESDB.db"
    click DBH "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/MESDBHandler.cs"
    click OSM "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/OldSettingsMigrator.cs"
    click V1 "https://github.com/criticalsession/Magic-Episode-Sort-v2/blob/master/TheMagic/v1Settings/v1Settings.cs"
    
    %% Style Applications
    class MW,PREF,ES,ECST,ESD,SF,AB ui
    class VF,STE,EM,DT,TT,SM,SDM logic
    class STM,SetM,SkipM,SrcM,DB,DBH,V1,OSM data
    class TVAPI external
```
