Overview
StreamSphere is a production-ready, YouTube-like backend video-streaming platform API, handling secure cookie-based authentication, video/thumbnail uploading and transcoding via Cloudinary, subscription systems, playlists, and engagement metrics (likes, comments, tweets).
Core Features
- Dual-Token Authentication: Short-lived
accessTokenplus a long-livedrefreshTokenpersisted on the user document, allowing silent token refresh without re-login. Passwords are hashed via abcryptpre-save hook at 10 salt rounds. - Video Publishing Pipeline: Multer stages
videoFileandthumbnailuploads on disk,uploadOnCloudinarypushes them to cloud storage and returns remote URLs, and local temp files are purged withfs.unlinkSync()immediately after. - Aggregation-Driven Subscriptions:
getUserChannelProfileuses MongoDB$lookup+$addFieldsto compute subscriber counts and the current user's subscription status in a single aggregation query, rather than N+1 lookups. - Layered Architecture: Every request flows through Routes → Middleware (Multer/Auth) → Controllers → Models, with
asyncHandlerauto-forwarding errors to Express's error pipeline andApiResponse/ApiErrorsutilities standardizing every JSON payload.
Engineering Audit
While documenting the codebase, I traced a full request lifecycle and surfaced two real issues worth fixing before this goes further:
- Field-name mismatch:
like.model.jsdefines the liking-user reference aslikedBy, buttoggleVideoLike/toggleCommentLikein the controller query and write usinguserinstead — meaning likes silently fail to match on lookup. Root-caused to a refactor that renamed the schema field without updating the controllers. - Unmounted routers: several feature routers (tweets, comments, subscriptions, likes, playlists, dashboard, healthcheck) were wired but commented out in
app.js, so those endpoints weren't actually reachable over HTTP despite being fully implemented.
Both are the kind of bug that only surfaces under a real code trace — exactly the value of pairing implementation with a deliberate architecture review.