Home
Comments • 3
Up next
⬇ Backend — Strong Feed Backend — Template
Right now Strong Feed is local-only — feed is a hardcoded let videos = [...] in JS, search is doSearch() filtering that array, likes just set likeCount = '1.3K' in the browser, comments are 3 hardcoded rows, subscribe just flips button text, and play is a fake progress bar with setInterval. This backend is the map to make it real: videos + channels live on the server, search / chips / feeds hit the server, likes / subs / comments are stored per-user. Proposed, not connected.
01 / Files to create
api/strong-feed/feed.php GET /api/strong-feed/feed?feed=home&chip=All&q=
api/strong-feed/video.php GET /api/strong-feed/video?id=12
api/strong-feed/upnext.php GET /api/strong-feed/upnext?id=12
api/strong-feed/like.php POST /api/strong-feed/like
api/strong-feed/subscribe.php POST /api/strong-feed/subscribe
api/strong-feed/comment.php GET /api/strong-feed/comment?video_id=
POST /api/strong-feed/comment
sql/strong_feed_tables.sql
Keep the tinyfiles PHP pattern: each endpoint loads /api/bootstrap.php, uses json_in() / json_out(), prepared PDO statements.
02 / Database tables
-- sql/strong_feed_tables.sql
feed_channels
id INT AUTO_INCREMENT PRIMARY KEY
name VARCHAR(120) NOT NULL -- "TinyFiles.tv", "Michael"
handle VARCHAR(80) NOT NULL UNIQUE
avatar_bg VARCHAR(80) NOT NULL -- "linear-gradient(...)" or color
subs_count INT NOT NULL DEFAULT 0
feed_videos
id INT AUTO_INCREMENT PRIMARY KEY
channel_id INT NOT NULL -- FK -> feed_channels.id
title VARCHAR(200) NOT NULL
cat ENUM('tinyfiles','ctalk','ptalk','gaming','music','live',
'sports','news','shorts') NOT NULL
emoji VARCHAR(20) NOT NULL
bg VARCHAR(120) NOT NULL -- gradient for thumb
duration VARCHAR(20) NOT NULL -- "12:34", "LIVE", "0:59"
views_count INT NOT NULL DEFAULT 0
description TEXT NOT NULL
is_live TINYINT(1) NOT NULL DEFAULT 0
created_at DATETIME NOT NULL
feed_subscriptions
id INT AUTO_INCREMENT PRIMARY KEY
user_id INT NOT NULL
channel_id INT NOT NULL
created_at DATETIME NOT NULL
UNIQUE(user_id, channel_id)
feed_likes
id INT AUTO_INCREMENT PRIMARY KEY
user_id INT NOT NULL
video_id INT NOT NULL
kind ENUM('like','dislike') NOT NULL
created_at DATETIME NOT NULL
UNIQUE(user_id, video_id)
feed_comments
id INT AUTO_INCREMENT PRIMARY KEY
video_id INT NOT NULL
user_id INT NOT NULL
body TEXT NOT NULL
created_at DATETIME NOT NULL
feed_history
id BIGINT AUTO_INCREMENT PRIMARY KEY
user_id INT NOT NULL
video_id INT NOT NULL
watched_at DATETIME NOT NULL
Counts are never stored as the source of truth — likes = COUNT(feed_likes WHERE kind='like'), subs = COUNT(feed_subscriptions), views increments on real watch, not on card render.
03 / API endpoints & request flow
GET /api/strong-feed/feed?feed=home&chip=All&q=
- returns { "ok": true, "videos": [ { id, title, channel, cat,
emoji, bg, views, time, dur, subs, desc }, ... ] }
- feed in [home, shorts, subs, history, playlists, watchlater,
liked, gaming, music, live, tinyfiles, ctalk, ptalk, sports, news]
- chip in [All, Gaming, Music, Live, TinyFiles, C-Talk, P-Talk, Sports, News]
- q = search string, matches title + channel, max 50, newest first
- subs / history / liked / watchlater require auth, else 401
GET /api/strong-feed/video?id=12
- returns { "ok": true, "video": {...}, "liked": true/false,
"subscribed": true/false, "like_count": 1240 }
- also INSERTs a feed_history row if authed
GET /api/strong-feed/upnext?id=12
- returns { "ok": true, "videos": [...] } — same cat first, then newest, excl. id
POST /api/strong-feed/like
{ "video_id": 12, "kind": "like" }
- auth required, INSERT ... ON DUPLICATE KEY UPDATE kind
- returns { "ok": true, "like_count": 1241 }
POST /api/strong-feed/subscribe
{ "channel_id": 3 }
- auth required, toggles row — INSERT if missing, DELETE if present
- returns { "ok": true, "subscribed": true, "subs_count": 48201 }
GET /api/strong-feed/comment?video_id=12
- returns { "ok": true, "comments": [ { author, body, created_at }, ... ] }
POST /api/strong-feed/comment
{ "video_id": 12, "body": "..." }
- auth required, body 1-1000 chars, plain text
Feed / watch / up-next all read from the same feed_videos table — no second source of truth. The chips + sidebar feeds are just filters on that one endpoint.
04 / C-Talk / P-Talk, moderation & validation (server owns this)
// Trust model — this page already says it, backend must keep it: // C-Talk = server can't see. P-Talk = server sees. // C-Talk videos / comments stay in encrypted buckets (see C-Mail / // daily-game Slot 2 pattern). Server stores ciphertext only. // P-Talk videos / comments are plaintext so server can search, // moderate, and keep history. Never mix the two. // Moderation: // comments are plain text — escape on render, never store HTML // P-Talk comments can be moderated (delete / hide). C-Talk cannot // be moderated by server by design — client-side block only. // Validation: // q: 1-100 chars, trimmed. body: 1-1000 chars, no URLs required. // like / subscribe: video_id / channel_id must exist, else 404. // rate-limit: max 30 likes / 20 comments per user per hour.
Keep the sidebar line: “C-Talk = 🔐 server can’t see · P-Talk = 👁 server sees · Strong Feed = videos, mostly.” The backend enforces which side a video / comment lives on.
05 / Frontend wiring
// Replace the hardcoded let videos = [...] in this page:
let videos = []; // filled from server, same shape as now
async function loadFeed(){
const url = '/api/strong-feed/feed?feed=' + currentFeed
+ '&chip=' + encodeURIComponent(currentChip)
+ '&q=' + encodeURIComponent(searchQ);
const res = await fetch(url);
const data = await res.json();
// data.videos -> renderGrid(), same .card HTML as now
// feedCount = data.videos.length + ' videos'
}
// Replace openVideo(id):
async function openVideo(id){
const res = await fetch('/api/strong-feed/video?id=' + id);
const data = await res.json();
// data.video -> wTitle / wChannel / wSubs / wDesc, same UI as now
// data.liked -> like button state, data.subscribed -> Subscribe button
// const up = await fetch('/api/strong-feed/upnext?id=' + id)...
// const cm = await fetch('/api/strong-feed/comment?video_id=' + id)...
}
// Replace like(btn):
async function like(btn){
const res = await fetch('/api/strong-feed/like', { method:'POST',
headers:{'Content-Type':'application/json'},
body: JSON.stringify({ video_id: currentVideo.id, kind: 'like' }) });
// update #likeCount from response, same UI as now
}
// Replace Subscribe button:
// POST /api/strong-feed/subscribe { channel_id }, toggle from response
// Replace setFeed / setChip / doSearch / filterChannel:
// setFeed / setChip / doSearch -> loadFeed(), keep active-pill logic
// filterChannel(ch) -> searchQ = ch, loadFeed()
// On load: loadFeed()
// If API fails, fall back to current hardcoded videos + 3 comments.
Keep the current hardcoded videos + fake player playable with no backend — if /api/strong-feed/feed fails, use the in-page list as the fallback.
api/strong-feed/ + sql/strong_feed_tables.sql — no GitHub needed. The <pre> blocks are the backend spec: server-owned videos + per-user likes / subs / comments + C-Talk vs P-Talk trust split, same layout, placeholders stay until wired.