How chirag-and-dheeraj/video-streaming-server works
Project type and purpose
• This is a full-stack, on-demand video streaming server called “Dekho.”
• The backend is a monolithic Go application that implements HLS (.m3u8 + .ts chunk) streaming, user authentication, video upload/metadata storage, and serves both API endpoints and static assets.
• The frontend is plain HTML/CSS/JS using HLS.js to play streams.
File structure
• Top-level directories:
• client/ → pure HTML pages (index, login, register, upload, watch, list)
• static/ → CSS, JS bundles, logo, videoList components
• controllers/ → HTTP handlers for users and videos
• services/ → business logic (upload, transcoding, HLS manifest generation)
• repositories/ → database access for user and video entities
• database/ → SQL migrations and database initialization
• middleware/ → auth, logging, CORS, rate-limiting
• config/ → config loader (env, Docker, Appwrite keys)
• utils/, types/ → shared utilities and type definitions
• main.go → application bootstrap (router, middleware, DI)
• Dockerfile, docker-compose.yml, Makefile → containerization and local/dev scripts
Extract additional insights from README
• Backend tech: Go 1.23, PostgreSQL 16.3, Appwrite Storage bucket, FFMPEG (for chunking), golang-migrate
• Frontend tech: HTML/CSS/JS, HLS.js
• Runtime: served on localhost:8000 (or in Docker) combining API + static server
• External dependencies: Appwrite REST API for object storage, PostgreSQL for metadata
Main components and interactions
• Browser / Client UI
• Static File Server (serving HTML, CSS, JS assets)
• Go Application Server
• HTTP Router & Middleware
• Controllers (UserController, VideoController)
• Services (UploadService, HLSService)
• Repositories (UserRepo, VideoRepo)
• FFMPEG Processor (invoked as CLI subprocess)
• PostgreSQL Database
• Appwrite Storage Bucket (for storing raw uploads, TS chunks, thumbnails)
• HLS.js Player (in the browser, embedded in watch.html)
1. Browser → Static File Server: GET HTML/CSS/JS
2. Browser → Go Server API:
• POST /register, /login → Auth → JWT/session
• GET /videos → fetch metadata (JSON) from VideoRepo → DB
• POST /upload → multipart upload → Go Server streams file to Appwrite Storage
3. Go Server → FFMPEG: invoke CLI to transcode & segment raw video blob into .ts chunks + .m3u8 manifest
4. FFMPEG → Appwrite Storage: upload TS chunk files and manifest
5. Browser (HLS.js) → Go Server: GET /videos/{id}/playlist.m3u8 and .ts segments → streamed over HTTP
6. Go Server → PostgreSQL: read/write user & video metadata using SQL migrations and Repositories
c. Architectural patterns & design principles:
• Layered MVC (controllers → services → repositories → database)
• Separation of concerns: video ingestion, processing, storage, metadata, playback
• Externalize configuration via env files and config module
• Containerized deployment via Docker + docker-compose
• Use of CI/CD-style migrations (golang-migrate)
• Single binary Go server serving both API and static assets
• Go net/http, Gorilla Mux (or native router)
• ffmpeg CLI for segmentation
• PostgreSQL
• Appwrite Storage REST API
• HTML/CSS/Vanilla JS + HLS.js