# voodoos/ocamix architecture

> Architecture diagram of the GitHub repository voodoos/ocamix, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/voodoos/ocamix
- Repository: https://github.com/voodoos/ocamix

## Overview

##### Main Components

a) Frontend Layer:
- UI Components (found in bin/ui*.ml files)
- Player Component (bin/player.ml)
- Menu System (bin/menu.ml)
- Application State Management (bin/app_state.ml)

b) Data Management Layer:
- Local Database (IndexedDB)
- Database Worker (bin/db_worker)
- Database Stores and Schema (lib/db/*)
- Sync System (lib/db/sync.ml)

c) Data Source Layer:
- Jellyfin Integration (lib/data_source/jellyfin.ml)
- Data Source Interface (lib/data_source/data_source_intf.ml)

d) Worker Architecture:
- Worker Client (bin/worker_client.ml)
- Worker API (lib/worker_api/*)

**[Frontend Layer]**
- ↕
**[Data Management Layer]**
- ↕
**[External Services Layer]**

##### Component Relationships

- Frontend components communicating with the local database through the worker architecture
- Database sync operations with external services (Jellyfin)
- State management flow between UI components
- Data flow between the worker client and worker API

##### Technical Details

- IndexedDB as the local storage solution
- Jellyfin API integration points
- Worker-based architecture for database operations
- Reactive programming patterns using brr-lwd

##### Implementation Notes

- The separation between the main thread and database worker
- The data source abstraction layer (allowing for future additional sources beyond Jellyfin)
- The local database's role in enabling fast sorting and filtering
- The reactive UI update mechanism

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#a8d1f0,stroke:#333
    classDef data fill:#90EE90,stroke:#333
    classDef external fill:#FFE5B4,stroke:#333
    classDef worker fill:#DDA0DD,stroke:#333
    classDef database fill:#E6E6FA,stroke:#333

    subgraph Frontend
        UI["UI Components"]
        Player["Player Component"]
        Menu["Menu System"]
        AppState["Application State"]
        ViewMgmt["View Management"]
    end

    subgraph DataManagement
        DBWorker["Database Worker"]
        Stores["Database Stores"]
        Schema["Database Schema"]
        Sync["Sync System"]
        LocalDB[(IndexedDB)]
        WorkerClient["Worker Client"]
        WorkerAPI["Worker API"]
    end

    subgraph DataSource
        DSInterface["Data Source Interface"]
        Jellyfin["Jellyfin Integration"]
    end

    %% Relationships
    UI --> AppState
    UI --> Player
    UI --> Menu
    UI --> ViewMgmt
    AppState --> WorkerClient
    ViewMgmt --> WorkerClient
    WorkerClient --> WorkerAPI
    WorkerAPI --> DBWorker
    DBWorker --> Stores
    DBWorker --> Schema
    DBWorker --> LocalDB
    Sync --> DSInterface
    DSInterface --> Jellyfin
    Sync --> LocalDB

    %% Click events
    click UI "https://github.com/voodoos/ocamix/blob/main//bin/ui.ml"
    click Player "https://github.com/voodoos/ocamix/blob/main//bin/player.ml"
    click Menu "https://github.com/voodoos/ocamix/blob/main//bin/menu.ml"
    click AppState "https://github.com/voodoos/ocamix/blob/main//bin/app_state.ml"
    click ViewMgmt "https://github.com/voodoos/ocamix/blob/main//bin/lwd_view.ml"
    click DBWorker "https://github.com/voodoos/ocamix/blob/main//bin/db_worker/db_worker.ml"
    click Stores "https://github.com/voodoos/ocamix/blob/main//lib/db/stores.ml"
    click Schema "https://github.com/voodoos/ocamix/blob/main//lib/db/generic_schema.ml"
    click Sync "https://github.com/voodoos/ocamix/blob/main//lib/db/sync.ml"
    click WorkerClient "https://github.com/voodoos/ocamix/blob/main//bin/worker_client.ml"
    click WorkerAPI "https://github.com/voodoos/ocamix/blob/main//lib/worker_api/worker_api.ml"
    click DSInterface "https://github.com/voodoos/ocamix/blob/main//lib/data_source/data_source_intf.ml"
    click Jellyfin "https://github.com/voodoos/ocamix/blob/main//lib/data_source/jellyfin.ml"

    %% Style applications
    class UI,Player,Menu,AppState,ViewMgmt frontend
    class DBWorker,Stores,Schema,Sync,WorkerClient,WorkerAPI worker
    class LocalDB database
    class DSInterface,Jellyfin external

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Worker["Worker Component"]:::worker
        Database["Database"]:::database
        External["External Service"]:::external
    end
```
