# robertandrews/cwp-tidy-media architecture

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

- Interactive diagram: https://gitdiagram.com/robertandrews/cwp-tidy-media
- Repository: https://github.com/robertandrews/cwp-tidy-media

## Overview

##### Main Components

a) Core Plugin Components:
- WordPress Core Integration Layer
- Media Processing Engine
- File System Manager
- Database Manager
- Settings Manager
- Admin Interface

b) Data Stores:
- WordPress Database (wp_posts, wp_postmeta tables)
- Custom Database Table (wp_tidy_media_organizer)
- WordPress File System (media files)

##### Key Flows

Create distinct flow paths for the five main features:

##### Specific Implementation Details

- Blue: WordPress Core Integration Points
- Green: File System Operations
- Orange: Database Operations
- Purple: Media Processing Functions
- Gray: Configuration/Settings

##### Component Relationships

- How the plugin hooks into WordPress' save_post action
- Database table relationships
- File system interaction paths
- Media Library integration points

##### Specific Elements

- /includes/plugin/admin.php: Admin Interface Controller
- /includes/plugin/wpdb.php: Database Operations
- /includes/origin/: Media Organization Logic
- /includes/content.php: Content Processing
- /includes/media.php: Media Handling
- /includes/notices.php: User Notification System

##### Technical Details to Note

Annotations for:
- Custom table schema (wp_tidy_media_organizer)
- WordPress hook integration points
- File path transformation logic
- Database field updates (guid, post_parent, etc.)

##### Process Flows

Order of operations:
##### Cleanup operations

- Media file movement workflow
- Database update sequence
- Remote image processing pipeline

This will help other developers understand both the high-level architecture and the detailed implementation specifics of the plugin.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        AdminSettings["Admin Settings Page"]:::ui
        BulkOps["Bulk Operations Interface"]:::ui
        PostEditor["Post Editor Integration"]:::ui
    end

    subgraph WP["WordPress Integration Layer"]
        WPCore["WordPress Core"]:::wp
        Hooks["Action/Filter Hooks"]:::wp
        PostSave["Post Save Handlers"]:::wp
        MediaLib["Media Library Integration"]:::wp
    end

    subgraph Core["Core Processing Layer"]
        MainController["Main Plugin Controller"]:::core
        MediaEngine["Media Processing Engine"]:::core
        ContentProc["Content Processing"]:::core
        MediaOrg["Media Organization Engine"]:::core
        URLProc["URL Processing"]:::core
        RemoteImg["Remote Image Fetcher"]:::core
        FSOperations["File System Operations"]:::core
    end

    subgraph Storage["Storage Layer"]
        DBOps["Database Operations"]:::storage
        FSManager["File System Manager"]:::storage
        WPDatabase[(WordPress Database)]:::db
        CustomTable[(Custom Media Table)]:::db
        FileSystem[("WordPress File System")]:::fs
    end

    %% UI Layer Connections
    AdminSettings --> MainController
    BulkOps --> MediaOrg
    PostEditor --> PostSave

    %% WordPress Integration Connections
    WPCore --> Hooks
    Hooks --> PostSave
    Hooks --> MediaLib
    PostSave --> MainController

    %% Core Processing Connections
    MainController --> MediaEngine
    MainController --> ContentProc
    MediaEngine --> URLProc
    MediaEngine --> RemoteImg
    MediaEngine --> FSOperations
    ContentProc --> MediaOrg
    MediaOrg --> FSOperations
    MediaOrg --> DBOps

    %% Storage Layer Connections
    DBOps --> WPDatabase
    DBOps --> CustomTable
    FSOperations --> FSManager
    FSManager --> FileSystem

    %% Click Events
    click WPCore "https://github.com/robertandrews/cwp-tidy-media/blob/main/wp-tidy-media.php"
    click AdminSettings "https://github.com/robertandrews/cwp-tidy-media/blob/main/includes/plugin/admin.php"
    click PostEditor "https://github.com/robertandrews/cwp-tidy-media/blob/main/assets/js/origin-edit.js"
    click MainController "https://github.com/robertandrews/cwp-tidy-media/blob/main/includes/main.php"
    click MediaEngine "https://github.com/robertandrews/cwp-tidy-media/blob/main/includes/media.php"
    click ContentProc "https://github.com/robertandrews/cwp-tidy-media/blob/main/includes/content.php"
    click MediaOrg "https://github.com/robertandrews/cwp-tidy-media/tree/main/includes/origin/"
    click DBOps "https://github.com/robertandrews/cwp-tidy-media/blob/main/includes/plugin/wpdb.php"
    click Notifications "https://github.com/robertandrews/cwp-tidy-media/blob/main/includes/notices.php"

    %% Styles
    classDef ui fill:#f9f,stroke:#333,stroke-width:2px
    classDef wp fill:#9cf,stroke:#333,stroke-width:2px
    classDef core fill:#fc9,stroke:#333,stroke-width:2px
    classDef storage fill:#9fc,stroke:#333,stroke-width:2px
    classDef db fill:#666,stroke:#333,stroke-width:2px,color:#fff
    classDef fs fill:#996,stroke:#333,stroke-width:2px,color:#fff

    %% Legend
    subgraph Legend
        UI_Legend["UI Component"]:::ui
        WP_Legend["WordPress Integration"]:::wp
        Core_Legend["Core Processing"]:::core
        Storage_Legend["Storage Component"]:::storage
        DB_Legend["Database"]:::db
        FS_Legend["File System"]:::fs
    end
```
