# wraient/curd architecture

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

- Interactive diagram: https://gitdiagram.com/wraient/curd
- Repository: https://github.com/wraient/curd

## Overview

##### Main Components
- CLI Entry Point – Represent the main command under “cmd/curd/main.go”. This is where user input is collected and command-line options (flags like -rofi, -skip-op, etc.) are interpreted.
- Core Business Logic – Inside the “internal” directory, several Go modules implement the core functionalities:
– Anime Retrieval and Listing (internal/anime_list.go, internal/episode_list.go, internal/episode_url.go)
– API Integrations for Anilist, AniSkip, Jikan, and others (internal/anilist.go, internal/aniskip.go, internal/jikan.go, etc.)
– Media Player Integration (internal/player.go) that interfaces with mpv.
– Discord Integration (internal/discord.go) managing the rich presence updates.
– UI & Selection Menu Components (internal/rofi.go, internal/selection_menu.go) for Rofi support and image preview features.
– Config and State Management (internal/config.go, internal/localTracking.go, internal/globals.go, internal/structs.go) handling configuration file reading (“~/.config/curd/curd.conf”) and local history data storage.
– Platform Specific IPC Modules (internal/unix_ipc.go and internal/windows_ipc.go) that manage interprocess or system-specific communications, ensuring compatibility on both Linux and Windows.

##### External Dependencies and Build Artifacts
- Build Directory – Contains binaries or scripts for different platforms and architectures (build targets for Linux, macOS, Windows). This can be abstracted as a “Deployment/Build” component separate from the core logic.

##### Relationships and Data Flow
- From there, data flows into respective modules: a module might call API handlers (for example, querying the AniSkip API to determine skipping times, or updating user progress via the Anilist API) and interact with the player module to launch mpv.
- Additionally, configuration management and UI selection via Rofi have bidirectional interactions – the application reads configuration settings on startup and might update them based on user choices.
- Build process separately to indicate how the project is packaged for different platforms.

##### Architectural Patterns and Design Principles
- Modularity: The clearly separated packages (cmd vs. internal) suggest a modular design where each functionality (API integration, config, UI) is isolated.
- Cross-Platform Considerations: Inclusion of separate files for unix and windows IPC shows that the design accommodates platform-specific differences.
- Dependency Management: The use of Go modules (go.mod, go.sum) and alternative build approaches (Flakes via flake.nix and package.nix) is important for reproducible builds.

- A Block for “CLI Entry Point” (cmd/curd/main.go) showing initial command parsing and flag resolution.
- A block that aggregates “Core Modules” from the internal directory, subdividing it into:
– API Integration Modules (anilist.go, aniskip.go, jikan.go)
– Player & Media Handling (player.go)
– UI Handling (rofi.go, selection_menu.go)
– Config & State Management (config.go, globals.go, localTracking.go)
– Platform-Specific Integrations (unix_ipc.go, windows_ipc.go)
- A block showing “External Dependencies” (mpv, rofi, ueberzugpp) connected to the player and UI components.
- A separate “Build & Deployment” section showing the Build directory and its different platform targets.
- A block for configuration files and persistent storage (“~/.config/curd/curd.conf”) linked to configuration management modules.

