# wordpress/reprint architecture

> Architecture diagram of the GitHub repository wordpress/reprint, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wordpress/reprint
- Repository: https://github.com/wordpress/reprint

## Overview

#### Purpose and entry points
Reprint is a PHP 7.4+ WordPress migration system: an exporter installed on a source WordPress site exposes a resumable authenticated HTTP API; an importer clones files, database, and runtime assumptions to a target. Primary CLI entrypoint: `packages/reprint-importer/src/import.php`, distributed as a PHAR via `bin/build-reprint-phar.sh`. `importer/import.php` is a compatibility wrapper. The source plugin entrypoint is `reprint-exporter-wp/index.php`.

#### Export server and protocol
The reusable export engine implements HTTP serving, HMAC authentication, staged endpoints, and resumable streaming protocols. It produces filesystem indexes/content and MySQL SQL dumps, backed by WordPress `$wpdb` or PDO/SQLite adapters.
- `packages/reprint-exporter/src/export.php`
- `packages/reprint-exporter/src/class-http-server.php`
- `packages/reprint-exporter/src/class-staged-push-stream-protocol.php`
- `packages/reprint-exporter/src/class-file-tree-producer.php`
- `packages/reprint-exporter/src/class-mysql-dump-producer.php`

The WordPress plugin packages this engine and exposes its site-export route. Source and target share an HMAC secret, establishing the trust boundary around remote migration data.
- `reprint-exporter-wp/index.php`
- `reprint-exporter-wp/wordpress/site-export.php`
- `packages/reprint-exporter/src/class-hmac-server.php`

#### Import orchestration and durable state
The importer CLI coordinates `preflight`, file sync, database pull/apply, runtime generation, and high-level `pull` variants. Its persistent import state/status enables restart after interruption, delta sync, cursored transfer, and crash recovery; state is the boundary between independent command invocations.
- `packages/reprint-importer/src/import.php`
- `packages/reprint-importer/src/lib/state/class-import-state.php`
- `packages/reprint-importer/bin/reprint-importer`

#### File migration pipeline
File transfer is a staged remote-index → local diff → download-list → streamed-body workflow. It supports filtering, path selection, resumable cursors, integrity/error handling, deletion/type changes, and symlink-aware reconstruction. Push-related client components batch and size staged stream requests; pull handles remote retrieval.
- `packages/reprint-importer/src/lib/pull/class-pull.php`
- `packages/reprint-importer/src/lib/upload/class-staged-push-stream-client.php`
- `packages/reprint-importer/src/lib/upload/class-push-request-sizer.php`
- `packages/reprint-importer/src/lib/push/class-push-journal.php`

#### Database transfer and transformation
The exporter streams SQL while the importer can persist it, emit it, or execute it directly against MySQL. `db-apply` targets MySQL or SQLite and rewrites site URLs safely across SQL literals, serialized PHP, JSON, and structured WordPress data. SQLite support depends on the bundled database-integration library.
- `packages/reprint-importer/src/lib/mysql-query-stream/class-wp-mysql-fast-query-stream.php`
- `packages/reprint-importer/src/lib/url-rewrite/class-sql-statement-rewriter.php`
- `packages/reprint-importer/src/lib/url-rewrite/class-structured-data-url-rewriter.php`
- `packages/reprint-exporter/src/class-sqlite-driver-pdo.php`
- `lib/sqlite-database-integration`

#### Host analysis and target runtime generation
Preflight gathers remote environment/layout data. Source-host analyzers translate it into a declarative runtime manifest; target runtime appliers render runtime PHP plus launch/server configuration. These are intentionally decoupled extension points: hosts include WP Cloud, SiteGround, and default; targets include PHP built-in, nginx/PHP-FPM, and Playground CLI.
- `packages/reprint-importer/src/lib/host/class-runtime-manifest.php`
- `packages/reprint-importer/src/lib/host/analyzers/class-wpcloud-host-analyzer.php`
- `packages/reprint-importer/src/lib/target-runtime/class-php-builtin-applier.php`
- `packages/reprint-importer/src/lib/target-runtime/class-nginx-fpm-applier.php`
- `packages/reprint-importer/src/lib/target-runtime/class-playground-cli-applier.php`

#### Distribution and optional UI
The repository publishes separate Composer packages, a WordPress plugin ZIP, and a self-contained PHAR. A small PHP UI provides migration-oriented browser endpoints and Playground upload proxy support; it is not the core migration path.
- `composer.json`
- `box.json`
- `reprint-ui/index.php`
- `reprint-ui/reprint-import.php`

