# embittered01/spotigod architecture

> Architecture diagram of the GitHub repository embittered01/spotigod, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/embittered01/spotigod
- Repository: https://github.com/embittered01/spotigod

## Overview

#### Purpose and Entry Point
SpotiGod is a Rust terminal client for controlling a Spotify account: playback, search, playlists, saved tracks, and playback settings. The executable starts at `src/main.rs`, which composes configuration, Spotify access, and terminal UI.

#### Runtime and External Boundary
The application runs as a native Rust CLI/TUI process built through Cargo (`Cargo.toml`). It integrates with Spotify’s Web API and OAuth application registration using client credentials and a localhost redirect URI. User-provided credentials are loaded from a local `config.json`; configuration handling is centralized in `src/config/mod.rs`.

#### Application Composition
`src/main.rs` is the top-level control boundary: it initializes dependencies, establishes the Spotify client/session, and enters the interactive terminal workflow. It should remain the composition root rather than carrying API or rendering details.

#### Spotify Integration Layer
`src/spotify/mod.rs` defines the Spotify subsystem boundary. `src/spotify/client.rs` is the API-facing client responsible for authentication and Spotify operations such as playback control, search, playlist retrieval, favorites, volume, shuffle, and repeat. `src/spotify/models.rs` contains domain/API data representations passed between the client layer and UI.

#### Terminal UI and Interaction
`src/ui/mod.rs` owns terminal presentation and keyboard-driven navigation. It maps the documented controls into actions—screen selection, transport controls, search, and settings—and invokes the Spotify layer rather than directly handling authentication or HTTP. The UI is the primary long-running event/control loop after startup.

#### Primary Flow
1. Startup in `src/main.rs` loads credentials through `src/config/mod.rs`.
2. The application constructs the Spotify integration from `src/spotify/client.rs`.
3. `src/ui/mod.rs` renders the active terminal view and accepts keyboard input.
4. User actions are translated to Spotify client calls; responses are represented with types from `src/spotify/models.rs`.
5. Updated playback, search, playlist, or library state is returned to the UI for display.

#### Architectural Boundaries
Configuration is isolated from application behavior in `src/config/mod.rs`. Spotify API communication and its models are grouped under `src/spotify/`, separating remote-service concerns from terminal interaction under `src/ui/`. The main executable in `src/main.rs` coordinates those subsystems and is the appropriate location for lifecycle and fatal-error handling.

Main entry points: [`src/spotify/client.rs`](https://github.com/embittered01/spotigod/blob/main/src/spotify/client.rs) (Spotify Client), [`src/main.rs`](https://github.com/embittered01/spotigod/blob/main/src/main.rs) (Application Entry), [`src/ui/mod.rs`](https://github.com/embittered01/spotigod/blob/main/src/ui/mod.rs) (Terminal UI), [`src/spotify/models.rs`](https://github.com/embittered01/spotigod/blob/main/src/spotify/models.rs) (Spotify Models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_spotify["Spotify Integration"]
  node_spotify_client["Spotify Client<br/>API client<br/>[client.rs]"]
  node_spotify_models["Spotify Models<br/>domain models<br/>[models.rs]"]
  node_spotify_module["Spotify Subsystem<br/>module boundary<br/>[mod.rs]"]
end

subgraph group_ui["Terminal UI"]
  node_ui_module["Terminal UI<br/>event loop<br/>[mod.rs]"]
end

node_cargo["Cargo Build<br/>Rust package<br/>[Cargo.toml]"]
node_main["Application Entry<br/>composition root<br/>[main.rs]"]
node_config["Configuration<br/>credentials loader<br/>[mod.rs]"]
node_spotify_api{{"Spotify Web API<br/>external service"}}
node_spotify_oauth{{"Spotify OAuth<br/>external identity"}}
node_terminal_user(("Terminal User<br/>actor"))

node_cargo -->|"builds"| node_main
node_main -->|"loads credentials"| node_config
node_main -->|"constructs session"| node_spotify_client
node_main -->|"starts workflow"| node_ui_module
node_terminal_user -->|"keyboard input"| node_ui_module
node_ui_module -->|"invokes actions"| node_spotify_client
node_spotify_client -->|"uses"| node_spotify_models
node_spotify_models -->|"display state"| node_ui_module
node_spotify_module -.->|"contains"| node_spotify_client
node_spotify_module -.->|"contains"| node_spotify_models
node_spotify_client -->|"authorizes via"| node_spotify_oauth
node_spotify_client -->|"calls"| node_spotify_api

click node_cargo "https://github.com/embittered01/spotigod/blob/main/Cargo.toml"
click node_main "https://github.com/embittered01/spotigod/blob/main/src/main.rs"
click node_config "https://github.com/embittered01/spotigod/blob/main/src/config/mod.rs"
click node_ui_module "https://github.com/embittered01/spotigod/blob/main/src/ui/mod.rs"
click node_spotify_client "https://github.com/embittered01/spotigod/blob/main/src/spotify/client.rs"
click node_spotify_models "https://github.com/embittered01/spotigod/blob/main/src/spotify/models.rs"
click node_spotify_module "https://github.com/embittered01/spotigod/blob/main/src/spotify/mod.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spotify_client,node_spotify_models,node_spotify_module toneBlue
class node_ui_module toneAmber
class node_cargo,node_main,node_config,node_spotify_api,node_spotify_oauth,node_terminal_user toneNeutral
```

## Components

### Spotify Integration

Remote API access and shared Spotify data.

- [Spotify Client](https://github.com/embittered01/spotigod/blob/main/src/spotify/client.rs): API client · Authenticates and performs playback, search, library, and settings operations. · `src/spotify/client.rs`
- [Spotify Models](https://github.com/embittered01/spotigod/blob/main/src/spotify/models.rs): domain models · API and domain representations exchanged with the UI. · `src/spotify/models.rs`
- [Spotify Subsystem](https://github.com/embittered01/spotigod/blob/main/src/spotify/mod.rs): module boundary · Groups remote-service access and data models. · `src/spotify/mod.rs`

### Terminal UI

Interactive terminal presentation and controls.

- [Terminal UI](https://github.com/embittered01/spotigod/blob/main/src/ui/mod.rs): event loop · Renders views and maps keyboard input to actions. · `src/ui/mod.rs`

### Other components

- [Cargo Build](https://github.com/embittered01/spotigod/blob/main/Cargo.toml): Rust package · `Cargo.toml`
- [Application Entry](https://github.com/embittered01/spotigod/blob/main/src/main.rs): composition root · Initializes dependencies and owns lifecycle handling. · `src/main.rs`
- [Configuration](https://github.com/embittered01/spotigod/blob/main/src/config/mod.rs): credentials loader · Loads local Spotify application credentials. · `src/config/mod.rs`
- **Spotify Web API**: external service · Remote playback, search, playlist, and library service.
- **Spotify OAuth**: external identity · OAuth registration and localhost redirect authorization.
- **Terminal User**: actor

## Connections

- Cargo Build → Application Entry: builds
- Application Entry → Configuration: loads credentials
- Application Entry → Spotify Client: constructs session
- Application Entry → Terminal UI: starts workflow
- Terminal User → Terminal UI: keyboard input
- Terminal UI → Spotify Client: invokes actions
- Spotify Client → Spotify Models: uses
- Spotify Models → Terminal UI: display state
- Spotify Subsystem → Spotify Client: contains
- Spotify Subsystem → Spotify Models: contains
- Spotify Client → Spotify OAuth: authorizes via
- Spotify Client → Spotify Web API: calls
