Technical Documentation - Juzt Deploy
System Architecture
Component Diagram
Text
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ WordPress │ │ Middleware │ │ GitHub │
│ Admin UI │◄──►│ OAuth Service │◄──►│ API │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Repo Manager │ │ Git Interface │ │ File System │
│ + Database │ │ (CLI/API) │ │ Operations │
└─────────────────┘ └──────────────────┘ └─────────────────┘
Installation Flow

Data Flows
OAuth Authentication
Bash
// Complete authentication flow
User → WordPress → Middleware → GitHub → Callback → Tokens → WordPress
Repository Cloning
Php
$repo_url = "https://github.com/owner/repo"
$branch = "main"
$type = "theme|plugin"
$custom_name = "Custom Name"
Process
- Validate OAuth permissions
- Resolve destination path
- Execute cloning (CLI/API)
- Update theme / plugins metadata
- Register in database
Database Structure
Table wp_github_repos
Sql
CREATE TABLE wp_github_repos (
id mediumint(9) NOT NULL AUTO_INCREMENT,
repo_name varchar(255) NOT NULL, -- Display name
repo_url varchar(500) NOT NULL, -- Repository URL
local_path varchar(500) NOT NULL, -- Absolute path (legacy)
folder_name varchar(255) NULL, -- Folder name (new)
current_branch varchar(255) NOT NULL, -- Current branch
repo_type varchar(20) NOT NULL, -- 'theme' or 'plugin'
last_update datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY local_path (local_path)
);
Table wp_wpvtp_commits_queue
Sql
CREATE TABLE wp_wpvtp_commits_queue (
id bigint(20) NOT NULL AUTO_INCREMENT,
theme_path varchar(255) NOT NULL, -- Theme/repo path
commit_message text NOT NULL, -- Commit message
file_path varchar(500) NULL, -- Specific file (optional)
status varchar(20) NOT NULL DEFAULT 'pending', -- pending/processing/completed/failed
attempts int(11) NOT NULL DEFAULT 0, -- Attempts made
last_error text NULL, -- Last error encountered
created_at datetime NOT NULL, -- Creation date
processed_at datetime NULL, -- Processing date
PRIMARY KEY (id),
KEY status (status),
KEY created_at (created_at)
);
Migrations
Php
// Automatic migration in class-repo-manager.php
public function migrate_old_paths() {}
APIs and Services
Php
const OAUTH_SERVICE_URL = 'https://github-app-api-production.up.railway.app';
Main endpoints
Php
'/auth/github' // Start OAuth flow
'/auth/github/refresh' // Refresh token
'/api/github/user' // User information
'/api/github/installations' // App installations
'/api/github/repos/{owner}/{type}' // Repositories by owner
OAuth Service Class
Php
class WPVTP_OAuth_Service {
private $session_token;
private $refresh_token;
public function get_authorization_url();
public function make_request($endpoint, $method, $data);
public function refresh_access_token();
public function get_all_repositories();
public function get_installations();
}
Github API Handler
Dual implementation (CLI/API)
Php
abstract class WPVTP_Git_Interface {
abstract public function clone_repository($repo_url, $branch, $destination, $access_token);
abstract public function update_repository($repo_path, $access_token);
abstract public function switch_branch($repo_path, $new_branch, $access_token);
abstract public function commit_and_push($repo_path, $file_path, $commit_message, $access_token);
}
class WPVTP_Git_CLI extends WPVTP_Git_Interface {
// Uses Git exec() commands
}
class WPVTP_Git_API extends WPVTP_Git_Interface {
// Uses GitHub API via ZIP downloads
}
Classes and Patterns
Main Class: WP_Versions_Themes_plugins
Php
class WP_Versions_Themes_Plugins {
// Singleton pattern
private static $instance = null;
public static function get_instance() {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
// Main hooks
private function init() {
add_action('admin_menu', array($this, 'add_admin_menu'));
add_action('setup_theme', array($this, 'handle_theme_preview'), 1);
// ... more hooks
}
}
Repository Manager: WPVTP_Repo_Manager
Php
class WPVTP_Repo_Manager {
// Git mode detection strategy
public function detect_git_mode() {
// 1. Check exec() function
// 2. Check Git installation
// 3. Decide CLI/API mode
}
// Factory pattern for Git instance
private function get_git_instance() {
$mode = $this->get_git_mode();
return ($mode === 'cli') ? new WPVTP_Git_CLI() : new WPVTP_Git_API();
}
}
Progress Tracker
Php
class WPVTP_Progress_Tracker {
// Uses WordPress transients for real-time tracking
public function update($step, $message, $progress = 0) {
set_transient('wpvtp_progress_' . $this->job_id, $data, 300);
}
// Bidirectional communication via AJAX
public static function get_progress($job_id) {
return get_transient('wpvtp_progress_' . $job_id);
}
}
Security
Token Management
Php
// Secure storage
update_option('wpvtp_oauth_token', $session_token);
update_option('wpvtp_refresh_token', $refresh_token);
// Automatic refresh
public function auto_refresh_token_if_needed() {
// Refresh every 7h 50min (before expiration)
$refresh_interval = 7 * 60 * 60 + 50 * 60;
}
Imput Validation
Php
// Sanitization in AJAX handlers
$owner = sanitize_text_field($_POST['owner']);
$repo = sanitize_text_field($_POST['repo']);
$branch = sanitize_text_field($_POST['branch']);
// Nonce verification
check_ajax_referer('wpvtp_nonce', 'nonce');
Path Traversal Protection
Php
// In serve_zip_file()
$file = isset($_GET['file']) ? sanitize_file_name($_GET['file']) : '';
$filepath = get_temp_dir() . $file;
// Verify file exists and is in temp dir
if (!file_exists($filepath)) {
wp_die('File not found');
}
Error handling
Hierarchical Error System
- Validation errors (invalid input)
- Authentication error (OAuth)
- Github API Errors (rate limits, permissions)
- System error (Git unavailable, file permissions)
- Network errors (timeout, connection)
Php
try {
$result = $git->clone_repository($repo_url, $branch, $destination, $access_token);
if (!$result['success']) {
throw new Exception($result['error']);
}
} catch (Exception $e) {
error_log('WPVTP Error: ' . $e->getMessage());
return array('success' => false, 'error' => $e->getMessage());
}
Recovery Strategies
Php
// Automatic retries in commit queue
if ($item['attempts'] >= 3) {
$status = 'failed';
} else {
$status = 'pending';
}
// Fallback between Git modes
if ($this->get_git_mode() === 'cli' && !$cli_available) {
// Automatic fallback to API mode
$this->force_git_mode('api');
}
Optimizations
Caching Strategy
Php
// Cache organizations and repositories (1 hour)
set_transient('wpvtp_orgs_' . $user_id, $organizations, HOUR_IN_SECONDS);
// Cache branches (30 minutes)
set_transient('wpvtp_branches_' . $owner . '_' . $repo, $branches, 30 * MINUTE_IN_SECONDS);
Lazy loading
Php
// On-demand loading of repositories
public function get_installed_repos() {
// Only resolve paths when requested
foreach ($repos as &$repo) {
$repo['local_path'] = $this->resolve_local_path($repo['folder_name'], $repo['repo_type']);
$repo['exists'] = is_dir($repo['local_path']); // Lazy verification
}
}
Batch Processing
Php
// Batch processing in commit queue
public function process_commit_queue_batch($limit = 5) {
$items = $wpdb->get_results(
"SELECT * FROM $table_name
WHERE status = 'pending' AND attempts < 3
ORDER BY created_at ASC
LIMIT $limit",
ARRAY_A
);
foreach ($items as $item) {
$this->process_commit_queue_item($item['id']);
}
}
Hooks and Filters
Available Actions
Php
/**
* Executed after successfully cloning a repository
* @param string $repo_path Path of the cloned repository
* @param array $repo_data Repository data
*/
do_action('wpvtp_repo_cloned', $repo_path, $repo_data);
/**
* Executed before processing a commit in the queue
* @param int $commit_id ID of the commit in queue
* @param array $commit_data Commit data
*/
do_action('wpvtp_before_commit_processing', $commit_id, $commit_data);
/**
* Executed after updating a repository
* @param string $repo_path Path of the updated repository
* @param string $result Operation result
*/
do_action('wpvtp_repo_updated', $repo_path, $result);
/**
* Executed when Git mode changes
* @param string $old_mode Previous mode
* @param string $new_mode New mode
*/
do_action('wpvtp_git_mode_changed', $old_mode, $new_mode);
Available Filters
Php
/**
* Filters the list of available organizations
* @param array $organizations List of organizations
* @return array Filtered list
*/
apply_filters('wpvtp_available_organizations', $organizations);
/**
* Filters repositories available for installation
* @param array $repositories List of repositories
* @param string $owner Repository owner
* @return array Filtered list
*/
apply_filters('wpvtp_available_repositories', $repositories, $owner);
/**
* Filters the generated folder name for a repository
* @param string $folder_name Generated name
* @param string $repo_name Repository name
* @param string $branch Selected branch
* @return string Modified name
*/
apply_filters('wpvtp_repo_folder_name', $folder_name, $repo_name, $branch);
/**
* Filters the local path where repository will be installed
* @param string $local_path Generated path
* @param string $folder_name Folder name
* @param string $type Type (theme/plugin)
* @return string Modified path
*/
apply_filters('wpvtp_repo_local_path', $local_path, $folder_name, $type);
/**
* Filters commit message before execution
* @param string $commit_message Original message
* @param string $context Commit context
* @return string Modified message
*/
apply_filters('wpvtp_commit_message', $commit_message, $context);
/**
* Filters Git configuration before executing commands
* @param array $git_config Current configuration
* @param string $operation Operation to perform
* @return array Modified configuration
*/
apply_filters('wpvtp_git_config', $git_config, $operation);
Hooks usage example
Extend commit functionality
Php
// In theme functions.php or another plugin
add_action('wpvtp_before_commit_processing', function($commit_id, $commit_data) {
// Log all processed commits
error_log("Processing commit ID: $commit_id for: " . $commit_data['theme_path']);
});
add_filter('wpvtp_commit_message', function($message, $context) {
// Add automatic prefix to commit messages
if ($context === 'auto_commit') {
return '[Auto] ' . $message;
}
return $message;
}, 10, 2);
Filter available repositories
Php
add_filter('wpvtp_available_repositories', function($repositories, $owner) {
// Exclude specific repositories
$excluded_repos = ['test-repo', 'sandbox'];
return array_filter($repositories, function($repo) use ($excluded_repos) {
return !in_array($repo['name'], $excluded_repos);
});
}, 10, 2);
Modified installation behavior
Php
add_filter('wpvtp_repo_folder_name', function($folder_name, $repo_name, $branch) {
// Use different format for folder names
if ($branch !== 'main' && $branch !== 'master') {
return $repo_name . '_' . $branch;
}
return $folder_name;
}, 10, 3);