# yyoshiki41/radigo architecture

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

- Interactive diagram: https://gitdiagram.com/yyoshiki41/radigo
- Repository: https://github.com/yyoshiki41/radigo

## Overview

##### Project Purpose and Type
- radigo is a command‐line tool written in Go for recording programs streamed by radiko.jp.
- It exposes multiple commands (such as “area”, “browse”, “rec”, “rec-live”, etc.) to allow users to list available stations, record time-shifted programs, and capture live streams.
- It also supports Docker usage and relies on an external tool (ffmpeg) for processing audio streams.

##### Analyzing the File Structure
- Top-Level Files: Files like area.go, audio_format.go, browse.go, rec.go, and similar files indicate that logic for each command is split into separate modules.
- cmd Directory: Contains the main entry-point (cmd/radigo/main.go) which bootstraps the CLI application. This is where argument parsing and command routing occur.
- Other files: Client, ffmpeg integration (ffmpeg.go), and output modules indicate different layers interacting with external systems (ffmpeg and radiko.jp).
- Build and Deployment: Presence of Dockerfile, CircleCI config, Makefile, and scripts indicates that the project is built with continuous integration in mind and is containerized for portability.

##### Components & Relationships
- CLI & Command Interface:
- Represents the entry point (cmd/radigo/main.go) where user input is parsed.
- The CLI routing directs to different commands (area, browse, rec, rec-live).
- Command Modules:
- Each command (for example, area.go, browse.go, rec.go, rec_live.go) forms a component.
- These components handle specific tasks like interacting with radiko.jp for listings or recording programs.
- Core Processing/Logic Modules:
- Modules like client.go, audio_format.go, output.go, and radigo.go represent the core processing logic.
- Commands delegate to these modules to perform tasks such as network requests, download handling, and audio processing.
- Internal Services:
- Under internal/download.go and internal/util.go reside common helper functions.
- They provide support for file downloads, data manipulation, and utility processing.
- External Dependencies:
- ffmpeg (referenced in ffmpeg.go) is an external dependency used for media processing.
- Environment Variables and configuration (RADIGO_HOME, RADIKO_MAIL, RADIKO_PASSWORD) allow for runtime customization.
- Build & Deployment:
- Dockerfile and CI configurations (.circleci/config.yml) can be noted as supporting infrastructure that packages and tests the application.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The codebase is divided between the CLI interface, command-specific modules, and supporting internal libraries.
- Modularity: Each command and supporting functionality is in its own file/module, making it easier to understand the data flow and maintain the system.
- Layered Architecture: Users interact through the CLI (presentation layer), which then delegates commands to the core business logic (application layer), and finally to the utilities and external tools (infrastructure layer).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface / CLI
    subgraph "User Interface/CLI"
        A["CLI / Entry Point"]:::cli
    end

    %% Command Handlers
    subgraph "Command Handlers"
        B["Area Command"]:::command
        C["Browse Command"]:::command
        D["Browse Live Command"]:::command
        E["Record Command"]:::command
        F["Record Live Command"]:::command
    end

    %% Core Processing Modules
    subgraph "Core Processing Modules"
        G["Client Module"]:::core
        H["Audio Format Module"]:::core
        I["Output Module"]:::core
        J["Radigo Logic Module"]:::core
    end

    %% Internal Services
    subgraph "Internal Services"
        K["Download Utilities"]:::internal
        L["Utility Functions"]:::internal
    end

    %% External Dependencies
    subgraph "External Dependencies"
        M["FFMpeg Integration"]:::external
        N["External API (radiko.jp)"]:::external
    end

    %% Build & Deployment
    subgraph "Build & Deployment"
        O["Docker Configuration"]:::deployment
        P["CI/CD Configuration"]:::deployment
        Q["Build Scripts"]:::deployment
    end

    %% Relationships
    %% CLI to Command Handlers
    A -->|"routes"| B
    A -->|"routes"| C
    A -->|"routes"| D
    A -->|"routes"| E
    A -->|"routes"| F

    %% Command Handlers to Core Processing Module (Radigo Logic)
    B -->|"delegates"| J
    C -->|"delegates"| J
    D -->|"delegates"| J
    E -->|"delegates"| J
    F -->|"delegates"| J

    %% Command Handlers interacting with External API for listings
    B -->|"queries"| N
    C -->|"queries"| N
    D -->|"queries"| N

    %% Record commands interacting with FFMpeg and Download Utilities
    E -->|"invokes"| M
    F -->|"invokes"| M
    E -->|"utilizes"| K
    F -->|"utilizes"| K

    %% Core Processing Modules relationships
    J -->|"calls"| G
    J -->|"calls"| H
    J -->|"calls"| I

    %% Internal Services support Core Logic
    K -->|"supports"| J
    L -->|"supports"| J

    %% Build & Deployment supports the system
    Q -->|"builds"| A
    Q -->|"builds"| B
    Q -->|"builds"| C
    Q -->|"builds"| D
    Q -->|"builds"| E
    Q -->|"builds"| F

    %% Click Events for Components
    click A "https://github.com/yyoshiki41/radigo/blob/main/cmd/radigo/main.go"
    click B "https://github.com/yyoshiki41/radigo/blob/main/area.go"
    click C "https://github.com/yyoshiki41/radigo/blob/main/browse.go"
    click D "https://github.com/yyoshiki41/radigo/blob/main/browse_live.go"
    click E "https://github.com/yyoshiki41/radigo/blob/main/rec.go"
    click F "https://github.com/yyoshiki41/radigo/blob/main/rec_live.go"
    click G "https://github.com/yyoshiki41/radigo/blob/main/client.go"
    click H "https://github.com/yyoshiki41/radigo/blob/main/audio_format.go"
    click I "https://github.com/yyoshiki41/radigo/blob/main/output.go"
    click J "https://github.com/yyoshiki41/radigo/blob/main/radigo.go"
    click K "https://github.com/yyoshiki41/radigo/blob/main/internal/download.go"
    click L "https://github.com/yyoshiki41/radigo/blob/main/internal/util.go"
    click M "https://github.com/yyoshiki41/radigo/blob/main/ffmpeg.go"
    click O "https://github.com/yyoshiki41/radigo/tree/main/Dockerfile"
    click P "https://github.com/yyoshiki41/radigo/blob/main/.circleci/config.yml"
    click Q "https://github.com/yyoshiki41/radigo/blob/main/Makefile and scripts/release.sh"

    %% Styles
    classDef cli fill:#f9e79f,stroke:#6c3483,stroke-width:2px;
    classDef command fill:#d5f5e3,stroke:#1e8449,stroke-width:2px;
    classDef core fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef internal fill:#f5cba7,stroke:#d35400,stroke-width:2px;
    classDef external fill:#f1948a,stroke:#c0392b,stroke-width:2px;
    classDef deployment fill:#d2b4de,stroke:#6c3483,stroke-width:2px;
```
