# sebastianaigner/reelchest architecture

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

- Interactive diagram: https://gitdiagram.com/sebastianaigner/reelchest
- Repository: https://github.com/sebastianaigner/reelchest

## Overview

Based on our review of the file tree and README, this project ("reelchest") is a web-based media manager that provides functionality for downloading/uploading media, generating and comparing perceptual hashes (DHash) to detect duplicate videos, basic tagging, and integration with external search and video-hosting adapters. It is a full-stack application that also extends to mobile platforms along with a dedicated Rust-based component (duplicates-agent-rs) for handling duplicate calculations.

##### Main Components
- Backend Server:
– Developed primarily in Kotlin using Ktor (evident from files like Application.kt, KtorPlugins.kt and the structured api/handlers).
– Contains sub-components for processing:
- API layer (multiple handlers under api/handlers)
- Media library management (library, downloader, storage)
- Duplicate detection (duplicatecalculator, phash, helpertools)
- Media processing integrations: ffmpeg, autoscrape, setup tasks.
- Other utilities: logging, networking, and hashing.
- Frontend Web UI:
– Built with a modern JavaScript/TypeScript stack (React) as seen in the frontend directory (e.g., App.tsx, views, components, styles).
– Uses Vite for development and has its own dev server on port 3000. It also includes a proxy that forwards API calls (under /api/) to the backend.
- Mobile Applications:
– Located in the “mobileapp” directory; this includes platform-specific projects for Android, iOS, and multiplatform shared code.
– Involves several modules such as androidApp, iosApp, mediaPlayer, webView, and windowManager.
- Additional Tools & External Agents:
– A Rust-based duplicates agent in "duplicates-agent-rs" which likely complements the backend's duplicate detection.
– Process module to manage external processes.

##### Relationships and Interactions
- The Frontend (web UI) and Mobile Apps interact with the Backend via REST API endpoints.
- The API layer in the backend routes requests to various handlers (e.g., for file uploads, downloads, tagging, duplicate checking, analytics).
- The media processing pipeline kicks in when media is uploaded or downloaded: components such as downloader, ffmpeg integration, and media library modules handle file operations and quality processing (e.g., thumbnail generation).
- The duplicate detection mechanism involves computing perceptual hashes (DHash), comparing media, and managing duplicate responses.
- The Rust duplicates agent could either work as an auxiliary service or be integrated in a microservice style separated from the primary backend.
- Data storage and file management are handled by a combination of filesystem-based storage (with dedicated directories in test_media_library) and likely a lightweight database (notice SQLite references).

##### Architectural Patterns and Design Principles Highlighted
- Separation of Concerns: The backend is modularized into packages (e.g., api, downloader, library, storage) which clearly delineate responsibilities.
- Microservice-like Components: Although the system is monolithic in codebase form, there is clear separation between backend, frontend, and mobile apps. The existence of the self-contained “duplicates-agent-rs” points to a componentized approach.
- API-first approach: Clear API endpoints with DTOs for data interchange (see backend/src/main/kotlin/api/dtos) and auto-generated API documentation (openapi dir).
- Utilization of external tools: Integration with ffmpeg for media processing, and dedicated modules for hashing and duplicate calculations.

##### Relevant Technologies, Frameworks, & Libraries
- Kotlin with Ktor for backend server capabilities.
- Gradle (KTS) for build and dependency management.
- JavaScript/TypeScript with React and Vite for the frontend.
- Mobile development with Kotlin Multiplatform (shared, Android, iOS, webView etc.).
- Rust for performance-critical duplicate calculations (duplicates-agent-rs).
- Ffmpeg for video processing.
- Docker (Dockerfile present for containerization) and CI/CD configurations (.github/workflows).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Clients"
        FE["Frontend Web UI"]:::client
        Mobile["Mobile Applications"]:::client
    end

    subgraph "Backend Server"
        BCore["Core Application"]:::backend
        API["API Layer (Handlers & DTOs)"]:::backend
        Library["Media Library Management"]:::backend

        subgraph "Media Processing Pipeline"
            Downloader["Downloader Module"]:::backend
            Ffmpeg["Ffmpeg Integration"]:::backend
            Autoscrape["Autoscrape Integration"]:::backend
        end

        subgraph "Duplicate Detection"
            DupCalc["Duplicate Calculator"]:::backend
            DHash["Perceptual Hashing (DHash)"]:::backend
            Helper["Helper Tools"]:::backend
        end

        Process["External Process Management"]:::backend
    end

    Rust["Rust-based Duplicates Agent"]:::aux

    %% Clients interactions with Backend API
    FE -->|"APIRequest/Response"| API
    Mobile -->|"APIRequest/Response"| API

    %% API routing to Media Processing Pipeline
    API -->|"MediaFileProcessing"| Downloader
    API -->|"MediaFileProcessing"| Ffmpeg
    API -->|"MediaFileProcessing"| Autoscrape

    %% Media Processing Pipeline stores/processes files with Library
    Downloader -->|"FileStorage"| Library
    Ffmpeg -->|"FileProcessing"| Library
    Autoscrape -->|"FileProcessing"| Library

    %% Library triggers Duplicate Detection
    Library -->|"DuplicateCheck"| DupCalc
    DupCalc -->|"ComputeHash"| DHash
    DupCalc -->|"UtilizeTools"| Helper

    %% Duplicate Detection offloads performance-intensive tasks to Rust Agent
    DupCalc -->|"OffloadDuplicateCalc"| Rust

    %% API calls external process management for various utilities
    API -->|"UtilityCalls"| Process

    %% Click Events
    click BCore "https://github.com/sebastianaigner/reelchest/tree/master/backend/src/main/kotlin"
    click API "https://github.com/sebastianaigner/reelchest/tree/master/backend/src/main/kotlin/api"
    click Downloader "https://github.com/sebastianaigner/reelchest/tree/master/backend/src/main/kotlin/downloader"
    click Ffmpeg "https://github.com/sebastianaigner/reelchest/tree/master/backend/src/main/kotlin/ffmpeg"
    click Autoscrape "https://github.com/sebastianaigner/reelchest/tree/master/backend/src/main/kotlin/autoscrape"
    click Library "https://github.com/sebastianaigner/reelchest/tree/master/backend/src/main/kotlin/library"
    click DupCalc "https://github.com/sebastianaigner/reelchest/tree/master/backend/src/main/kotlin/duplicatecalculator"
    click DHash "https://github.com/sebastianaigner/reelchest/tree/master/backend/src/main/kotlin/phash"
    click Helper "https://github.com/sebastianaigner/reelchest/tree/master/backend/src/main/kotlin/helpertools"
    click FE "https://github.com/sebastianaigner/reelchest/tree/master/frontend"
    click Mobile "https://github.com/sebastianaigner/reelchest/tree/master/mobileapp"
    click Rust "https://github.com/sebastianaigner/reelchest/tree/master/duplicates-agent-rs"
    click Process "https://github.com/sebastianaigner/reelchest/tree/master/process"

    %% Styles
    classDef client fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef backend fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef aux fill:#FAD7A0,stroke:#F39C12,stroke-width:2px;
```
