video-streaming-ledger

byMorphy Morxel

You are a Principal Full-Stack Software Engineer and Systems Architect. I want you to build a complete, production-ready global video streaming platform (Netflix-style) with an integrated financial ledger, micro-transactional wallet system, creator payout dashboard, and administrative control center. Here are the exact technical, economic, and architectural specifications you must implement: --- ### 1. Database Architecture & Ledger (PostgreSQL) Build an immutable, double-entry financial ledger in PostgreSQL using raw SQL or Prisma/Sequelize. - **Users Table:** Stores user accounts with roles ('streamer', 'creator', 'admin'). - **Wallets Table:** Tracks live user balances (`balance_usd`, numeric precision 12,4). - **Ledger Transactions Table:** Immutable, append-only transaction log with unique idempotency keys to prevent double-spending or race conditions. All balance changes must write to this ledger. - **ACID Transactions:** Use explicit row locking (`SELECT ... FOR UPDATE`) inside database transactions for all wallet deductions and credits. --- ### 2. Business Logic & Monetization Rules - **User Funding:** Users fund their wallets via payment gateways (Stripe/Paystack webhook integrations supporting $3.00 minimum top-ups with tiered AOV bundles). - **Per-Stream Charges:** - Full Movie / Series: **₦60 (~$0.040 USD)**. - Season Episode: **₦30 (~$0.020 USD)**. - **The 70% Watch Milestone Payout:** - The frontend video player must securely track watch time (handling seeks/scrubs). - When a user reaches $\ge 70\%$ watch completion of a video session, the client sends a cryptographically signed heartbeat telemetry packet to the backend. - The backend validates the telemetry, deducts the fee from the streamer's wallet, and credits the creator's wallet (minus platform commissions). - **Platform Fee Split (Withdrawals):** - Creators can request withdrawals from their balance. - The platform automatically deducts a **40% platform commission** upon withdrawal, routing the 40% cut to the platform wallet and dispatching the remaining 60% net payout via Stripe Connect / Paystack / payout APIs. --- ### 3. Backend API (Node.js / Express) Implement the following secure REST endpoints: 1. `POST /v1/auth/login` - JWT-based authentication. 2. `POST /v1/billing/create-intent` & Webhook Handlers (`/webhook/stripe`, `/webhook/paystack`) - Handles card/mobile money top-ups and securely credits user wallets idempotently. 3. `POST /v1/telemetry/heartbeat` - Validates playback time-deltas and triggers the atomic 70% milestone payout. 4. `GET /v1/creator/metrics` - Returns real-time creator earnings, view counts, and recent $0.022/$0.040 micro-payout activity feed. 5. `POST /v1/creator/withdraw` - Calculates the 40% fee split and logs ledger entries. 6. `GET /v1/admin/analytics` - Computes total system volume, deposits, creator payouts, and total **40% platform commission revenue** collected. --- ### 4. Frontend Application (React / Next.js + Tailwind CSS) Build a sleek, dark-themed Netflix-style UI with the following views: 1. **Streaming Player View (`VideoPlayer.jsx`):** Integrates HLS.js for adaptive bitrate streaming, displays a live navbar wallet balance, and automatically fires secure telemetry heartbeats. 2. **Creator Studio Dashboard (`CreatorDashboard.jsx`):** Displays real-time earnings cards, total views, live transaction feeds, and a **Withdrawal Modal** that calculates the 40% platform fee split live before submitting. 3. **Admin Control Center (`AdminDashboard.jsx`):** Displays executive financial KPIs (Total Deposits, Gross Volume, 40% Platform Revenue, Active User Balance Float) and a real-time ledger auditing table. --- ### 5. Deployment & Containerization - Provide a `docker-compose.yml` file spinning up PostgreSQL and the Node.js backend container. - Ensure all code is clean, modular, heavily commented, secure against race conditions and bot manipulation, and ready for production deployment. Build the complete application now, starting with the database schema and backend server.

Landing
Landing

Comments (0)

No comments yet. Be the first!

Live
Landing design preview
Landing: Read platform settlement explanation
Sign Up: 1. Choose admin role and enroll
Sign Up: 2. Correct inline validation error
Login: 1. Submit credentials
Login: 2. Retry after invalid credentials
Admin Control Center: 1. Review executive financial KPIs
Admin Control Center: 2. Retry failed analytics fetch
Admin Control Center: Audit real-time ledger table
Admin Control Center: Inspect individual ledger rows
Admin Control Center: Identify marked commission entries
Live
Landing design preview
Landing: Read platform settlement explanation
Sign Up: 1. Choose admin role and enroll
Sign Up: 2. Correct inline validation error
Login: 1. Submit credentials
Login: 2. Retry after invalid credentials
Admin Control Center: 1. Review executive financial KPIs
Admin Control Center: 2. Retry failed analytics fetch
Admin Control Center: Audit real-time ledger table
Admin Control Center: Inspect individual ledger rows
Admin Control Center: Identify marked commission entries