##### Additional Notes
- Don’t shy away from being as detailed as possible. Every module observed in the file tree (and noted in the README for its functionality) should be represented to provide a clear architectural picture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface / CLI Layer
    CLI["CLI Entry Point"]:::cliLayer

    %% Core Business Logic Layer
    subgraph "Core Business Logic"
        AnimeList["Anime Listing Module"]:::businessLayer
        subgraph "API Integrations"
            Anilist["Anilist Integration"]:::businessLayer
            AniSkip["AniSkip Integration"]:::businessLayer
            Jikan["Jikan Integration"]:::businessLayer
        end
        Player["Media Player Integration"]:::businessLayer
        Discord["Discord Integration"]:::businessLayer
        subgraph "UI Components"
            Rofi["Rofi Support"]:::businessLayer
            SelMenu["Selection Menu"]:::businessLayer
        end
        Config["Config & State Management"]:::businessLayer
        subgraph "Platform-Specific IPC"
            UnixIPC["Unix IPC"]:::businessLayer
            WindowsIPC["Windows IPC"]:::businessLayer
        end
    end

    %% External Systems Layer
    subgraph "External Systems"
        MPV["mpv"]:::externalLayer
        RofiDep["rofi"]:::externalLayer
        Ueber["ueberzugpp"]:::externalLayer
        AnilistAPI["Anilist API"]:::externalLayer
        AniSkipAPI["AniSkip API"]:::externalLayer
        JikanAPI["Jikan API"]:::externalLayer
        AllAnimeAPI["AllAnime API"]:::externalLayer
    end

    %% Build & Deployment Layer
    subgraph "Build & Deployment"
        Build["Build Artifacts"]:::buildLayer
    end

    %% Configuration File (persistent storage)
    ConfigFile["User Config (~/.config/curd/curd.conf)"]:::businessLayer

    %% Additional UI Assets
    subgraph "Rofi UI Assets"
        RofiAnime["selectanime.rasi"]:::businessLayer
        RofiPreview["selectanimepreview.rasi"]:::businessLayer
        RofiInput["userinput.rasi"]:::businessLayer
    end

    %% Data Flow Connections

    %% CLI Layer to Core Business Logic
    CLI -->|"parseCommand"| AnimeList
    CLI -->|"loadConfig"| Config
    CLI -->|"launchPlayer"| Player
    CLI -->|"initDiscord"| Discord
    CLI -->|"showUI"| Rofi
    CLI -->|"displayMenu"| SelMenu

    %% Core internal interconnections
    AnimeList -->|"fetchDetails"| Anilist
    AnimeList -->|"determineSkip"| AniSkip
    AnimeList -->|"lookupEpisodes"| Jikan

    %% API integrations to External APIs
    Anilist -->|"callAPI"| AnilistAPI
    AniSkip -->|"callAPI"| AniSkipAPI
    Jikan -->|"callAPI"| JikanAPI
    Jikan -->|"fetchContent"| AllAnimeAPI

    %% Media player and UI external dependencies
    Player -->|"playMedia"| MPV
    Rofi -->|"invokeRofi"| RofiDep
    SelMenu -->|"previewImages"| Ueber

    %% Config interactions with persistent storage
    Config <-->|"readWrite"| ConfigFile

    %% Click Events
    click CLI "https://github.com/wraient/curd/blob/main/cmd/curd/main.go"
    click AnimeList "https://github.com/wraient/curd/blob/main/internal/anime_list.go"
    click Anilist "https://github.com/wraient/curd/blob/main/internal/anilist.go"
    click AniSkip "https://github.com/wraient/curd/blob/main/internal/aniskip.go"
    click Jikan "https://github.com/wraient/curd/blob/main/internal/jikan.go"
    click Player "https://github.com/wraient/curd/blob/main/internal/player.go"
    click Discord "https://github.com/wraient/curd/blob/main/internal/discord.go"
    click Rofi "https://github.com/wraient/curd/blob/main/internal/rofi.go"
    click SelMenu "https://github.com/wraient/curd/blob/main/internal/selection_menu.go"
    click RofiAnime "https://github.com/wraient/curd/blob/main/rofi/selectanime.rasi"
    click RofiPreview "https://github.com/wraient/curd/blob/main/rofi/selectanimepreview.rasi"
    click RofiInput "https://github.com/wraient/curd/blob/main/rofi/userinput.rasi"
    click Config "https://github.com/wraient/curd/blob/main/internal/config.go"
    click UnixIPC "https://github.com/wraient/curd/blob/main/internal/unix_ipc.go"
    click WindowsIPC "https://github.com/wraient/curd/blob/main/internal/windows_ipc.go"
    click Build "https://github.com/wraient/curd/tree/main/Build/"

    %% Styles
    classDef cliLayer fill:#ffcc00,stroke:#333,stroke-width:2px,color:#000;
    classDef businessLayer fill:#ccffcc,stroke:#333,stroke-width:2px,color:#000;
    classDef externalLayer fill:#cce5ff,stroke:#333,stroke-width:2px,color:#000;
    classDef buildLayer fill:#f0e68c,stroke:#333,stroke-width:2px,color:#000;
```
