VOOZH about

URL: https://deepwiki.com/Automattic/BuddyPress-VIP-Go/2-system-architecture

⇱ System Architecture | Automattic/BuddyPress-VIP-Go | DeepWiki


Loading...
Menu

System Architecture

This document describes the overall architectural design of the BuddyPress VIP Go plugin, including major components, data flows, and key architectural decisions. For detailed information about specific subsystems, see:

Architectural Overview

The BuddyPress VIP Go plugin implements a metadata-driven, transformation-on-demand architecture that enables BuddyPress media functionality on WordPress VIP's distributed file hosting infrastructure. The plugin consists of two primary components that work together to intercept BuddyPress media operations and redirect them through VIP-compatible pathways.

The architecture addresses fundamental incompatibilities between BuddyPress's filesystem expectations (local directory scanning, file locking, pre-generated image sizes) and VIP Go's distributed file hosting service (no directory listing, no flock support, CDN-backed delivery).

Core Architectural Principles

  1. Separation of Storage and Transformation: Original media files are stored once in VIP FHS; transformations (crops, resizes) are applied dynamically via URL parameters rather than creating physical files
  2. Metadata as Source of Truth: All media information (URLs, crop coordinates, dimensions) is stored in WordPress database tables rather than derived from filesystem scanning
  3. Hook-Based Interception: BuddyPress operations are intercepted at the filter/action level to prevent filesystem operations before they occur
  4. Lazy Loading: Integration layer only loads when VIP environment markers are detected
  5. Root Blog Centralization: All metadata is stored on the root blog in multisite installations for consistent access patterns

Component Architecture


Sources:

Data Flow Architecture

The plugin implements distinct data flows for different media operations. Each flow follows the pattern of intercepting BuddyPress operations before filesystem access occurs.

Avatar Upload Flow


Sources:

Dynamic Image Retrieval Flow


Sources:

Filter Hook Architecture

The plugin's integration strategy relies on carefully timed filter hooks that intercept BuddyPress operations. Hook priorities and registration timing are critical to prevent filesystem operations.

Hook Registration Timeline


Sources:

Filter Categories and Return Patterns

Filter CategoryPurposeReturn PatternExample
Early PreventionPrevent filesystem operations before bp_initReturn empty/false before BP tries to scanbp_core_avatar_folder_dir__return_empty_string
URL ReplacementReplace filesystem-based URLs with VIP FHS URLsReturn complete URL with transformation paramsbp_core_default_avatar_uservipbp_filter_user_avatar_urls()
Operation InterceptionHandle media operations (upload, crop, delete)Return false to short-circuit BP functionbp_core_pre_avatar_handle_uploadvipbp_handle_avatar_upload()false
Path RedirectionRedirect paths from VIP FHS to local filesystemReturn alternative pathbfu_temp_dirvipbp_filter_chunked_upload_temp_dir()

Sources:

Metadata Schema

The plugin stores all media information in WordPress database tables, avoiding any dependency on filesystem scanning. Different media types use different metadata structures optimized for their transformation requirements.

Avatar Metadata Structure


Avatar metadata includes crop coordinates because users can select custom crop regions. The ui_width field prevents upscaling images that were uploaded from narrow displays (e.g., mobile devices with 320px width).

Cover metadata includes only the URL because cover images use a fixed crop pattern (middle 25% vertically, full width horizontally) applied via URL parameters at render time.

Sources:

URL Transformation Strategy

Instead of creating multiple physical image files (thumb, full), the plugin generates dynamic URLs with query parameters that instruct VIP FHS to perform transformations on-the-fly.

URL Parameter Mapping

ParameterPurposeSourceApplied By
wClamp maximum width (anti-upscale)ui_width from metadatafiles.php223
cropCrop coordinates (format: x,y,w,h)crop_x, crop_y, crop_w, crop_h from metadatafiles.php226-232
resizeTarget dimensions (format: w,h)$params['width'], $params['height'] from BPfiles.php235
stripRemove EXIF/IPTC dataAlways infofiles.php238

Example URL Transformation

Original uploaded file:

https://example.com/wp-content/uploads/2024/01/avatar-12345.jpg

Transformed URL for 150x150 avatar display:

https://example.com/wp-content/uploads/2024/01/avatar-12345.jpg?w=450&crop=50px,30px,400px,400px&resize=150,150&strip=info

The VIP File Hosting Service processes these parameters server-side, caching the result in the CDN for subsequent requests.

Sources:

Multisite Considerations

In WordPress multisite installations, the plugin centralizes all metadata storage on the root blog to simplify data access and avoid cross-blog metadata queries.


All metadata storage and retrieval functions check bp_is_root_blog() and call switch_to_blog() / restore_current_blog() as needed. This pattern appears in:

Sources:

BuddyBoss Compatibility Layer

BuddyBoss Platform extends BuddyPress with additional features that introduce new filesystem dependencies. The plugin includes specialized compatibility functions to handle these.

Default Group Avatar Handling

BuddyBoss's bb_get_default_custom_avatar() function uses opendir() to scan for avatar files, which fails on VIP FHS. The plugin uses a two-filter strategy to prevent this:

  1. option_bp-default-custom-group-avatar filter (files.php941-947): Returns empty string when VIP avatar exists, preventing the condition that triggers opendir()
  2. bb_get_default_custom_upload_group_avatar filter (files.php958-966): Provides the actual avatar URL from stored option

Chunked Video Upload Workaround

BuddyBoss's chunked video upload requires flock() for file locking, which VIP FHS doesn't support. The plugin redirects chunk assembly to local temp directory:

  • bfu_temp_dir filter (files.php923-925): Returns get_temp_dir() . 'bb-large-upload'
  • bp_core_pre_remove_temp_directory filter (files.php886-897): Uses wp_delete_file() instead of directory removal
  • bp_video_after_save action (files.php905-907): Flushes cache after video moves to final location

Sources:

Security and Permissions

The plugin relies on BuddyPress's upstream permission checks rather than implementing its own authorization layer. All media operation functions document their permission check dependency:

  • Avatar uploads: Permission checks in xprofile_screen_change_avatar() (files.php329)
  • Cover uploads: Permission checks in bp_attachments_cover_image_ajax_upload() (files.php554)
  • Avatar crops: Permission checks in xprofile_screen_change_avatar() (files.php657)
  • Deletions: Permission checks in "several screen handling functions" (files.php744 files.php841)

Files are stored in VIP FHS with standard WordPress upload permissions. VIP's security model controls access through its file hosting infrastructure.

Sources: