Skip to content

PHP + Rust-Tauri → tiny signed desktop binaries. No 100 MB Electron runtime; uses the OS webview (WebView2 / WKWebView / WebKitGTK).

License

Notifications You must be signed in to change notification settings

makalin/php-tauri

Repository files navigation

php-tauri

PHP + Rust-Tauri → tiny signed desktop binaries No 100 MB Electron runtime; uses the OS webview (WebView2 / WKWebView / WebKitGTK).

License: MIT PHP Version Tauri Node.js


Why?

  • Small: ship PHP + app in ~15–30 MB, not 100s.
  • Fast: native window, hardware-accelerated webview.
  • Signed: platform-native code signing & notarization.
  • Portable: single EXE/AppImage/.app bundle.
  • Secure: no open localhost port required.
  • Modern: Beautiful UI with glassmorphism design.
  • Tested: Comprehensive test suite with PHPUnit, Vitest, and Playwright.

What is this?

A complete starter kit + patterns to build desktop apps where UI = HTML/CSS/JS, logic = PHP, and shell/native glue = Rust (Tauri).

This project includes:

  1. IPC Mode (implemented) Call PHP scripts from Rust via tauri::command, capture output (JSON/HTML), and render in the webview.

  2. Modern Frontend Beautiful, responsive interface with calculator, file manager, and API testing tools.

  3. Comprehensive Backend PHP API endpoints with proper error handling, validation, and security.

  4. Full Test Suite Unit tests, integration tests, and end-to-end tests.

  5. Production Ready Build scripts, documentation, and deployment guides.


Quick Start

# 1) Clone the repository
git clone <repository-url>
cd php-tauri

# 2) Install dependencies
make install
# or manually:
# npm install && composer install

# 3) Start development server
make dev
# or: npm run tauri:dev

# 4) Run tests
make test
# or: npm test

# 5) Build for production
make build
# or: npm run tauri:build

Project Structure

php-tauri/
├── dist/                    # Frontend build output
│   ├── index.html           # Main HTML page
│   ├── styles.css           # Modern CSS styling
│   └── main.js              # JavaScript application
├── php/                     # PHP backend
│   ├── index.php            # Main PHP page
│   ├── api/                 # API endpoints
│   │   ├── hello.php        # Hello API
│   │   ├── calculator.php   # Calculator API
│   │   └── files.php        # File operations API
│   └── src/                 # PHP classes
│       ├── App.php          # Main app class
│       ├── Calculator.php   # Calculator class
│       └── FileManager.php  # File manager class
├── src-tauri/              # Rust Tauri application
│   ├── src/
│   │   └── main.rs         # Main Rust code
│   ├── Cargo.toml          # Rust dependencies
│   ├── tauri.conf.json     # Tauri configuration
│   └── bin/php/            # PHP runtime (for bundling)
├── tests/                  # Test suites
│   ├── php/                # PHP unit tests
│   ├── frontend/           # Frontend unit tests
│   └── e2e/                # End-to-end tests
└── docs/                   # Documentation
    ├── DEVELOPMENT.md      # Development guide
    ├── BUILD.md           # Build guide
    └── API.md             # API documentation

Features

🎨 Modern Frontend

  • Beautiful UI: Glassmorphism design with gradients and animations
  • Responsive: Works on desktop, tablet, and mobile
  • Interactive: Real-time calculator and file manager
  • API Testing: Built-in tools for testing PHP endpoints

🔧 PHP Backend

  • RESTful APIs: JSON-based communication
  • Calculator: Mathematical operations (add, subtract, multiply, divide, power, sqrt)
  • File Manager: List, read, write, delete files and directories
  • Hello API: Testing communication between frontend and backend
  • Security: Input validation and path traversal protection

🦀 Rust Integration

  • IPC Communication: Seamless frontend ↔ PHP communication
  • Native Performance: Hardware-accelerated webview
  • Cross-Platform: Windows, macOS, and Linux support
  • Small Size: ~15-30 MB total application size

🧪 Testing

  • Unit Tests: PHP classes and frontend functions
  • Integration Tests: API endpoint testing
  • E2E Tests: Full application workflow testing
  • Coverage: Code coverage reporting

API Examples

Hello API

const result = await invoke('php_call', {
  script: 'api/hello.php',
  payload: { name: 'World' }
});
// Returns: { ok: true, message: "Hello, World from PHP!", ... }

