# Development Guide This guide covers development workflows, coding standards, and best practices for EasyStream development. ## Development Environment Setup ### Local Development with Docker ```bash # Clone the repository git clone cd easystream # Copy environment configuration cp .env.example .env # Start development environment docker-compose up -d --build # Access the application open http://localhost:8083 ``` ### Native PHP Development ```bash # Install PHP 8.2+ with required extensions # - pdo_mysql # - gd # - curl # - mbstring # - xml # - zip # Install Composer dependencies (if any) composer install # Configure database connection cp f_core/config.database.php.example f_core/config.database.php # Edit database settings # Set up web server (Apache/Nginx) # Point document root to project directory ``` ## Project Structure Deep Dive ### Core Framework (`f_core/`) ``` f_core/ ├── config.*.php # Configuration files ├── f_classes/ # Core business logic classes ├── f_functions/ # Utility functions └── f_workers/ # Background workers ``` ### Modules (`f_modules/`) ``` f_modules/ ├── m_frontend/ # User-facing modules ├── m_backend/ # Admin modules └── api/ # API endpoints ``` ### Templates (`f_templates/`) ``` f_templates/ ├── tpl_frontend/ # User interface templates ├── tpl_backend/ # Admin interface templates └── frontend/ # Static frontend assets ``` ### Jobs (`f_jobs/`) ``` f_jobs/ ├── BaseJob.php # Base job class ├── VideoProcessingJob.php ├── NotificationJob.php └── CleanupJob.php ``` ## Coding Standards ### PHP Standards Follow PSR-12 coding standards with EasyStream-specific conventions: ```php assertEquals('test@example.com', $result); } public function testValidateInputInvalid() { $this->expectException(ValidationException::class); VSecurity::validateInput('invalid-email', 'email'); } } ``` ### Integration Testing ```php createTestUser(); $result = VAuth::authenticate($user['username'], 'password'); $this->assertTrue($result); $this->assertTrue(VAuth::isLoggedIn()); } } ``` ### Test Data Management ```php loadFixtures('test_data.sql'); } ``` ## Database Development ### Migration Pattern ```php execute($sql, [$userId])->getRows(); } public function createFeatureData(int $userId, string $data): bool { global $class_database; $sql = "INSERT INTO feature_data (user_id, data) VALUES (?, ?)"; return $class_database->execute($sql, [$userId, $data])->rowCount() > 0; } } ``` ## Frontend Development ### Template Development ```smarty {* f_templates/tpl_frontend/feature.tpl *}

{$feature_title|escape}

{if $user_logged_in}
{csrf_field('feature_form')}
{else}

Please login to use this feature.

{/if}
``` ### JavaScript Development ```javascript // f_templates/frontend/js/feature.js class FeatureManager { constructor() { this.initializeEventListeners(); } initializeEventListeners() { document.addEventListener('DOMContentLoaded', () => { this.setupFeatureForm(); }); } setupFeatureForm() { const form = document.getElementById('feature-form'); if (form) { form.addEventListener('submit', this.handleFormSubmit.bind(this)); } } async handleFormSubmit(event) { event.preventDefault(); const formData = new FormData(event.target); try { const response = await fetch('/api/feature', { method: 'POST', body: formData }); const result = await response.json(); this.handleResponse(result); } catch (error) { console.error('Feature submission failed:', error); } } } // Initialize when DOM is ready new FeatureManager(); ``` ## API Development ### RESTful API Structure ```php getFeature(); case 'POST': return $this->createFeature(); case 'PUT': return $this->updateFeature(); case 'DELETE': return $this->deleteFeature(); default: http_response_code(405); return ['error' => 'Method not allowed']; } } private function getFeature() { $id = get_param('id', 'int'); if (!$id) { http_response_code(400); return ['error' => 'Feature ID required']; } // Implementation return ['feature' => $featureData]; } } // Handle the request $api = new FeatureAPI(); header('Content-Type: application/json'); echo json_encode($api->handleRequest()); ``` ## Background Jobs ### Job Implementation ```php processFeature($featureId); return true; } catch (Exception $e) { $this->logError('Feature processing failed', [ 'error' => $e->getMessage(), 'data' => $data ]); return false; } } private function processFeature(int $featureId): void { // Implementation } } ``` ### Job Queue Management ```php addJob('feature_processing', [ 'feature_id' => $featureId, 'priority' => 'high' ]); // Process jobs (in worker) $worker = new QueueWorker(); $worker->processJobs(); ``` ## Security Development ### Input Validation ```php 'custom', 'pattern' => '/^[A-Z]{2,5}$/', 'required' => true ]); ``` ### CSRF Protection ```php get($cacheKey); if (!$userData) { $userData = $this->loadUserData($userId); $cache->set($cacheKey, $userData, 3600); // 1 hour } ``` ### Template Optimization - Enable Smarty template caching - Minimize template complexity - Use template inheritance - Optimize asset loading ## Debugging and Troubleshooting ### Debug Mode ```php $value, 'context' => $context ]); ``` ### Error Handling ```php performOperation(); } catch (Exception $e) { VLogger::error('Operation failed', [ 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); // Handle gracefully return $this->handleError($e); } ``` ### Log Analysis ```bash # View recent errors tail -f f_data/logs/error_$(date +%Y-%m-%d).log # Search for specific issues grep "CRITICAL" f_data/logs/*.log # Monitor performance grep "SLOW_QUERY" f_data/logs/*.log ``` ## Deployment Preparation ### Pre-deployment Checklist - [ ] All tests passing - [ ] Security review completed - [ ] Performance testing done - [ ] Database migrations ready - [ ] Configuration updated - [ ] Documentation updated ### Production Considerations - Disable debug mode - Configure proper logging levels - Set up monitoring and alerts - Implement backup procedures - Configure SSL/TLS properly ## Code Review Guidelines ### Review Checklist - [ ] Code follows project standards - [ ] Security best practices implemented - [ ] Tests cover new functionality - [ ] Documentation updated - [ ] Performance impact considered - [ ] Error handling implemented - [ ] Logging added where appropriate ### Common Issues to Check - SQL injection vulnerabilities - XSS vulnerabilities - Missing input validation - Improper error handling - Performance bottlenecks - Missing tests - Inadequate logging