# andrew82mm/ai-wrapped architecture

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

- Interactive diagram: https://gitdiagram.com/andrew82mm/ai-wrapped
- Repository: https://github.com/andrew82mm/ai-wrapped

## Overview

AI-Wrapped turns a Last.fm username and listening period into a personalized editorial report. The web server or CLI orchestrates profile retrieval, metadata enrichment, behavioral analysis, narrative generation, and report presentation. The README documents the overall pipeline and feature set; sampled source confirms key orchestration and provider relationships. Some feature internals and browser wiring were not sampled, so those links reflect documented behavior rather than inspected calls.

Main entry points: [`frontend/server.py`](https://github.com/andrew82mm/ai-wrapped/blob/main/frontend/server.py) (Web API), [`wrapped.py`](https://github.com/andrew82mm/ai-wrapped/blob/main/wrapped.py) (CLI pipeline), [`src/metadata/provider.py`](https://github.com/andrew82mm/ai-wrapped/blob/main/src/metadata/provider.py) (Track resolver), [`src/narrative/generate.py`](https://github.com/andrew82mm/ai-wrapped/blob/main/src/narrative/generate.py) (Narrative generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_web["Web API<br/>[server.py]"]
  node_cli["CLI pipeline<br/>[wrapped.py]"]
end

subgraph group_listening["Listening data"]
  node_lastfm["Last.fm history<br/>[client.py]"]
  node_sessions["Session detector<br/>[sessions.py]"]
  node_cache[("Per-user cache<br/>[cache.py]")]
end

subgraph group_enrichment["Metadata enrichment"]
  node_metadata["Track resolver<br/>[provider.py]"]
  node_musicbrainz["Recording metadata<br/>[client.py]"]
  node_acousticbrainz["Audio features<br/>[client.py]"]
  node_genius["Song context<br/>[client.py]"]
  node_http["HTTP client base<br/>[http.py]"]
end

subgraph group_analysis["Analysis and narrative"]
  node_features["Behavioral features"]
  node_narrative["Narrative generator<br/>[generate.py]"]
  node_narrative_context["Narrative context<br/>[context.py]"]
  node_narrative_prompt["Prompt builder<br/>[prompt.py]"]
  node_narrative_verify["Name verifier<br/>[verify.py]"]
end

subgraph group_presentation["Report presentation"]
  node_browser["Web interface<br/>[index.html]"]
  node_render["Report formatter<br/>[render.py]"]
  node_demo["Demo report data<br/>[demo.py]"]
end

node_user(("Listener"))
node_lastfm_service(("Last.fm API"))
node_musicbrainz_service(("MusicBrainz API"))
node_acousticbrainz_service(("AcousticBrainz API"))
node_genius_service(("Genius API"))
node_llm(("OpenAI-compatible LLM"))

node_user -->|"submits username"| node_web
node_user -->|"runs report"| node_cli
node_browser -->|"requests report"| node_web
node_web -->|"runs pipeline"| node_lastfm
node_cli -->|"fetches profile"| node_lastfm
node_lastfm -->|"fetches scrobbles"| node_lastfm_service
node_cli -->|"detects sessions"| node_sessions
node_web -->|"loads session data"| node_sessions
node_cli -->|"enriches tracks"| node_metadata
node_web -->|"enriches tracks"| node_metadata
node_metadata -->|"resolves recordings"| node_musicbrainz
node_metadata -->|"fetches audio features"| node_acousticbrainz
node_metadata -->|"looks up release year"| node_genius
node_metadata -->|"reads and writes"| node_cache
node_musicbrainz -->|"searches recordings"| node_musicbrainz_service
node_acousticbrainz -->|"fetches classifiers"| node_acousticbrainz_service
node_genius -->|"searches songs"| node_genius_service
node_musicbrainz -->|"uses client base"| node_http
node_acousticbrainz -->|"uses client base"| node_http
node_genius -->|"uses client base"| node_http
node_cli -->|"computes features"| node_features
node_web -->|"computes features"| node_features
node_cli -->|"generates narrative"| node_narrative
node_web -->|"generates narrative"| node_narrative
node_narrative -->|"builds context"| node_narrative_context
node_narrative -->|"builds prompts"| node_narrative_prompt
node_narrative -->|"checks names"| node_narrative_verify
node_narrative -->|"requests completion"| node_llm
node_cli -->|"formats report"| node_render
node_web -->|"formats report"| node_render
node_browser -->|"loads demo report"| node_demo

click node_web "https://github.com/andrew82mm/ai-wrapped/blob/main/frontend/server.py"
click node_cli "https://github.com/andrew82mm/ai-wrapped/blob/main/wrapped.py"
click node_browser "https://github.com/andrew82mm/ai-wrapped/blob/main/frontend/index.html"
click node_lastfm "https://github.com/andrew82mm/ai-wrapped/blob/main/src/lastfm/client.py"
click node_sessions "https://github.com/andrew82mm/ai-wrapped/blob/main/src/lastfm/sessions.py"
click node_cache "https://github.com/andrew82mm/ai-wrapped/blob/main/src/lastfm/cache.py"
click node_metadata "https://github.com/andrew82mm/ai-wrapped/blob/main/src/metadata/provider.py"
click node_musicbrainz "https://github.com/andrew82mm/ai-wrapped/blob/main/src/musicbrainz/client.py"
click node_acousticbrainz "https://github.com/andrew82mm/ai-wrapped/blob/main/src/acousticbrainz/client.py"
click node_genius "https://github.com/andrew82mm/ai-wrapped/blob/main/src/genius/client.py"
click node_features "https://github.com/andrew82mm/ai-wrapped/tree/main/src/features"
click node_narrative "https://github.com/andrew82mm/ai-wrapped/blob/main/src/narrative/generate.py"
click node_narrative_context "https://github.com/andrew82mm/ai-wrapped/blob/main/src/narrative/context.py"
click node_narrative_prompt "https://github.com/andrew82mm/ai-wrapped/blob/main/src/narrative/prompt.py"
click node_narrative_verify "https://github.com/andrew82mm/ai-wrapped/blob/main/src/narrative/verify.py"
click node_render "https://github.com/andrew82mm/ai-wrapped/blob/main/frontend/render.py"
click node_demo "https://github.com/andrew82mm/ai-wrapped/blob/main/frontend/demo.py"
click node_http "https://github.com/andrew82mm/ai-wrapped/blob/main/src/common/http.py"

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_web,node_cli toneBlue
class node_lastfm,node_sessions,node_cache toneAmber
class node_metadata,node_musicbrainz,node_acousticbrainz,node_genius,node_http,node_lastfm_service,node_musicbrainz_service,node_acousticbrainz_service,node_genius_service toneMint
class node_features,node_narrative,node_narrative_context,node_narrative_prompt,node_narrative_verify toneRose
class node_browser,node_render,node_demo,node_user,node_llm toneIndigo
```

## Components

### Entry points

- [Web API](https://github.com/andrew82mm/ai-wrapped/blob/main/frontend/server.py): `frontend/server.py`
- [CLI pipeline](https://github.com/andrew82mm/ai-wrapped/blob/main/wrapped.py): `wrapped.py`

### Listening data

- [Last.fm history](https://github.com/andrew82mm/ai-wrapped/blob/main/src/lastfm/client.py): `src/lastfm/client.py`
- [Session detector](https://github.com/andrew82mm/ai-wrapped/blob/main/src/lastfm/sessions.py): `src/lastfm/sessions.py`
- [Per-user cache](https://github.com/andrew82mm/ai-wrapped/blob/main/src/lastfm/cache.py): `src/lastfm/cache.py`

### Metadata enrichment

- [Track resolver](https://github.com/andrew82mm/ai-wrapped/blob/main/src/metadata/provider.py): `src/metadata/provider.py`
- [Recording metadata](https://github.com/andrew82mm/ai-wrapped/blob/main/src/musicbrainz/client.py): `src/musicbrainz/client.py`
- [Audio features](https://github.com/andrew82mm/ai-wrapped/blob/main/src/acousticbrainz/client.py): `src/acousticbrainz/client.py`
- [Song context](https://github.com/andrew82mm/ai-wrapped/blob/main/src/genius/client.py): `src/genius/client.py`
- [HTTP client base](https://github.com/andrew82mm/ai-wrapped/blob/main/src/common/http.py): `src/common/http.py`

### Analysis and narrative

- [Behavioral features](https://github.com/andrew82mm/ai-wrapped/tree/main/src/features): `src/features`
- [Narrative generator](https://github.com/andrew82mm/ai-wrapped/blob/main/src/narrative/generate.py): `src/narrative/generate.py`
- [Narrative context](https://github.com/andrew82mm/ai-wrapped/blob/main/src/narrative/context.py): `src/narrative/context.py`
- [Prompt builder](https://github.com/andrew82mm/ai-wrapped/blob/main/src/narrative/prompt.py): `src/narrative/prompt.py`
- [Name verifier](https://github.com/andrew82mm/ai-wrapped/blob/main/src/narrative/verify.py): `src/narrative/verify.py`

### Report presentation

- [Web interface](https://github.com/andrew82mm/ai-wrapped/blob/main/frontend/index.html): `frontend/index.html`
- [Report formatter](https://github.com/andrew82mm/ai-wrapped/blob/main/frontend/render.py): `frontend/render.py`
- [Demo report data](https://github.com/andrew82mm/ai-wrapped/blob/main/frontend/demo.py): `frontend/demo.py`

### Other components

- **Listener**
- **Last.fm API**
- **MusicBrainz API**
- **AcousticBrainz API**
- **Genius API**
- **OpenAI-compatible LLM**

## Connections

- Listener → Web API: submits username (evidence: `README.md`)
- Listener → CLI pipeline: runs report (evidence: `README.md`)
- Web interface → Web API: requests report (evidence: `README.md`)
- Web API → Last.fm history: runs pipeline (evidence: `frontend/server.py`)
- CLI pipeline → Last.fm history: fetches profile (evidence: `wrapped.py`)
- Last.fm history → Last.fm API: fetches scrobbles (evidence: `src/lastfm/client.py`)
- CLI pipeline → Session detector: detects sessions (evidence: `wrapped.py`)
- Web API → Session detector: loads session data (evidence: `frontend/server.py`)
- CLI pipeline → Track resolver: enriches tracks (evidence: `wrapped.py`)
- Web API → Track resolver: enriches tracks (evidence: `frontend/server.py`)
- Track resolver → Recording metadata: resolves recordings (evidence: `src/metadata/provider.py`)
- Track resolver → Audio features: fetches audio features (evidence: `src/metadata/provider.py`)
- Track resolver → Song context: looks up release year (evidence: `src/metadata/provider.py`)
- Track resolver → Per-user cache: reads and writes (evidence: `src/metadata/provider.py`)
- Recording metadata → MusicBrainz API: searches recordings (evidence: `src/musicbrainz/client.py`)
- Audio features → AcousticBrainz API: fetches classifiers (evidence: `src/acousticbrainz/client.py`)
- Song context → Genius API: searches songs (evidence: `src/genius/client.py`)
- Recording metadata → HTTP client base: uses client base (evidence: `src/musicbrainz/client.py`)
- Audio features → HTTP client base: uses client base (evidence: `src/acousticbrainz/client.py`)
- Song context → HTTP client base: uses client base (evidence: `src/genius/client.py`)
- CLI pipeline → Behavioral features: computes features (evidence: `wrapped.py`)
- Web API → Behavioral features: computes features (evidence: `frontend/server.py`)
- CLI pipeline → Narrative generator: generates narrative (evidence: `wrapped.py`)
- Web API → Narrative generator: generates narrative (evidence: `frontend/server.py`)
- Narrative generator → Narrative context: builds context (evidence: `src/narrative/generate.py`)
- Narrative generator → Prompt builder: builds prompts (evidence: `src/narrative/generate.py`)
- Narrative generator → Name verifier: checks names (evidence: `src/narrative/generate.py`)
- Narrative generator → OpenAI-compatible LLM: requests completion (evidence: `src/narrative/generate.py`)
- CLI pipeline → Report formatter: formats report (evidence: `wrapped.py`)
- Web API → Report formatter: formats report (evidence: `frontend/server.py`)
- Web interface → Demo report data: loads demo report