Main entry points: [`packages/reprint-importer/src/import.php`](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/import.php) (Importer CLI), [`packages/reprint-exporter/src/export.php`](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/export.php) (Export engine), [`packages/reprint-importer/src/lib/pull/class-pull.php`](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/pull/class-pull.php) (Pull pipeline), [`packages/reprint-exporter/src/class-http-server.php`](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/class-http-server.php) (HTTP server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_source["Source WordPress"]
  node_wp_plugin["Exporter WP plugin<br/>WordPress plugin<br/>[index.php]"]
  node_site_export["Site export route<br/>HTTP route<br/>[site-export.php]"]
  node_export_engine["Export engine<br/>PHP library<br/>[export.php]"]
  node_http_server["HTTP server<br/>protocol server"]
  node_hmac_server{{"HMAC authentication<br/>trust boundary"}}
  node_stream_protocol["Staged stream protocol<br/>resumable protocol"]
  node_file_producer["File tree producer<br/>export producer"]
  node_sql_producer["MySQL dump producer<br/>export producer"]
end

subgraph group_importer["Importer"]
  node_import_cli["Importer CLI<br/>CLI entrypoint<br/>[import.php]"]
  node_import_state[("Import state<br/>durable state")]
  node_pull_pipeline["Pull pipeline<br/>file sync<br/>[class-pull.php]"]
  node_push_client["Staged push client<br/>stream client"]
  node_push_journal[("Push journal<br/>transfer journal")]
  node_sql_stream["SQL query stream<br/>database transfer"]
  node_sql_rewriter["SQL URL rewriter<br/>data transformation"]
  node_runtime_manifest["Runtime manifest<br/>host abstraction"]
end

subgraph group_target["Target Runtime"]
  node_target_appliers["Target runtime appliers<br/>runtime generation"]
  node_target_site["Target site<br/>WordPress runtime"]
end

subgraph group_distribution["Distribution &amp; UI"]
  node_packaging["Package &amp; PHAR build<br/>distribution<br/>[box.json]"]
  node_migration_ui["Migration UI<br/>optional PHP UI<br/>[index.php]"]
end

node_wp_plugin -->|"registers"| node_site_export
node_site_export -->|"invokes"| node_export_engine
node_export_engine -->|"serves through"| node_http_server
node_http_server -->|"authenticates with"| node_hmac_server
node_export_engine -->|"uses"| node_stream_protocol
node_export_engine -->|"exports files"| node_file_producer
node_export_engine -->|"streams SQL"| node_sql_producer
node_import_cli -->|"persists progress"| node_import_state
node_import_cli -->|"orchestrates"| node_pull_pipeline
node_pull_pipeline -->|"retrieves export"| node_http_server
node_pull_pipeline -->|"resumes streams"| node_stream_protocol
node_push_client -->|"sends staged requests"| node_stream_protocol
node_import_cli -->|"records transfers"| node_push_journal
node_import_cli -->|"pulls or applies SQL"| node_sql_stream
node_sql_stream -->|"transforms statements"| node_sql_rewriter
node_sql_rewriter -->|"applies database"| node_target_site
node_import_cli -->|"builds after preflight"| node_runtime_manifest
node_runtime_manifest -->|"drives"| node_target_appliers
node_target_appliers -->|"generates runtime"| node_target_site
node_pull_pipeline -->|"reconstructs files"| node_target_site
node_packaging -->|"bundles as PHAR"| node_import_cli
node_migration_ui -.->|"supports migration flow"| node_import_cli

click node_wp_plugin "https://github.com/wordpress/reprint/blob/trunk/reprint-exporter-wp/index.php"
click node_site_export "https://github.com/wordpress/reprint/blob/trunk/reprint-exporter-wp/wordpress/site-export.php"
click node_export_engine "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/export.php"
click node_http_server "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/class-http-server.php"
click node_hmac_server "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/class-hmac-server.php"
click node_stream_protocol "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/class-staged-push-stream-protocol.php"
click node_file_producer "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/class-file-tree-producer.php"
click node_sql_producer "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/class-mysql-dump-producer.php"
click node_import_cli "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/import.php"
click node_import_state "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/state/class-import-state.php"
click node_pull_pipeline "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/pull/class-pull.php"
click node_push_client "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/upload/class-staged-push-stream-client.php"
click node_push_journal "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/push/class-push-journal.php"
click node_sql_stream "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/mysql-query-stream/class-wp-mysql-fast-query-stream.php"
click node_sql_rewriter "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/url-rewrite/class-sql-statement-rewriter.php"
click node_runtime_manifest "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/host/class-runtime-manifest.php"
click node_target_appliers "https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/target-runtime/class-php-builtin-applier.php"
click node_packaging "https://github.com/wordpress/reprint/blob/trunk/box.json"
click node_migration_ui "https://github.com/wordpress/reprint/blob/trunk/reprint-ui/index.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_wp_plugin,node_site_export,node_export_engine,node_http_server,node_hmac_server,node_stream_protocol,node_file_producer,node_sql_producer toneBlue
class node_import_cli,node_import_state,node_pull_pipeline,node_push_client,node_push_journal,node_sql_stream,node_sql_rewriter,node_runtime_manifest toneAmber
class node_target_appliers,node_target_site toneMint
class node_packaging,node_migration_ui toneRose
```

## Components

### Source WordPress

Authenticated export surface.

- [Exporter WP plugin](https://github.com/wordpress/reprint/blob/trunk/reprint-exporter-wp/index.php): WordPress plugin · `reprint-exporter-wp/index.php`
- [Site export route](https://github.com/wordpress/reprint/blob/trunk/reprint-exporter-wp/wordpress/site-export.php): HTTP route · `reprint-exporter-wp/wordpress/site-export.php`
- [Export engine](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/export.php): PHP library · Serves staged filesystem and database exports. · `packages/reprint-exporter/src/export.php`
- [HTTP server](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/class-http-server.php): protocol server · `packages/reprint-exporter/src/class-http-server.php`
- [HMAC authentication](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/class-hmac-server.php): trust boundary · Shared secret authenticates migration requests. · `packages/reprint-exporter/src/class-hmac-server.php`
- [Staged stream protocol](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/class-staged-push-stream-protocol.php): resumable protocol · `packages/reprint-exporter/src/class-staged-push-stream-protocol.php`
- [File tree producer](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/class-file-tree-producer.php): export producer · `packages/reprint-exporter/src/class-file-tree-producer.php`
- [MySQL dump producer](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-exporter/src/class-mysql-dump-producer.php): export producer · `packages/reprint-exporter/src/class-mysql-dump-producer.php`

### Importer

CLI orchestration and durable migration pipeline.

- [Importer CLI](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/import.php): CLI entrypoint · Coordinates preflight, pull, apply, and runtime generation. · `packages/reprint-importer/src/import.php`
- [Import state](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/state/class-import-state.php): durable state · Persists status and cursors across command invocations. · `packages/reprint-importer/src/lib/state/class-import-state.php`
- [Pull pipeline](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/pull/class-pull.php): file sync · Fetches remote indexes, diffs, and streamed file bodies. · `packages/reprint-importer/src/lib/pull/class-pull.php`
- [Staged push client](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/upload/class-staged-push-stream-client.php): stream client · Batches and sizes staged transfer requests. · `packages/reprint-importer/src/lib/upload/class-staged-push-stream-client.php`
- [Push journal](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/push/class-push-journal.php): transfer journal · `packages/reprint-importer/src/lib/push/class-push-journal.php`
- [SQL query stream](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/mysql-query-stream/class-wp-mysql-fast-query-stream.php): database transfer · `packages/reprint-importer/src/lib/mysql-query-stream/class-wp-mysql-fast-query-stream.php`
- [SQL URL rewriter](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/url-rewrite/class-sql-statement-rewriter.php): data transformation · Safely rewrites SQL literals and structured WordPress data. · `packages/reprint-importer/src/lib/url-rewrite/class-sql-statement-rewriter.php`
- [Runtime manifest](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/host/class-runtime-manifest.php): host abstraction · Decouples source-host analysis from target application. · `packages/reprint-importer/src/lib/host/class-runtime-manifest.php`

### Target Runtime

Generated runtime and applied data.

- [Target runtime appliers](https://github.com/wordpress/reprint/blob/trunk/packages/reprint-importer/src/lib/target-runtime/class-php-builtin-applier.php): runtime generation · Renders PHP and launch configuration for supported targets. · `packages/reprint-importer/src/lib/target-runtime/class-php-builtin-applier.php`
- **Target site**: WordPress runtime · Receives synchronized files, database, and generated configuration.

### Distribution & UI

Packaging and optional browser interface.

- [Package & PHAR build](https://github.com/wordpress/reprint/blob/trunk/box.json): distribution · Publishes Composer packages, plugin ZIP, and importer PHAR. · `box.json`
- [Migration UI](https://github.com/wordpress/reprint/blob/trunk/reprint-ui/index.php): optional PHP UI · Browser endpoints and Playground upload proxy. · `reprint-ui/index.php`

## Connections

- Exporter WP plugin → Site export route: registers
- Site export route → Export engine: invokes
- Export engine → HTTP server: serves through
- HTTP server → HMAC authentication: authenticates with
- Export engine → Staged stream protocol: uses
- Export engine → File tree producer: exports files
- Export engine → MySQL dump producer: streams SQL
- Importer CLI → Import state: persists progress
- Importer CLI → Pull pipeline: orchestrates
- Pull pipeline → HTTP server: retrieves export
- Pull pipeline → Staged stream protocol: resumes streams
- Staged push client → Staged stream protocol: sends staged requests
- Importer CLI → Push journal: records transfers
- Importer CLI → SQL query stream: pulls or applies SQL
- SQL query stream → SQL URL rewriter: transforms statements
- SQL URL rewriter → Target site: applies database
- Importer CLI → Runtime manifest: builds after preflight
- Runtime manifest → Target runtime appliers: drives
- Target runtime appliers → Target site: generates runtime
- Pull pipeline → Target site: reconstructs files
- Package & PHAR build → Importer CLI: bundles as PHAR
- Migration UI → Importer CLI: supports migration flow
