How subhojit0012/youtube-backend works
This is a TypeScript tRPC backend for a YouTube-like sharing service. Requests enter through Express, receive a token-aware context, and are dispatched through merged user, video, playlist, and history routers to service logic or Mongoose models. The principal workflows cover authentication and account operations, video management, playlist updates, and watch history. MongoDB connection/bootstrap and JWT context are included; the README documents upload and account capabilities, though implementation details are not uniformly shown in the excerpts.
Main entry points: user.model.ts User model · _app.router.ts Router registry · index.ts Express bootstrap · playlist.model.ts Playlist model
Components 22
HTTP and tRPC
- Express bootstrap
src/index.ts - Router registry
src/router/_app.router.ts
Identity and context
- tRPC context and auth
src/utility/context.utility.ts - JWT utilities
src/utility/token.utility.ts
Product workflows
- User routes
src/router/user.route.ts - Video routes
src/router/video.route.ts - Playlist routes
src/router/playlist.route.ts - History routes
src/router/history.route.ts - Account operations
src/service/user.service.ts - Video operations
src/service/video.service.ts - Watch history
src/service/history.service.ts - Playlist service
src/service/playlist.service.ts
MongoDB persistence
- MongoDB connection
src/db/connect.db.ts - User model
src/db/models/user.model.ts - Video model
src/db/models/video.model.ts - Playlist model
src/db/models/playlist.model.ts - History model
src/db/models/history.model.ts - Channel model
src/db/models/channel.model.ts - Comment model
src/db/models/comment.model.ts - Subscription model
src/db/models/subscribe.model.ts
Other components
- API client
- MongoDB
Connections 25
- API client → Express bootstrap: sends requests
README.md - Express bootstrap → Router registry: mounts tRPC
src/index.ts - Express bootstrap → tRPC context and auth: creates context
src/index.ts - Express bootstrap → MongoDB connection: connects database
src/index.ts - Router registry → User routes: merges routes
src/router/_app.router.ts - Router registry → Video routes: merges routes
src/router/_app.router.ts - Router registry → Playlist routes: merges routes
src/router/_app.router.ts - Router registry → History routes: merges routes
src/router/_app.router.ts - tRPC context and auth → JWT utilities: decodes tokens
src/utility/context.utility.ts - User routes → Account operations: calls operations
src/router/user.route.ts - User routes → User model: reads profile
src/router/user.route.ts - Video routes → Video operations: calls operations
src/router/video.route.ts - Playlist routes → Playlist model: reads and writes
src/router/playlist.route.ts - History routes → Watch history: calls operations
src/router/history.route.ts - Account operations → User model: reads and writes
src/service/user.service.ts - Video operations → Video model: reads and writes
src/service/video.service.ts - Watch history → History model: reads and writes
src/service/history.service.ts - Playlist model → Video model: references videos
src/db/models/playlist.model.ts - Playlist model → User model: references owner
src/db/models/playlist.model.ts - User model → Channel model: references channel
src/db/models/user.model.ts - User model → History model: references history
src/db/models/user.model.ts - User model → Playlist model: references playlists
src/db/models/user.model.ts - User model → Video model: references videos
src/db/models/user.model.ts - User model → Subscription model: references subscriptions
src/db/models/user.model.ts - MongoDB connection → MongoDB: opens connection
src/db/connect.db.ts