# prasanta-mondal76/playtube-fullstack architecture

> Architecture diagram of the GitHub repository prasanta-mondal76/playtube-fullstack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prasanta-mondal76/playtube-fullstack
- Repository: https://github.com/prasanta-mondal76/playtube-fullstack

## Overview

1. Repository shape
- This is a Node.js backend for PlayTube, a video/social platform inspired by YouTube.
- The codebase is organized as a classic layered API server: routes → middleware → controllers → models → utilities, with a separate DB bootstrap and a small public temp storage area for uploads.

2. Runtime and application entry
- `src/index.js` is the server entrypoint.
- `src/app.js` likely configures the Express application, registers middleware, and mounts feature routes.
- `src/constants.js` centralizes shared config values used across the app.

3. API surface and feature modules
- The main HTTP API is split by domain into four route groups:
  - `user.routes.js`
  - `video.routes.js`
  - `playlist.routes.js`
  - `tweet.routes.js`
- This suggests a modular REST API where each domain owns its own endpoints and request handling.

4. Controller layer as the orchestration boundary
- Controllers in `src/controller/` contain the request-level business logic:
  - `user.controller.js`
  - `video.controller.js`
  - `playlist.controller.js`
  - `tweet.controller.js`
- Controllers sit between Express routes and the persistence layer. They likely validate inputs, call models, manage file uploads, and return standardized responses.

5. Data model layer and domain boundaries
- The app uses distinct Mongoose-style domain models in `src/models/`:
  - `user.model.js`
  - `video.model.js`
  - `playlist.model.js`
  - `tweet.model.js`
  - `comment.model.js`
  - `like.model.js`
  - `subscription.model.js`
- This indicates a document database architecture with relationships expressed through references between collections rather than a relational schema.
- Core domain boundaries are:
  - identity and auth: users
  - media content: videos
  - curation: playlists
  - social posting: tweets
  - engagement: comments and likes
  - following graph: subscriptions

6. Authentication and request protection
- `src/middlewares/auth.middleware.js` is the main access-control boundary.
- Protected routes likely require a verified user context before controllers can execute.
- This middleware is important for any diagram because it separates public endpoints from authenticated operations like upload, create, like, subscribe, or edit.

7. File upload and media handling pipeline
- `src/middlewares/multer.middleware.js` indicates multipart/form-data upload handling.
- `public/temp/` is a staging area for uploaded files before they are processed or moved elsewhere.
- `src/utils/deleteTempFiles.js` implies a lifecycle where temporary local files are cleaned up after successful processing.
- `src/utils/cloudinary.js` shows that video/image assets are pushed to Cloudinary, so media storage is externalized instead of kept on the app server.

8. External service integrations
- Cloudinary is the clear external media service in the architecture.
- `src/utils/sendMail.js` shows email delivery is part of the system, likely for onboarding, verification, password recovery, or notifications.
- These integrations sit outside the core API/database boundary and are invoked from controllers or supporting utilities.

9. Database and persistence boundary
- `src/db/index.js` handles database connectivity and startup initialization.
- Given the model structure, the persistence layer is almost certainly MongoDB accessed through ODM models.
- The data flow is: request → controller → model → database, with response formatting on the way back.

10. Shared utility layer
- `src/utils/` contains cross-cutting infrastructure:
  - `apiError.js` for consistent error objects
  - `apiResponse.js` for consistent success payloads
  - `asyncHandler.js` for wrapping async route handlers
  - `index.js` as a utility barrel/export surface
- This utility layer standardizes error handling and response formatting across all route modules.

11. Request processing pattern
- The app likely follows a common Express sequence:
  - route matches request
  - auth/upload middleware runs if needed
  - controller executes domain logic
  - model reads/writes the database
  - utility helpers format the response or error
- That makes controllers the main orchestration point and models the main persistence boundary.

12. Architectural emphasis for a diagram
- The most important boxes to draw are:
  - Express app/server
  - route modules by feature
  - auth and multer middleware
  - controllers
  - domain models
  - database
  - Cloudinary
  - email service
  - temp upload storage
- The strongest data flow is media upload: client upload → multer/temp file → controller → Cloudinary → database record update.

13. What this repo is not showing
- The tree does not include a frontend app, socket/chat implementation, or task queue, even though the README mentions real-time chat.
- So from the available files, the visible architecture is primarily the backend API and its storage/integration boundaries rather than a full client-server monorepo.