Calculator API

const result = await invoke('php_call', {
  script: 'api/calculator.php',
  payload: { operation: 'add', a: 5, b: 3 }
});
// Returns: { ok: true, result: 8, ... }

File Manager API

// List files
const files = await invoke('php_call', {
  script: 'api/files.php',
  payload: { action: 'list', path: '.' }
});

// Read file
const content = await invoke('php_call', {
  script: 'api/files.php',
  payload: { action: 'read', path: 'test.txt' }
});

Development Commands

# Development
make dev              # Start development server
make install          # Install all dependencies
make setup            # Setup development environment

# Testing
make test             # Run all tests
make test-php         # Run PHP tests only
make test-frontend    # Run frontend tests only
make test-e2e         # Run end-to-end tests

# Building
make build            # Build for production
make build-windows    # Build for Windows
make build-macos      # Build for macOS
make build-linux      # Build for Linux

# Code Quality
make lint             # Run linters
make format           # Format code
make lint-fix         # Fix linting issues

# Maintenance
make clean            # Clean build artifacts
make clean-all        # Clean everything
make status           # Show project status

Prerequisites

  • Node.js (v18 or higher)
  • PHP (v8.1 or higher)
  • Rust (latest stable)
  • Tauri CLI (npm install -g @tauri-apps/cli)

Platform-Specific Requirements

Windows

  • Visual Studio Build Tools or Visual Studio Community
  • Windows SDK
  • WebView2 Runtime (usually pre-installed)

macOS

  • Xcode Command Line Tools (xcode-select --install)
  • macOS SDK

Linux

  • WebKit2GTK development packages
  • GTK3 development packages
  • libssl development packages

Configuration

Environment Variables

Copy env.example to .env and customize:

# App Configuration
APP_NAME=php-tauri
APP_VERSION=0.1.0
APP_DEBUG=true

# PHP Configuration
PHP_BIN=php
PHP_MEMORY_LIMIT=128M

# Tauri Configuration
TAURI_DEBUG=true
TAURI_DEV_SERVER_URL=http://localhost:1420

Tauri Configuration

The src-tauri/tauri.conf.json includes:

  • Bundle configuration for all platforms
  • Security policies
  • Window settings
  • Resource bundling

Testing

PHP Tests

# Run all PHP tests
composer test

# Run with coverage
composer test-coverage

# Run specific test
php tests/php/run_tests.php

Frontend Tests

# Run unit tests
npm run test:frontend

# Run with watch mode
npx vitest watch

End-to-End Tests

# Run E2E tests
npm run test:e2e

# Run with UI
npm run test:e2e:ui

Building & Distribution

Development Build

npm run tauri:dev

Production Build

npm run tauri:build

Platform-Specific Builds

# Windows
TAURI_PLATFORM=windows npm run tauri:build

# macOS
TAURI_PLATFORM=macos npm run tauri:build

# Linux
TAURI_PLATFORM=linux npm run tauri:build

Documentation


Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite (make test)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

FAQ

Q: Why not use Electron? A: Tauri provides smaller bundle sizes (~15-30 MB vs 100+ MB), better performance, and native security.

Q: Can I use Composer packages? A: Yes! Install packages in php/vendor and they'll be bundled with the application.

Q: How do I add new API endpoints? A: Create a new PHP file in php/api/ following the JSON input/output pattern, then call it from the frontend using invoke('php_call', ...).

Q: Can I customize the UI? A: Absolutely! The frontend is in dist/ with modern CSS. You can use any CSS framework or build tool.

Q: How do I add native functionality? A: Add Rust commands in src-tauri/src/main.rs and call them from the frontend using invoke().


Roadmap

  • SQLite integration example
  • Auto-updater implementation
  • Custom scheme mode template
  • Docker development environment
  • CI/CD pipeline examples
  • More API endpoint examples
  • Theme system
  • Plugin architecture

License

This project is licensed under the MIT License - see the LICENSE file for details.


Credits

  • Tauri for the native wrapper framework
  • PHP for the powerful backend runtime
  • Vite for the fast build tooling
  • Playwright for the excellent testing framework
  • All contributors for making this project better

Tagline "Ship PHP like it's 2025: tiny, native, signed, and beautiful."

About

PHP + Rust-Tauri → tiny signed desktop binaries. No 100 MB Electron runtime; uses the OS webview (WebView2 / WKWebView / WebKitGTK).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published