feat: Add comprehensive documentation suite and reorganize project structure

- Created complete documentation in docs/ directory
- Added PROJECT_OVERVIEW.md with feature highlights and getting started guide
- Added ARCHITECTURE.md with system design and technical details
- Added SECURITY.md with comprehensive security implementation guide
- Added DEVELOPMENT.md with development workflows and best practices
- Added DEPLOYMENT.md with production deployment instructions
- Added API.md with complete REST API documentation
- Added CONTRIBUTING.md with contribution guidelines
- Added CHANGELOG.md with version history and migration notes
- Reorganized all documentation files into docs/ directory for better organization
- Updated README.md with proper documentation links and quick navigation
- Enhanced project structure with professional documentation standards
This commit is contained in:
SamiAhmed7777
2025-10-21 00:39:45 -07:00
commit 0b7e2d0a5b
6080 changed files with 1332936 additions and 0 deletions

94
f_modules/api/index.php Normal file
View File

@@ -0,0 +1,94 @@
<?php
/*******************************************************************************************************************
| EasyStream API Endpoint
| RESTful API for EasyStream application
|*******************************************************************************************************************/
define('_ISVALID', true);
// Load core system
$main_dir = realpath(dirname(__FILE__) . '/../../');
set_include_path($main_dir);
if (!file_exists('f_core/config.core.php')) {
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
echo json_encode(['error' => 'Core system not found']);
exit;
}
include_once 'f_core/config.core.php';
// Set JSON response headers
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
// Handle preflight requests
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit;
}
// Get endpoint from query string
$endpoint = isset($_GET['endpoint']) ? $_GET['endpoint'] : '';
$method = $_SERVER['REQUEST_METHOD'];
// Basic API routing
switch ($endpoint) {
case 'status':
echo json_encode([
'status' => 'online',
'version' => '1.0.0',
'timestamp' => date('c'),
'container' => gethostname()
]);
break;
case 'health':
// Redirect to health check
include_once '../../health_check.php';
break;
case 'videos':
case 'users':
case 'live':
case 'search':
case 'analytics':
// Redirect to v1 API
$api = new VAPI();
$data = [];
if ($method === 'GET') {
$data = $_GET;
} else {
$input = file_get_contents('php://input');
if ($input) {
$data = json_decode($input, true) ?: [];
}
$data = array_merge($data, $_POST);
}
$headers = getallheaders() ?: [];
$response = $api->handleRequest($method, $endpoint, $data, $headers);
http_response_code($response['status']);
echo json_encode($response);
break;
default:
http_response_code(404);
echo json_encode([
'error' => 'API endpoint not found',
'endpoint' => $endpoint,
'available_endpoints' => [
'status',
'health',
'videos',
'users'
]
]);
break;
}
?>

View File