Main entry points: [`src/controller/video.controller.js`](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/controller/video.controller.js) (Video Controller), [`src/app.js`](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/app.js) (Express App), [`src/routes/video.routes.js`](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/routes/video.routes.js) (Video Routes), [`src/controller/user.controller.js`](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/controller/user.controller.js) (User Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_runtime["Runtime"]
  node_node_index(("Server<br/>entrypoint<br/>[index.js]"))
  node_node_app["Express App<br/>express config<br/>[app.js]"]
  node_node_constants["Constants<br/>shared config<br/>[constants.js]"]
end

subgraph group_group_api["API Layer"]
  node_node_user_routes["User Routes<br/>route module<br/>[user.routes.js]"]
  node_node_video_routes["Video Routes<br/>route module<br/>[video.routes.js]"]
  node_node_playlist_routes["Playlist Routes<br/>route module<br/>[playlist.routes.js]"]
  node_node_tweet_routes["Tweet Routes<br/>route module<br/>[tweet.routes.js]"]
  node_node_auth{{"Auth Middleware<br/>access control<br/>[auth.middleware.js]"}}
  node_node_multer{{"Upload Middleware<br/>multipart parser"}}
  node_node_user_ctrl["User Controller<br/>request handler<br/>[user.controller.js]"]
  node_node_video_ctrl["Video Controller<br/>request handler"]
  node_node_playlist_ctrl["Playlist Controller<br/>request handler"]
  node_node_tweet_ctrl["Tweet Controller<br/>request handler"]
end

subgraph group_group_domain["Domain Models"]
  node_node_user_model[("User Model<br/>domain model<br/>[user.model.js]")]
  node_node_video_model[("Video Model<br/>domain model<br/>[video.model.js]")]
  node_node_playlist_model[("Playlist Model<br/>domain model<br/>[playlist.model.js]")]
  node_node_tweet_model[("Tweet Model<br/>domain model<br/>[tweet.model.js]")]
  node_node_social_models[("Engagement Models<br/>domain models<br/>[comment.model.js]")]
end

subgraph group_group_infra["Infrastructure"]
  node_node_db[("Database<br/>mongo bootstrap<br/>[index.js]")]
  node_node_temp["Temp Storage<br/>upload staging"]
  node_node_cloudinary{{"Cloudinary<br/>media service<br/>[cloudinary.js]"}}
  node_node_mail{{"Mail Service<br/>email integration<br/>[sendMail.js]"}}
end

subgraph group_group_shared["Shared Utils"]
  node_node_api_error["API Error<br/>error helper<br/>[apiError.js]"]
  node_node_api_response["API Response<br/>response helper<br/>[apiResponse.js]"]
  node_node_async["Async Handler<br/>wrapper helper<br/>[asyncHandler.js]"]
  node_node_utils_index["Utils Index<br/>barrel export<br/>[index.js]"]
  node_node_delete_temp["Temp Cleanup<br/>file helper<br/>[deleteTempFiles.js]"]
end

node_node_index -->|"boots"| node_node_app
node_node_app -->|"uses"| node_node_constants
node_node_app -->|"mounts"| node_node_user_routes
node_node_app -->|"mounts"| node_node_video_routes
node_node_app -->|"mounts"| node_node_playlist_routes
node_node_app -->|"mounts"| node_node_tweet_routes
node_node_user_routes -->|"guards"| node_node_auth
node_node_video_routes -->|"guards"| node_node_auth
node_node_playlist_routes -->|"guards"| node_node_auth
node_node_tweet_routes -->|"guards"| node_node_auth
node_node_video_routes -->|"uploads"| node_node_multer
node_node_user_routes -->|"calls"| node_node_user_ctrl
node_node_video_routes -->|"calls"| node_node_video_ctrl
node_node_playlist_routes -->|"calls"| node_node_playlist_ctrl
node_node_tweet_routes -->|"calls"| node_node_tweet_ctrl
node_node_user_ctrl -->|"reads/writes"| node_node_user_model
node_node_video_ctrl -->|"reads/writes"| node_node_video_model
node_node_video_ctrl -->|"references"| node_node_playlist_model
node_node_playlist_ctrl -->|"reads/writes"| node_node_playlist_model
node_node_tweet_ctrl -->|"reads/writes"| node_node_tweet_model
node_node_user_ctrl -->|"uses"| node_node_social_models
node_node_video_ctrl -->|"uses"| node_node_social_models
node_node_user_model -->|"stored in"| node_node_db
node_node_video_model -->|"stored in"| node_node_db
node_node_playlist_model -->|"stored in"| node_node_db
node_node_tweet_model -->|"stored in"| node_node_db
node_node_social_models -->|"stored in"| node_node_db
node_node_video_ctrl -->|"stages files"| node_node_temp
node_node_video_ctrl -->|"uploads"| node_node_cloudinary
node_node_video_ctrl -->|"cleans up"| node_node_delete_temp
node_node_user_ctrl -->|"sends"| node_node_mail
node_node_playlist_ctrl -->|"formats"| node_node_api_response
node_node_tweet_ctrl -->|"formats"| node_node_api_response
node_node_user_ctrl -->|"raises"| node_node_api_error
node_node_video_ctrl -->|"raises"| node_node_api_error
node_node_user_routes -->|"wraps"| node_node_async
node_node_video_routes -->|"wraps"| node_node_async
node_node_playlist_routes -->|"wraps"| node_node_async
node_node_tweet_routes -->|"wraps"| node_node_async
node_node_utils_index -->|"exports"| node_node_api_error
node_node_utils_index -->|"exports"| node_node_api_response
node_node_utils_index -->|"exports"| node_node_async
node_node_utils_index -->|"exports"| node_node_cloudinary

click node_node_index "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/index.js"
click node_node_app "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/app.js"
click node_node_constants "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/constants.js"
click node_node_user_routes "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/routes/user.routes.js"
click node_node_video_routes "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/routes/video.routes.js"
click node_node_playlist_routes "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/routes/playlist.routes.js"
click node_node_tweet_routes "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/routes/tweet.routes.js"
click node_node_auth "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/middlewares/auth.middleware.js"
click node_node_multer "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/middlewares/multer.middleware.js"
click node_node_user_ctrl "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/controller/user.controller.js"
click node_node_video_ctrl "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/controller/video.controller.js"
click node_node_playlist_ctrl "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/controller/playlist.controller.js"
click node_node_tweet_ctrl "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/controller/tweet.controller.js"
click node_node_user_model "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/models/user.model.js"
click node_node_video_model "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/models/video.model.js"
click node_node_playlist_model "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/models/playlist.model.js"
click node_node_tweet_model "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/models/tweet.model.js"
click node_node_social_models "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/models/comment.model.js"
click node_node_db "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/db/index.js"
click node_node_temp "https://github.com/prasanta-mondal76/playtube-fullstack/tree/main/public/temp"
click node_node_cloudinary "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/cloudinary.js"
click node_node_mail "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/sendMail.js"
click node_node_api_error "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/apiError.js"
click node_node_api_response "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/apiResponse.js"
click node_node_async "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/asyncHandler.js"
click node_node_utils_index "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/index.js"
click node_node_delete_temp "https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/deleteTempFiles.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_index,node_node_app,node_node_constants toneBlue
class node_node_user_routes,node_node_video_routes,node_node_playlist_routes,node_node_tweet_routes,node_node_auth,node_node_multer,node_node_user_ctrl,node_node_video_ctrl,node_node_playlist_ctrl,node_node_tweet_ctrl toneAmber
class node_node_user_model,node_node_video_model,node_node_playlist_model,node_node_tweet_model,node_node_social_models toneMint
class node_node_db,node_node_temp,node_node_cloudinary,node_node_mail toneRose
class node_node_api_error,node_node_api_response,node_node_async,node_node_utils_index,node_node_delete_temp toneIndigo
```

## Components

### Runtime

Express server bootstrap and app setup

- [Server](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/index.js): entrypoint · Starts the Node.js process and boots the app · `src/index.js`
- [Express App](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/app.js): express config · Configures middleware and mounts feature routes · `src/app.js`
- [Constants](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/constants.js): shared config · Centralized application constants · `src/constants.js`

### API Layer

Feature routes, middleware, and controllers

- [User Routes](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/routes/user.routes.js): route module · HTTP endpoints for user features · `src/routes/user.routes.js`
- [Video Routes](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/routes/video.routes.js): route module · HTTP endpoints for video features · `src/routes/video.routes.js`
- [Playlist Routes](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/routes/playlist.routes.js): route module · HTTP endpoints for playlist features · `src/routes/playlist.routes.js`
- [Tweet Routes](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/routes/tweet.routes.js): route module · HTTP endpoints for tweet features · `src/routes/tweet.routes.js`
- [Auth Middleware](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/middlewares/auth.middleware.js): access control · Verifies request identity and protects private endpoints · `src/middlewares/auth.middleware.js`
- [Upload Middleware](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/middlewares/multer.middleware.js): multipart parser · Handles multipart uploads before controller logic · `src/middlewares/multer.middleware.js`
- [User Controller](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/controller/user.controller.js): request handler · Orchestrates user-related request flow · `src/controller/user.controller.js`
- [Video Controller](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/controller/video.controller.js): request handler · Orchestrates video upload and content logic · `src/controller/video.controller.js`
- [Playlist Controller](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/controller/playlist.controller.js): request handler · Orchestrates playlist operations · `src/controller/playlist.controller.js`
- [Tweet Controller](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/controller/tweet.controller.js): request handler · Orchestrates tweet operations · `src/controller/tweet.controller.js`

### Domain Models

Mongo-style persistence models

- [User Model](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/models/user.model.js): domain model · User collection schema and queries · `src/models/user.model.js`
- [Video Model](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/models/video.model.js): domain model · Video collection schema and queries · `src/models/video.model.js`
- [Playlist Model](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/models/playlist.model.js): domain model · Playlist collection schema and queries · `src/models/playlist.model.js`
- [Tweet Model](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/models/tweet.model.js): domain model · Tweet collection schema and queries · `src/models/tweet.model.js`
- [Engagement Models](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/models/comment.model.js): domain models · Comment, like, and subscription collections · `src/models/comment.model.js`

### Infrastructure

Database, media storage, and external services

- [Database](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/db/index.js): mongo bootstrap · Initializes application database connectivity · `src/db/index.js`
- [Temp Storage](https://github.com/prasanta-mondal76/playtube-fullstack/tree/main/public/temp): upload staging · Local staging area for uploaded files · `public/temp`
- [Cloudinary](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/cloudinary.js): media service · External media storage for images and video assets · `src/utils/cloudinary.js`
- [Mail Service](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/sendMail.js): email integration · Sends onboarding and notification emails · `src/utils/sendMail.js`

### Shared Utils

Cross-cutting helpers used across the app

- [API Error](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/apiError.js): error helper · Standardized application error objects · `src/utils/apiError.js`
- [API Response](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/apiResponse.js): response helper · Standardized success payloads · `src/utils/apiResponse.js`
- [Async Handler](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/asyncHandler.js): wrapper helper · Wraps async controllers and routes · `src/utils/asyncHandler.js`
- [Utils Index](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/index.js): barrel export · Shared utility export surface · `src/utils/index.js`
- [Temp Cleanup](https://github.com/prasanta-mondal76/playtube-fullstack/blob/main/src/utils/deleteTempFiles.js): file helper · Removes temporary local upload files · `src/utils/deleteTempFiles.js`

## Connections

- Server → Express App: boots · Process startup enters the Express application
- Express App → Constants: uses · Application configuration reads shared constants
- Express App → User Routes: mounts · Registers user feature routes
- Express App → Video Routes: mounts · Registers video feature routes
- Express App → Playlist Routes: mounts · Registers playlist feature routes
- Express App → Tweet Routes: mounts · Registers tweet feature routes
- User Routes → Auth Middleware: guards · Protected user endpoints require authentication
- Video Routes → Auth Middleware: guards · Protected video endpoints require authentication
- Playlist Routes → Auth Middleware: guards · Protected playlist endpoints require authentication
- Tweet Routes → Auth Middleware: guards · Protected tweet endpoints require authentication
- Video Routes → Upload Middleware: uploads · Video requests accept multipart file uploads
- User Routes → User Controller: calls · Routes delegate to user controller logic
- Video Routes → Video Controller: calls · Routes delegate to video controller logic
- Playlist Routes → Playlist Controller: calls · Routes delegate to playlist controller logic
- Tweet Routes → Tweet Controller: calls · Routes delegate to tweet controller logic
- User Controller → User Model: reads/writes · User controller persists user data
- Video Controller → Video Model: reads/writes · Video controller persists video data
- Video Controller → Playlist Model: references · Video logic may relate to playlists
- Playlist Controller → Playlist Model: reads/writes · Playlist controller persists playlist data
- Tweet Controller → Tweet Model: reads/writes · Tweet controller persists tweet data
- User Controller → Engagement Models: uses · User logic interacts with comments, likes, and subscriptions
- Video Controller → Engagement Models: uses · Video logic interacts with engagement collections
- User Model → Database: stored in · Domain models are backed by the database
- Video Model → Database: stored in · Domain models are backed by the database
- Playlist Model → Database: stored in · Domain models are backed by the database
- Tweet Model → Database: stored in · Domain models are backed by the database
- Engagement Models → Database: stored in · Domain models are backed by the database
- Video Controller → Temp Storage: stages files · Uploaded media is staged locally before processing
- Video Controller → Cloudinary: uploads · Media assets are pushed to external storage
- Video Controller → Temp Cleanup: cleans up · Temporary upload files are removed after processing
- User Controller → Mail Service: sends · User flows may trigger email delivery
- Playlist Controller → API Response: formats · Controllers return standardized responses
- Tweet Controller → API Response: formats · Controllers return standardized responses
- User Controller → API Error: raises · Controllers emit standardized errors
- Video Controller → API Error: raises · Controllers emit standardized errors
- User Routes → Async Handler: wraps · Async route handlers are wrapped for error propagation
- Video Routes → Async Handler: wraps · Async route handlers are wrapped for error propagation
- Playlist Routes → Async Handler: wraps · Async route handlers are wrapped for error propagation
- Tweet Routes → Async Handler: wraps · Async route handlers are wrapped for error propagation
- Utils Index → API Error: exports · Utility barrel re-exports error helpers
- Utils Index → API Response: exports · Utility barrel re-exports response helpers
- Utils Index → Async Handler: exports · Utility barrel re-exports async wrapper
- Utils Index → Cloudinary: exports · Utility barrel re-exports integration helpers
