# codecrafted7/moodsync architecture

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

- Interactive diagram: https://gitdiagram.com/codecrafted7/moodsync
- Repository: https://github.com/codecrafted7/moodsync

## Overview

##### Main Components Identification

a. Frontend Layer (UI)
- Emotion capture interface
- Video recommendation display
- Real-time emotion statistics

b. Core Services
- Emotion Detection Service
- Video Recommendation Service
- Request Executor Service

c. External Services & Storage
- YouTube Data API
- Local SQLite Database
- DeepFace Integration

**User Interface Layer**
**↕️**
**Core Processing Layer**
**↕️**
**Data & External Services Layer**

##### Component Relationships

a. Real-time Flow:
**Camera Input → Emotion Detector (DeepFace) → Request Executor → Video Service**

b. Data Flow:
**Video Service → SQLite DB (check local cache)**
- ↓
- YouTube Data API (if cache miss)

##### Specific Implementation Details

Technical aspects:

a. Parallel Processing:
- ThreadExecutorPool for emotion detection
- Request queue in the Request Executor

b. Data Models (represented as smaller components):
- Emotion Model (src/data/models/emotion.py)
- Video Model (src/data/models/video.py)

##### Important Architectural Patterns to Highlight

- Three-Layer Architecture:
- Presenter Layer (UI & Request Handling)
- Domain Layer (Business Logic)
- Data Layer (Storage & External Services)

- Asynchronous Processing:
- Parallel emotion detection
- Request queue management

##### Specific Elements

a. Components:
**[Camera Input] → [Emotion Detector (DeepFace)] → [Request Executor]**
- ↓
**[YouTube Data API] ← [Video Service] → [SQLite Database]**

b. Key Processes:
- Real-time frame capture
- Emotion detection processing
- Video recommendation pipeline
- Data caching mechanism

##### Technical Details to Emphasize

- ThreadExecutorPool implementation
- DeepFace integration points
- YouTube API interaction
- SQLite database operations
- Request queue management

Remember to indicate the technology stack used:
- Python (Core)
- DeepFace (Emotion Detection)
- YouTube Data API v3
- SQLite3
- Flask (Web Interface)

This system design should clearly demonstrate how MoodSync captures user emotions in real-time, processes them asynchronously, and delivers personalized video recommendations while maintaining a smooth user experience.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef service fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef critical fill:#e74c3c,stroke:#c0392b,color:white
    
    %% User Interface Layer
    subgraph UI
        Camera["Camera Input"]:::ui
        Interface["Frontend Interface"]:::ui
        Stats["Emotion Statistics"]:::ui
        VideoDisplay["Video Recommendations Display"]:::ui
    end
    
    %% Core Processing Layer
    subgraph Core
        EmotionDetector["Emotion Detection Service"]:::service
        RequestExecutor["Request Executor Service"]:::service
        VideoService["Video Recommendation Service"]:::service
        ThreadPool["Thread Executor Pool"]:::service
    end
    
    %% Data & External Services Layer
    subgraph Data
        DB[(SQLite Database)]:::storage
        YouTubeAPI["YouTube Data API"]:::external
        DeepFace["DeepFace Integration"]:::external
    end
    
    %% Data Models
    subgraph Models
        EmotionModel["Emotion Model"]:::service
        VideoModel["Video Model"]:::service
    end
    
    %% Relationships
    Camera --> EmotionDetector
    EmotionDetector --> DeepFace
    EmotionDetector --> ThreadPool
    ThreadPool --> RequestExecutor
    RequestExecutor --> VideoService
    VideoService --> DB
    VideoService --> YouTubeAPI
    VideoService --> VideoDisplay
    EmotionDetector --> Stats
    
    %% Component Mappings
    click Interface "https://github.com/CodeCrafted7/MoodSync/blob/main/src/presenter/home.py"
    click EmotionDetector "https://github.com/CodeCrafted7/MoodSync/blob/main/src/data/emotion_detector.py"
    click VideoService "https://github.com/CodeCrafted7/MoodSync/blob/main/src/domain/video_service.py"
    click RequestExecutor "https://github.com/CodeCrafted7/MoodSync/blob/main/src/presenter/request_executor.py"
    click DB "https://github.com/CodeCrafted7/MoodSync/blob/main/moodsync.db"
    click YouTubeAPI "https://github.com/CodeCrafted7/MoodSync/blob/main/src/data/youtube.py"
    click EmotionModel "https://github.com/CodeCrafted7/MoodSync/blob/main/src/data/models/emotion.py"
    click VideoModel "https://github.com/CodeCrafted7/MoodSync/blob/main/src/data/models/video.py"
    
    %% Legend
    subgraph Legend
        UI_Legend["UI Components"]:::ui
        Service_Legend["Services"]:::service
        External_Legend["External Services"]:::external
        Storage_Legend["Storage"]:::storage
        Critical_Legend["Critical Path"]:::critical
    end
```
