Bonus Features

bonus · optional
Story 24h · Group / Community · Live Stream  ·  Tất cả chưa implement — tài liệu đề xuất kiến trúc

📸 Story 24h bonus

Story tạm thời hiển thị 24 giờ rồi tự ẩn, giống Instagram/Facebook Stories. Hỗ trợ ảnh, video ngắn, text overlay.

Proposed: Story Flow


POST /stories — Upload story INSERT Story userId, mediaUrl, type, expiresAt = now()+24h GET /stories/feed — Lấy stories WHERE expiresAt > now() AND userId IN (followingIds) GROUP BY userId → ring avatars trên đầu feed ⏰ Cron: cleanup expired stories mỗi 1h: soft delete WHERE expiresAt < now()
#TaskChi tiếtStatus
01
Prisma: model Story
Story { id, userId, mediaUrl, mediaType (IMAGE/VIDEO), text, expiresAt, viewCount, createdAt }. Index on (userId, expiresAt).todo
02
Prisma: model StoryView
StoryView { id, storyId, viewerId, viewedAt }. Unique (storyId, viewerId) — mỗi user chỉ count 1 view.todo
03
POST /stories
Upload media trước (reuse Upload module) → tạo Story với expiresAt = now() + 24h.todo
04
GET /stories/feed
Lấy stories từ following users. Group by user. Sort: chưa xem trước, mới nhất trước. Bao gồm isViewed boolean.todo
05
POST /stories/:id/view
Record view: INSERT StoryView (upsert, idempotent). Increment viewCount. Trả danh sách viewers cho chủ story.todo
06
Cron: cleanup expired
BullMQ repeatable job mỗi 1h. Soft delete stories quá 24h. Sau 30 ngày hard delete + xóa media từ S3.todo

👥 Group / Community bonus

Nhóm chung sở thích. Thành viên có thể đăng bài, thảo luận trong nhóm. Admin nhóm quản lý thành viên và nội dung.

Proposed: Schema & API


Circle
Dự án đã có model Circle, CircleMember, CircleInvitation trong Prisma. Có thể mở rộng thành Group/Community.
Mở rộng
Thêm fields: description, coverImage, isPublic, memberCount. Thêm GroupPost (bài viết trong group).
API
POST /groups — tạo group
GET /groups/:id — chi tiết group
POST /groups/:id/join — tham gia
POST /groups/:id/posts — đăng bài trong group
GET /groups/:id/feed — feed group
GET /groups/discover — gợi ý group
Permission
3 role: OWNER (tạo nhóm), ADMIN (quản lý), MEMBER (đăng bài). Enum RoleMembership đã có trong Prisma.
#TaskChi tiếtStatus
01
Mở rộng Circle → Group
Thêm description, coverImage, isPublic, category. Migration Prisma. Reuse CircleMember, CircleInvitation.todo
02
Group Post
Bài viết gắn groupId. Hiển thị trong group feed. Visibility mặc định = GROUP (chỉ member thấy).todo
03
Group moderation
Admin group có thể: xóa bài, kick member, approve join request (nếu private group).todo
04
Discover groups
Gợi ý group phổ biến, hoặc dựa trên topics user quan tâm (link với AI Recommendation).todo

🔴 Live Stream bonus

Phát sóng trực tiếp video. Viewer có thể comment realtime, gửi reaction. Tự động lưu replay sau khi kết thúc.

Proposed: Live Stream Architecture


Broadcaster RTMP push HLS Live Streaming RTMP ingest → HLS transcode Auto-generate playback URL HLS Playback Viewers xem 👥 FE video.js Pusher: live-chat-{streamId} Comment + Reaction realtime overlay API Server start/stop stream, viewer count

Dùng HLS Live (đã có integration). Broadcaster push RTMP → HLS transcode → HLS playback. Chat overlay qua Pusher. Replay tự động lưu.

HLS
Dự án đã tích hợp HLS cho video upload. HLS Live Streaming thêm ~$0.025/phút stream. Tự động tạo replay asset khi stream kết thúc.
Webhook
Reuse HLSWebhookFlow đã có. Thêm event types: video.live_stream.active, video.live_stream.idle, video.asset.live_stream_completed.
Scale
1000 viewers = 1000 Pusher connections cho chat. Nếu cần scale hơn → dùng Pusher batch events hoặc poll API thay vì subscribe all.
Complexity
Live stream là feature phức tạp nhất. Khuyến nghị: chỉ làm nếu đã hoàn thành tất cả core features. Ưu tiên Story > Group > Live.