# serene-brew/kaizen architecture

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

- Interactive diagram: https://gitdiagram.com/serene-brew/kaizen
- Repository: https://github.com/serene-brew/kaizen

## Overview

##### Project type and purpose
- Kaizen is a Go-based TUI (terminal user interface) application for streaming anime directly in the command line.
- It consumes a private home-grown API to fetch anime metadata and stream URLs, then launches an external video player.
- It is not a full-stack web app but a single-binary CLI tool with a presentation layer (TUI), application-logic layer, and an external service dependency (the anime API and video player).

##### File structure
- Top-level files:
- main.go – program entry point, bootstraps configuration and TUI.
- install.sh / update.sh / uninstall.sh – lifecycle scripts.
- Go module files (go.mod, go.sum), CI/CD workflows (in .github/workflows).
- src/ directory holds the core application:
- APIcore.go – HTTP client code for interacting with the anime API.
- config.go – code to load user config from ~/.config/kaizen/config.yaml.
- mainModel.go, appState_test.go – the core model/state of the TUI.
- HelpMenu.go, InfoBox.go, WatchAnime.go, about.go – UI components.
- keymap.go, componentFocus_test.go – input handling, focus logic.
- styles.go – theme definitions.
- utils.go, shared.go – common utilities and types.
- Tests are co-located with their components for unit testing.

##### README for additional insights
- Describes user flows: search anime, browse SUB/DUB episodes, launch player.
- Mentions configuration directory, keybindings, and known display-size constraints.
- Confirms reliance on a “home‐grown” confidential API.

##### Elements
- Clear labels on each component (e.g., “TUI: WatchAnime”, “API Client”, “Config Loader”).
- Startup flow (main.go → Config Loader → MainModel).
- Data flow (MainModel ↔ API Client).
- Control flow (User Input → Keymap → MainModel → UI update).
- Process invocation (MainModel → External Video Player).
- Another for application/core-logic.
- A third for external services (API, player).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry & Bootstrapping
    subgraph "Entry & Bootstrapping"
        MainGo["main.go"]:::core
    end

    %% Configuration
    subgraph "Configuration Loader"
        ConfigGO["src/config.go"]:::config
        ConfigYAML["config.yaml"]:::config
    end

    %% Presentation Layer
    subgraph "Presentation Layer (TUI)"
        subgraph "UI Components"
            HelpMenu["HelpMenu"]:::presentation
            InfoBox["InfoBox"]:::presentation
            WatchAnime["WatchAnime"]:::presentation
            About["about"]:::presentation
        end
        subgraph "Input Handling / Controller"
            Keymap["keymap"]:::presentation
            FocusTest["componentFocus_test.go"]:::presentation
        end
    end

    %% Core Logic
    subgraph "Application / Core Logic"
        MainModel["mainModel"]:::core
        AppStateTest["appState_test.go"]:::core
    end

    %% Utilities & Shared Types
    subgraph "Utilities & Shared"
        Utils["utils"]:::core
        Shared["shared"]:::core
        Styles["styles"]:::core
    end

    %% External Interaction
    subgraph "External Interaction"
        APIClient["API Client"]:::external
        Player["External Video Player"]:::external
    end

    %% Lifecycle & Distribution Scripts
    subgraph "Lifecycle & Distribution Scripts"
        Install["install.sh"]:::infra
        Update["update.sh"]:::infra
        Uninstall["uninstall.sh"]:::infra
    end

    %% CI/CD Workflows
    subgraph "CI/CD Workflows"
        GoTest[".github/workflows/go-test.yml"]:::infra
        Lint[".github/workflows/golangci-lint.yml"]:::infra
        Release[".github/workflows/goreleaser.yml"]:::infra
    end

    %% Relationships
    MainGo -->|bootstraps| ConfigGO
    ConfigGO -->|reads| ConfigYAML
    MainGo -->|initializes| MainModel
    Keymap -->|captures input| MainModel
    FocusTest -->|validates focus| Keymap
    MainModel -->|fetch data| APIClient
    APIClient -->|returns data| MainModel
    MainModel -->|updates view| HelpMenu
    MainModel -->|updates view| InfoBox
    MainModel -->|updates view| WatchAnime
    MainModel -->|updates view| About
    MainModel -->|uses| Utils
    Utils -->|spawns| Player
    Player -->|exit event| MainModel

    Install --> MainGo
    Update --> MainGo
    Uninstall --> MainGo

    GoTest --> MainModel
    GoTest --> Keymap
    Lint --> MainModel
    Release --> MainGo

    %% Click Events
    click MainGo "https://github.com/serene-brew/kaizen/blob/main/main.go"
    click ConfigGO "https://github.com/serene-brew/kaizen/blob/main/src/config.go"
    click ConfigYAML "https://github.com/serene-brew/kaizen/blob/main/config.yaml"
    click HelpMenu "https://github.com/serene-brew/kaizen/blob/main/src/HelpMenu.go"
    click InfoBox "https://github.com/serene-brew/kaizen/blob/main/src/InfoBox.go"
    click WatchAnime "https://github.com/serene-brew/kaizen/blob/main/src/WatchAnime.go"
    click About "https://github.com/serene-brew/kaizen/blob/main/src/about.go"
    click Keymap "https://github.com/serene-brew/kaizen/blob/main/src/keymap.go"
    click FocusTest "https://github.com/serene-brew/kaizen/blob/main/src/componentFocus_test.go"
    click MainModel "https://github.com/serene-brew/kaizen/blob/main/src/mainModel.go"
    click AppStateTest "https://github.com/serene-brew/kaizen/blob/main/src/appState_test.go"
    click Utils "https://github.com/serene-brew/kaizen/blob/main/src/utils.go"
    click Shared "https://github.com/serene-brew/kaizen/blob/main/src/shared.go"
    click Styles "https://github.com/serene-brew/kaizen/blob/main/src/styles.go"
    click APIClient "https://github.com/serene-brew/kaizen/blob/main/src/APIcore.go"

    click Install "https://github.com/serene-brew/kaizen/blob/main/install.sh"
    click Update "https://github.com/serene-brew/kaizen/blob/main/update.sh"
    click Uninstall "https://github.com/serene-brew/kaizen/blob/main/uninstall.sh"

    click GoTest "https://github.com/serene-brew/kaizen/blob/main/.github/workflows/go-test.yml"
    click Lint "https://github.com/serene-brew/kaizen/blob/main/.github/workflows/golangci-lint.yml"
    click Release "https://github.com/serene-brew/kaizen/blob/main/.github/workflows/goreleaser.yml"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#3399ff,color:#000
    classDef core fill:#d4edda,stroke:#28a745,color:#000
    classDef external fill:#fff3cd,stroke:#ffc107,color:#000
    classDef config fill:#ffe5b4,stroke:#ff8c00,color:#000
    classDef infra fill:#e2e3e5,stroke:#6c757d,color:#000
```
