Architecture Overview
Visual Diff Merge is built with a modular architecture that separates backend processing from frontend visualization. This separation allows for flexibility in deployment and usage scenarios while maintaining a consistent user experience.
Figure 1: High-level architecture of Visual Diff Merge
The system is composed of three main layers:
- Backend (PHP): Handles file operations, diff generation, and security
- API Layer: Provides endpoints for diff processing, file access, and configuration
- Frontend (JavaScript): Manages UI components, visualization, and user interactions
For implementation details about configuring these components, see the Configuration section of the Installation guide.
System Components
Backend Components
The backend is implemented in PHP and provides core functionality for file operations, diff generation, and security.
| Component | Description | Responsibilities |
|---|---|---|
DiffViewer |
Core diff generation engine |
|
FileBrowser |
File system interaction |
|
Config |
Configuration management |
|
PathManager |
Secure path handling |
|
Security |
Security services |
|
DebugLogger |
Logging functionality |
|
API Layer Components
The API layer consists of several endpoint scripts that handle specific functionality and bridge the frontend with the backend.
| Endpoint | Description | Responsibilities |
|---|---|---|
diff-processor.php |
Primary diff processing endpoint |
|
ajax-diff-merge.php |
Merge operation handler |
|
get-file-content.php |
Secure file content provider |
|
get-url-content.php |
URL content fetcher |
|
endpoint-config.php |
Configuration provider |
|
endpoints-config.php |
API discovery service |
|
Frontend Components
The frontend is built with modular JavaScript components that handle visualization, user interaction, and state management.
| Component | Description | Responsibilities |
|---|---|---|
DiffViewer |
Main viewer component |
|
ChunkManager |
Chunk handling and rendering |
|
MergeHandler |
Merge operations controller |
|
DiffNavigator |
Navigation controls |
|
SyntaxHighlighter |
Code highlighting |
|
ThemeManager |
Theme handling |
|
| Mode-specific Managers | Mode controllers |
|
| Utility Classes | Shared services |
|
Data Flow
The data flow in Visual Diff Merge varies depending on the operation mode, but follows a general pattern:
Figure 2: Data flow across system components
General Data Flow Sequence
- Content Acquisition: Content is obtained from the source (files, URLs, or direct input)
- Content Processing: Content is sent to the API for diff generation
- Diff Calculation: The backend processes the content and generates diff data
- Diff Visualization: The frontend renders the diff data in the viewer
- User Interaction: Users navigate, select chunks, and make merge decisions
- Merge Processing: Selected merge operations are processed by the API (if applicable)
- Result Delivery: Merged content is saved or returned to the user
Mode-Specific Workflows
File Browser Mode
- User → FileBrowserManager: Select files for comparison
- FileBrowserManager → get-file-content.php: Request file content using file references
- get-file-content.php → PathManager: Resolve file paths from references
- PathManager → Security: Validate file access permissions
- get-file-content.php → FileBrowserManager: Return file content
- FileBrowserManager → diff-processor.php: Send content for diff processing
- diff-processor.php → DiffViewer (PHP): Process content and generate diff
- diff-processor.php → FileBrowserManager: Return diff data and configuration
- FileBrowserManager → DiffViewer (JS): Initialize viewer with diff data
- DiffViewer (JS): Render diff visualization and UI components
File Upload Mode
- User → FileUploadManager: Upload files for comparison
- FileUploadManager: Read file content from uploaded files
- FileUploadManager → diff-processor.php: Send content for diff processing
- diff-processor.php → DiffViewer (PHP): Process content and generate diff
- diff-processor.php → FileUploadManager: Return diff data and configuration
- FileUploadManager → DiffViewer (JS): Initialize viewer with diff data
- DiffViewer (JS): Render diff visualization and UI components
Text Compare Mode
- User → TextCompareManager: Input text for comparison
- TextCompareManager → diff-processor.php: Send text content for diff processing
- diff-processor.php → DiffViewer (PHP): Process content and generate diff
- diff-processor.php → TextCompareManager: Return diff data and configuration
- TextCompareManager → DiffViewer (JS): Initialize viewer with diff data
- DiffViewer (JS): Render diff visualization and UI components
URL Compare Mode
- User → UrlCompareManager: Input URLs for comparison
- UrlCompareManager → get-url-content.php: Request URL content for client-side preview (optional)
- UrlCompareManager → diff-processor.php: Send URLs for diff processing
- diff-processor.php: Fetch content from URLs
- diff-processor.php → DiffViewer (PHP): Process content and generate diff
- diff-processor.php → UrlCompareManager: Return diff data and configuration
- UrlCompareManager → DiffViewer (JS): Initialize viewer with diff data
- DiffViewer (JS): Render diff visualization and UI components
Mode-Specific Data Flows
Visual Diff Merge supports four primary modes of operation, each with its own data flow pattern. These diagrams illustrate how data moves through the system in each operational mode.
File Browser Mode
File Browser mode allows users to navigate the server's file system and select files for comparison.
Figure 5: Data flow in File Browser mode
File Upload Mode
File Upload mode enables users to upload files from their local system for comparison.
Figure 6: Data flow in File Upload mode
Text Compare Mode
Text Compare mode allows direct comparison of text snippets entered by users.
Figure 7: Data flow in Text Compare mode
URL Compare Mode
URL Compare mode fetches content from remote URLs for comparison.
Figure 8: Data flow in URL Compare mode
Initialization Sequence
The initialization sequence describes how the application bootstraps itself when a page is loaded. This process includes loading configuration settings, initializing components, and preparing the UI.
Figure 9: Application initialization sequence
During initialization, the following steps occur:
- DOM content load triggers the application bootstrap
- Configuration is loaded from default and user settings
- Theme preferences are applied
- Core components are initialized
- Mode-specific components are loaded based on the current view
- Event listeners are attached to UI elements
- Initial state is established
Configuration Flow
Visual Diff Merge uses a cascading configuration system that merges defaults with user preferences and runtime settings. This ensures flexibility while maintaining consistent behavior.
Figure 10: Configuration resolution flow
The configuration system processes settings in this order of precedence:
- Runtime settings (highest priority)
- URL parameters
- User preferences (stored in localStorage)
- Instance configuration (server-side settings)
- Default configuration (lowest priority)
This hierarchical approach allows for flexible customization while ensuring the application always has valid settings to fall back on.
Extension Points
Visual Diff Merge is designed with extensibility in mind. The application provides several extension points where developers can customize behavior without modifying the core codebase.
Syntax Highlighting
The SyntaxHighlighter component supports custom language definitions and themes beyond the built-in options provided by highlight.js.
Diff Algorithms
The core differencing engine can be extended with custom algorithms by implementing the appropriate interfaces in the DiffViewer component.
Custom Themes
The ThemeManager supports registration of custom themes that can be added to the theme selection options available to users.
Custom File Sources
Beyond the built-in file sources (browser, upload, text, URL), developers can implement custom file sources by extending the appropriate base classes and registering them with the application.
Conclusion
This architectural overview provides a high-level understanding of Visual Diff Merge's design and component structure. For implementation details, refer to the source code and inline documentation. For customization options, see the Customization guide.
Last updated: April 21, 2025