# jkt3000/rubyplex architecture

> Architecture diagram of the GitHub repository jkt3000/rubyplex, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jkt3000/rubyplex
- Repository: https://github.com/jkt3000/rubyplex

## Overview

##### Main Components

a. Client Application Layer:
- How external Ruby applications integrate with the gem
- Configuration options (YAML file or direct configuration)

b. Core Gem Components:
- Main entry point (Plex.server)
- Class hierarchy and relationships

c. Plex Media Server:
- Connection to the external Plex Media Server
- HTTP/HTTPS communication

##### Top Level (Client Interface)
- It to a "Configuration" component (showing both YAML and direct config options)

##### Core Components (Middle Layer)
- Server
- Library
- Movie
- Media
- Part
- Show
- Episode
- Media
- Part

##### API Communication Layer
- HTTP/HTTPS connection to Plex Media Server
- Authentication with token
- Response parsing into Ruby objects

Use these visual elements:

Key Relationships to Highlight:

##### Model Hierarchy
- Base → Server → Library → (Movie/Show) → Media → Part
- Special relationship with Episodes

##### Data Flow
- Configuration → Server initialization
- Server → Library queries
- Library → Media object creation
- Media → File system representation

##### Error Handling
- Error propagation from API calls
- Error handling module connection

Technical details:

##### Entry Points
- Plex.server(config)
- Plex::Server.new(config)

##### Configuration Options
- Host
- Port
- Token

##### Key Methods
- Library: all, unwatched, newest, recently_added
- Search: find_by_filename, find_by_title
- Media handling: load_details!, to_hash, to_json

- Component types
- Common method patterns
- Configuration options

Level of Detail:
- Notes about pagination and filtering options
- Extension points for future features

Remember to:
##### Authentication flow

- How the gem integrates with applications
- Internal component relationships
- Data flow through the system
- Configuration options and flexibility
- Error handling patterns
- Extension points for future development

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef client fill:#a8d1ff,stroke:#333
    classDef config fill:#ffe0a8,stroke:#333
    classDef core fill:#a8ffd1,stroke:#333
    classDef external fill:#ffa8a8,stroke:#333
    classDef error fill:#ff8080,stroke:#333
    classDef api fill:#d1a8ff,stroke:#333
    classDef test fill:#e0e0e0,stroke:#333

    %% Client Application Layer
    Client["Client Application"]:::client
    Config["Configuration\n(YAML/Direct)"]:::config
    click Config "https://github.com/jkt3000/rubyplex/blob/master/rubyplex_config.yml"

    %% Core Components
    EntryPoint["Plex.server\nEntry Point"]:::core
    click EntryPoint "https://github.com/jkt3000/rubyplex/blob/master/lib/rubyplex.rb"

    Base["Base Component"]:::core
    click Base "https://github.com/jkt3000/rubyplex/blob/master/lib/plex/base.rb"

    Server["Server"]:::core
    click Server "https://github.com/jkt3000/rubyplex/blob/master/lib/plex/server.rb"

    Library["Library"]:::core
    click Library "https://github.com/jkt3000/rubyplex/blob/master/lib/plex/library.rb"

    %% Media Components
    subgraph MediaTypes["Media Types"]
        Movie["Movie"]:::core
        Show["Show"]:::core
        Episode["Episode"]:::core
        click Movie "https://github.com/jkt3000/rubyplex/blob/master/lib/plex/movie.rb"
        click Show "https://github.com/jkt3000/rubyplex/blob/master/lib/plex/show.rb"
        click Episode "https://github.com/jkt3000/rubyplex/blob/master/lib/plex/episode.rb"
    end

    subgraph MediaHandling["Media Handling"]
        Media["Media"]:::core
        Part["Part"]:::core
        Stream["Stream"]:::core
        click Media "https://github.com/jkt3000/rubyplex/blob/master/lib/plex/media.rb"
        click Part "https://github.com/jkt3000/rubyplex/blob/master/lib/plex/part.rb"
        click Stream "https://github.com/jkt3000/rubyplex/blob/master/lib/plex/stream.rb"
    end

    %% Error Handling
    ErrorHandler["Error Handler"]:::error
    click ErrorHandler "https://github.com/jkt3000/rubyplex/blob/master/lib/plex/errors.rb"

    %% External System
    PlexServer["Plex Media Server"]:::external

    %% Testing Components
    subgraph Testing["Test Suite"]
        MovieTest["Movie Tests"]:::test
        ShowTest["Show Tests"]:::test
        LibraryTest["Library Tests"]:::test
        ServerTest["Server Tests"]:::test
        MediaTest["Media Tests"]:::test
        click MovieTest "https://github.com/jkt3000/rubyplex/blob/master/test/movie_test.rb"
        click ShowTest "https://github.com/jkt3000/rubyplex/blob/master/test/show_test.rb"
        click LibraryTest "https://github.com/jkt3000/rubyplex/blob/master/test/library_test.rb"
        click ServerTest "https://github.com/jkt3000/rubyplex/blob/master/test/server_test.rb"
        click MediaTest "https://github.com/jkt3000/rubyplex/blob/master/test/media_test.rb"
    end

    %% Documentation
    APIDoc["API Documentation"]:::api
    click APIDoc "https://github.com/jkt3000/rubyplex/blob/master/docs/api_requests.rb"

    %% Relationships
    Client --> Config
    Config --> EntryPoint
    EntryPoint --> Base
    Base --> Server
    Server --> Library
    Library --> MediaTypes
    Movie & Show & Episode --> Media
    Media --> Part
    Part --> Stream
    Server -.-> ErrorHandler
    Server <--> PlexServer
    
    %% Testing Relationships
    MovieTest -.-> Movie
    ShowTest -.-> Show
    LibraryTest -.-> Library
    ServerTest -.-> Server
    MediaTest -.-> Media

    %% Legend
    subgraph Legend
        L1["Client Component"]:::client
        L2["Configuration"]:::config
        L3["Core Component"]:::core
        L4["External System"]:::external
        L5["Error Handling"]:::error
        L6["Testing"]:::test
        L7["API Documentation"]:::api
    end
```
