<?php
// Set response type to standard JSON format
header('Content-Type: application/json');

try {
    // Reference standard shared zero-dependency storage system
    $db = new PDO('sqlite:app_feed.db');
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Table initialization guarantee sequence
    $db->exec("CREATE TABLE IF NOT EXISTS application_comments (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        name TEXT,
        flag TEXT,
        tier TEXT,
        txt TEXT,
        created_at DATETIME DEFAULT CURRENT_TIMESTAMP
    )");

    // Pull last 30 entries sequentially to keep UI rendering agile
    $query = $db->query("SELECT name, flag, tier, txt FROM application_comments ORDER BY id ASC LIMIT 30");
    $comments = $query->fetchAll(PDO::FETCH_ASSOC);

    // Stream arrays cleanly into application view framework pipelines
    echo json_encode($comments);

} catch (PDOException $e) {
    // Fault isolation structure yielding empty array on pristine boot environments
    echo json_encode([]);
}
?>