# LiveComponents Documentation **Production-Ready Interactive Components for Custom PHP Framework** LiveComponents is a modern, secure, and performant system for building interactive web applications with minimal JavaScript. It combines server-side rendering with client-side interactivity, providing a reactive programming model similar to frameworks like Livewire or Phoenix LiveView. ## Features at a Glance ✅ **Zero-Config Reactivity** - Automatic state synchronization between server and client ✅ **Fragment-based Rendering** - Update only changed parts of the DOM ✅ **Optimistic UI** - Instant feedback with automatic rollback on errors ✅ **Request Batching** - Automatic batching for improved network efficiency ✅ **Chunked Uploads** - Large file uploads with progress tracking ✅ **Real-time Updates** - Server-Sent Events (SSE) for live data ✅ **Security First** - CSRF protection, rate limiting, idempotency keys ✅ **Production-Ready** - Comprehensive error handling and recovery ✅ **Developer Experience** - DevTools overlay with performance profiling ## Quick Start ### 1. Basic Component ```php count++; } #[LiveAction] public function decrement(): void { $this->count--; } public function render(): string { return $this->view('components/counter', [ 'count' => $this->count ]); } } ``` ### 2. Template (components/counter.view.php) ```html

Counter: {count}

``` ### 3. Usage in Controller ```php LiveComponent::mount(Counter::class) ]); } } ``` ### 4. Include in View ```html

Welcome

{counterComponent}
``` That's it! The counter is now fully interactive with zero JavaScript written. ## Documentation Structure ### Getting Started - [Installation & Setup](01-getting-started.md) - Initial setup and configuration - [Your First Component](02-first-component.md) - Step-by-step tutorial - [Core Concepts](03-core-concepts.md) - Understanding LiveComponents architecture ### Guides - [Security Guide](security-guide.md) - CSRF, rate limiting, input validation - [Performance Guide](performance-guide.md) - Optimization strategies and best practices - [Advanced Features](advanced-features.md) - Fragments, batching, SSE, optimistic UI ### Reference - [API Reference](api-reference.md) - Complete API documentation - [Attributes Reference](attributes-reference.md) - All available attributes - [Events Reference](events-reference.md) - Client-side events and lifecycle ### Best Practices - [Component Design](best-practices/component-design.md) - Structuring components - [State Management](best-practices/state-management.md) - Managing component state - [Testing Components](best-practices/testing.md) - Unit and E2E testing ### Troubleshooting - [Common Issues](troubleshooting.md) - Solutions to common problems - [Debugging Guide](debugging-guide.md) - Tools and techniques - [FAQ](faq.md) - Frequently asked questions ## Key Concepts ### Server-Side Components Components are PHP classes that live on the server. State changes trigger re-renders, and only the changed HTML is sent to the client. ### Reactive Properties Properties marked with `#[LiveProp]` are automatically synchronized between server and client: ```php #[LiveProp] public string $searchTerm = ''; #[LiveProp] public array $filters = []; ``` ### Actions Methods marked with `#[LiveAction]` can be triggered from the client: ```php #[LiveAction] public function search(): void { $this->results = $this->searchService->search($this->searchTerm); } ``` ### Fragment Rendering Update specific parts of your component without re-rendering everything: ```html
{result.title}
``` ### Optimistic UI Provide instant feedback while waiting for server confirmation: ```html ``` ### Real-time Updates Keep components in sync with server-side events: ```php final class Dashboard extends LiveComponent { #[LiveProp] public int $activeUsers = 0; public function mount(): void { $this->enableSse(); // Enable real-time updates } } ``` ## Architecture Overview ``` ┌─────────────────────────────────────────────────────────────┐ │ Client (Browser) │ ├─────────────────────────────────────────────────────────────┤ │ LiveComponent.js │ DevTools │ DomPatcher │ SSE Client│ └─────────────────────────────────────────────────────────────┘ │ HTTP/SSE │ ┌─────────────────────────────────────────────────────────────┐ │ Server (PHP Framework) │ ├─────────────────────────────────────────────────────────────┤ │ Component Classes │ State Manager │ Fragment Renderer │ │ Action Dispatcher │ Security Layer │ SSE Update Service │ └─────────────────────────────────────────────────────────────┘ ``` ## Performance Characteristics - **Initial Render**: Server-side, SEO-friendly HTML - **Action Latency**: <100ms for simple actions - **Network Efficiency**: 80%+ reduction via request batching - **UI Responsiveness**: <50ms with optimistic updates - **Memory Usage**: ~2MB per component in browser - **Scalability**: 1000+ concurrent components per page ## Browser Support - **Chrome/Edge**: 90+ - **Firefox**: 88+ - **Safari**: 14+ - **Mobile Safari**: 14+ - **Mobile Chrome**: 90+ **Required Features**: - ES2020 JavaScript - Fetch API - EventSource (SSE) - MutationObserver - Custom Elements (for future enhancements) ## Production Checklist - [ ] Enable CSRF protection (automatic) - [ ] Configure rate limiting per component - [ ] Set up idempotency keys for critical actions - [ ] Enable fragment rendering for large components - [ ] Configure request batching thresholds - [ ] Set up SSE for real-time features - [ ] Test error recovery scenarios - [ ] Enable production error logging - [ ] Configure CDN for static assets - [ ] Set up monitoring for component performance ## License This documentation is part of the Custom PHP Framework project. ## Support - **Issues**: GitHub Issues - **Discussions**: GitHub Discussions - **Security**: security@example.com --- **Ready to build?** Start with [Installation & Setup](01-getting-started.md) →