@@ -0,0 +1,129 @@
<?php
/*******************************************************************************************************************
| SRS Webhook Handler
| Handles callbacks from SRS server for live streaming events
|*******************************************************************************************************************/
define('_ISVALID', true);
require_once '../../f_core/config.core.php';
// Set JSON response headers
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
// Handle preflight requests
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit;
}
try {
$liveStreaming = new VLiveStreaming();
$logger = VLogger::getInstance();
// Get request data
$input = file_get_contents('php://input');
$data = json_decode($input, true);
if (!$data) {
throw new Exception('Invalid JSON data');
}
// Determine action from URL path
$path = $_SERVER['REQUEST_URI'] ?? '';
$action = '';
// Parse SRS webhook action
if (isset($data['action'])) {
$action = $data['action'];
} elseif (strpos($path, 'on_connect') !== false) {
$action = 'on_connect';
} elseif (strpos($path, 'on_close') !== false) {
$action = 'on_close';
} elseif (strpos($path, 'on_publish') !== false) {
$action = 'on_publish';
} elseif (strpos($path, 'on_unpublish') !== false) {
$action = 'on_unpublish';
} elseif (strpos($path, 'on_play') !== false) {
$action = 'on_play';
} elseif (strpos($path, 'on_stop') !== false) {
$action = 'on_stop';
} elseif (strpos($path, 'on_dvr') !== false) {
$action = 'on_dvr';
} elseif (strpos($path, 'on_hls') !== false) {
$action = 'on_hls';
} elseif (strpos($path, 'heartbeat') !== false) {
$action = 'heartbeat';
}
$logger->info('SRS webhook received', [
'action' => $action,
'data' => $data,
'path' => $path
]);
// Handle heartbeat separately
if ($action === 'heartbeat') {
// Update SRS server status
updateSRSStatus($data);
echo json_encode(['code' => 0, 'message' => 'heartbeat received']);
exit;
}
// Handle stream webhooks
$response = $liveStreaming->handleSRSWebhook($action, $data);
echo json_encode($response);
} catch (Exception $e) {
$logger->error('SRS webhook error', [
'error' => $e->getMessage(),
'input' => $input ?? '',
'path' => $_SERVER['REQUEST_URI'] ?? ''
]);
// Return error response
echo json_encode([
'code' => 1,
'message' => $e->getMessage()
]);
}
/**
* Update SRS server status
* @param array $data Heartbeat data
*/
function updateSRSStatus($data)
{
try {
$db = VDatabase::getInstance();
$statusData = [
'server_id' => $data['device_id'] ?? 'srs-server',
'status' => 'online',
'last_heartbeat' => date('Y-m-d H:i:s'),
'data' => json_encode($data),
'updated_at' => date('Y-m-d H:i:s')
];
// Insert or update server status
$existing = $db->doQuery("SELECT id FROM db_srs_servers WHERE server_id = ?", [$statusData['server_id']]);
if ($db->doFetch($existing)) {
$db->doUpdate('db_srs_servers', 'server_id', $statusData, $statusData['server_id']);
} else {
$statusData['created_at'] = date('Y-m-d H:i:s');
$db->doInsert('db_srs_servers', $statusData);
}
} catch (Exception $e) {
VLogger::getInstance()->error('Failed to update SRS status', [
'error' => $e->getMessage(),
'data' => $data
]);
}
}
?>

View File

@@ -0,0 +1,76 @@
<?php
/*******************************************************************************************************************
| EasyStream REST API v1
| Main API endpoint handler for mobile apps and third-party integration
|*******************************************************************************************************************/
define('_ISVALID', true);
require_once '../../../f_core/config.core.php';
// Set JSON response headers
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
try {
$api = new VAPI();
// Get request method and endpoint
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
// Parse endpoint from URI
$basePath = '/api/v1/';
$endpoint = '';
if (strpos($requestUri, $basePath) !== false) {
$endpoint = substr($requestUri, strpos($requestUri, $basePath) + strlen($basePath));
$endpoint = strtok($endpoint, '?'); // Remove query parameters
}
// Get request data
$data = [];
if ($method === 'GET') {
$data = $_GET;
} else {
$input = file_get_contents('php://input');
if ($input) {
$data = json_decode($input, true) ?: [];
}
// Merge with POST data if available
$data = array_merge($data, $_POST);
}
// Get request headers
$headers = getallheaders() ?: [];
// Handle API request
$response = $api->handleRequest($method, $endpoint, $data, $headers);
// Set HTTP status code
http_response_code($response['status']);
// Return JSON response
echo json_encode($response);
} catch (Exception $e) {
// Log error
$logger = VLogger::getInstance();
$logger->error('API error', [
'error' => $e->getMessage(),
'method' => $_SERVER['REQUEST_METHOD'] ?? '',
'uri' => $_SERVER['REQUEST_URI'] ?? '',
'trace' => $e->getTraceAsString()
]);
// Return error response
http_response_code(500);
echo json_encode([
'status' => 500,
'data' => ['error' => 'Internal server error'],
'timestamp' => time(),
'version' => 'v1'
]);
}
?>