# rajukumarsaw/shorts_videos_apps architecture

> Architecture diagram of the GitHub repository rajukumarsaw/shorts_videos_apps, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rajukumarsaw/shorts_videos_apps
- Repository: https://github.com/rajukumarsaw/shorts_videos_apps

## Overview

##### Main Components

A. Client Layer (Frontend):
- React Application (Vite-based)
- Key components:
- Video-related components (VideoList, Video, VideoSideBar)
- Authentication pages (Login/Signup)
- User Profile
- Upload functionality
- Integration with Tailwind CSS for styling

B. Backend Services:
- Express.js Server
- Three main controllers:
- User Controller (authentication/authorization)
- Short Videos Controller (video management)
- Interaction Controller (likes, comments)
- Middleware layer for authentication
- API Routes structure

C. Recommendation System:
- Flask-based microservice
- NMF (Non-negative Matrix Factorization) model
- Training pipeline

D. External Services:
- MongoDB Database
- Cloudinary (for video storage)
- Authentication service (JWT)

**[Client Layer]**
- ↕
**[API Gateway/Backend Layer]**
- ↕
**[Services Layer]**
- ↙     ↓     ↘
**[Database] [Storage] [Recommendation]**

##### Component Relationships

- User interactions → Frontend → Backend
- Backend → Database for CRUD operations
- Backend → Cloudinary for video storage
- Backend ↔ Recommendation System for personalized content
- Recommendation System → Database for user interaction data

##### Specific Implementation Details

A. Frontend Architecture:
- Main routes (/login, /signup, /profile, /upload, /reels)
- Component hierarchy
- State management flow

B. Backend Architecture:
- Express middleware pipeline
- Controller organization
- Model structure (User, Video, Interaction)

C. Recommendation System:
- Model training pipeline
- Inference API
- Data flow for recommendations

##### Additional Elements

A. Security Layer:
- JWT authentication flow
- Protected routes
- Authorization middleware

B. Performance Considerations:
- Video streaming paths
- Caching layers
- API optimization points

##### Key Focus Areas

- Video handling pipeline
- Recommendation system integration
- Authentication flow
- Demonstrate the separation of concerns
- Scaling considerations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        App["App"]:::frontend
        VideoComp["Video Components"]:::frontend
        AuthPages["Auth Pages"]:::frontend
        Profile["Profile"]:::frontend
        Upload["Upload"]:::frontend
        
        App --> VideoComp
        App --> AuthPages
        App --> Profile
        App --> Upload
        
        VideoComp --> VideoList["Video List"]:::frontend
        VideoComp --> VideoPlayer["Video Player"]:::frontend
        VideoComp --> VideoSideBar["Video Sidebar"]:::frontend
    end

    subgraph Backend
        Server["Express Server"]:::backend
        
        subgraph Controllers
            UserCtrl["User Controller"]:::controller
            VideoCtrl["Short Videos Controller"]:::controller
            InteractionCtrl["Interaction Controller"]:::controller
        end
        
        subgraph Middleware
            AuthMW["Auth Middleware"]:::middleware
        end
        
        subgraph Routes
            UserRoute["User Routes"]:::route
            VideoRoute["Video Routes"]:::route
            InteractionRoute["Interaction Routes"]:::route
        end
        
        Server --> AuthMW
        AuthMW --> Controllers
        Controllers --> Routes
    end

    subgraph Services
        MongoDB[(MongoDB)]:::database
        Cloudinary["Cloudinary Storage"]:::external
        
        subgraph "Recommendation System"
            FlaskApp["Flask Service"]:::recommendation
            NMFModel["NMF Model"]:::recommendation
            TrainingPipe["Training Pipeline"]:::recommendation
            
            FlaskApp --> NMFModel
            TrainingPipe --> NMFModel
        end
    end

    Client --> Backend
    Backend --> Services
    
    %% Component Mappings
    click App "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/frontend/src/App.jsx"
    click VideoList "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/frontend/src/components/videoList.jsx"
    click VideoPlayer "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/frontend/src/components/video.jsx"
    click VideoSideBar "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/frontend/src/components/VideoSideBar.jsx"
    click AuthPages "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/frontend/src/pages/logIn.jsx"
    click Profile "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/frontend/src/pages/profile.jsx"
    click Upload "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/frontend/src/pages/upload.jsx"
    click Server "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/backend/app.js"
    click UserCtrl "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/backend/controllers/userController.js"
    click VideoCtrl "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/backend/controllers/shortVideosController.js"
    click InteractionCtrl "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/backend/controllers/interactionController.js"
    click AuthMW "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/backend/middleware/auth.js"
    click UserRoute "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/backend/routes/userRoute.js"
    click VideoRoute "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/backend/routes/videosRoute.js"
    click InteractionRoute "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/backend/routes/interactionRoute.js"
    click FlaskApp "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/recommendation-system/flask_app/app.py"
    click NMFModel "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/recommendation-system/flask_app/model/nmf_model.pkl"
    click TrainingPipe "https://github.com/Rajukumarsaw/shorts_videos_apps/blob/main/recommendation-system/utils/train_model.py"

    %% Styling
    classDef frontend fill:#2196F3,color:white
    classDef backend fill:#4CAF50,color:white
    classDef controller fill:#81C784,color:white
    classDef middleware fill:#A5D6A7,color:white
    classDef route fill:#C8E6C9,color:black
    classDef database fill:#9E9E9E,color:white
    classDef external fill:#FFC107,color:black
    classDef recommendation fill:#9C27B0,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        BackendComp["Backend Component"]:::backend
        DatabaseComp[(Database)]:::database
        ExternalComp["External Service"]:::external
        RecommendationComp["Recommendation Component"]:::recommendation
    end
```
