# michaelchung888/audiostash architecture

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

- Interactive diagram: https://gitdiagram.com/michaelchung888/audiostash
- Repository: https://github.com/michaelchung888/audiostash
- Video tour (about a minute): https://gitdiagram.com/michaelchung888/audiostash/video

## Overview

AudioStash is an offline-first Android music library backed by an API and a home-PC worker. The principal workflow is: request a download in the app, queue and process it on the worker, store the audio, then synchronize the resulting library entry and file back to the phone for offline playback. The graph also includes catalog discovery, playlists, and the server/mobile data layers. Some subsystem links are documented only at a high level in the README; unsampled implementation details are not asserted.

Main entry points: [`apps/worker/src/jobs/item.ts`](https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/jobs/item.ts) (Worker job runtime), [`apps/api/src/services/worker-jobs.ts`](https://github.com/michaelchung888/audiostash/blob/main/apps/api/src/services/worker-jobs.ts) (Download orchestration), [`apps/mobile/src/app`](https://github.com/michaelchung888/audiostash/tree/main/apps/mobile/src/app) (Library and discovery UI), [`apps/mobile/src/api`](https://github.com/michaelchung888/audiostash/tree/main/apps/mobile/src/api) (API client and queries)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Android app"]
  node_mobile_ui["Library and discovery UI"]
  node_mobile_api["API client and queries"]
  node_mobile_sync["Two-way sync engine<br/>[engine.ts]"]
  node_phone_db[("Offline library database<br/>[database.ts]")]
  node_phone_files["Music folder mirror"]
  node_player["Offline player and queue"]
end

subgraph group_api["API and data"]
  node_api_app["HTTP API and routing<br/>[app.ts]"]
  node_api_context["Service composition<br/>[context.ts]"]
  node_download_service["Download orchestration<br/>[worker-jobs.ts]"]
  node_catalog_service["Catalog services<br/>[catalog.ts]"]
  node_api_storage["Object storage access<br/>[storage.ts]"]
  node_api_db["Library and job data"]
  node_postgres[("Postgres<br/>[schema.ts]")]
  node_event_stream["Live event stream"]
end

subgraph group_worker["Home worker"]
  node_worker_runtime["Worker job runtime<br/>[item.ts]"]
  node_source_finder["Source resolution<br/>[find-source.ts]"]
  node_youtube_tool["YouTube downloader<br/>[ytdlp.ts]"]
  node_metadata["Metadata and lyrics<br/>[metadata.ts]"]
  node_audio_tools["Audio conversion and tagging<br/>[ffmpeg.ts]"]
  node_worker_api["Worker API client<br/>[client.ts]"]
end

subgraph group_shared["Shared packages"]
  node_queue["Job queues and events<br/>[jobs.ts]"]
  node_catalog_clients["Music catalog clients"]
  node_contracts["Shared request and event shapes<br/>[common.ts]"]
  node_core_logic["Matching and path logic<br/>[match.ts]"]
end

node_listener(("Music listener"))
node_object_store[("Object storage")]

node_listener -->|"requests music"| node_mobile_ui
node_mobile_ui -->|"requests downloads"| node_mobile_api
node_mobile_api -->|"calls API"| node_api_app
node_api_app -->|"uses services"| node_api_context
node_api_app -->|"routes worker actions"| node_download_service
node_download_service -->|"enqueues jobs"| node_queue
node_queue -->|"dispatches jobs"| node_worker_runtime
node_worker_runtime -->|"finds source"| node_source_finder
node_source_finder -->|"probes and downloads"| node_youtube_tool
node_worker_runtime -->|"looks up metadata"| node_metadata
node_worker_runtime -->|"processes audio"| node_audio_tools
node_worker_runtime -->|"reports completion"| node_worker_api
node_worker_api -->|"posts worker updates"| node_api_app
node_download_service -->|"records results"| node_api_db
node_api_db -->|"reads and writes"| node_postgres
node_download_service -->|"requests upload access"| node_api_storage
node_api_storage -->|"signs object access"| node_object_store
node_worker_runtime -->|"uploads audio"| node_object_store
node_download_service -->|"publishes updates"| node_event_stream
node_event_stream -->|"streams events"| node_mobile_api
node_mobile_api -->|"syncs library"| node_mobile_sync
node_mobile_sync -->|"applies changes"| node_phone_db
node_mobile_ui -->|"saves offline files"| node_phone_files
node_phone_files -->|"downloads audio"| node_object_store
node_phone_db -.->|"supplies library"| node_player
node_mobile_ui -->|"searches catalog"| node_catalog_service
node_catalog_service -.->|"queries providers"| node_catalog_clients
node_worker_runtime -->|"consumes jobs"| node_queue
node_worker_runtime -->|"uses job shapes"| node_contracts
node_mobile_sync -->|"uses sync shapes"| node_contracts
node_download_service -->|"uses path logic"| node_core_logic

click node_mobile_ui "https://github.com/michaelchung888/audiostash/tree/main/apps/mobile/src/app"
click node_mobile_api "https://github.com/michaelchung888/audiostash/tree/main/apps/mobile/src/api"
click node_mobile_sync "https://github.com/michaelchung888/audiostash/blob/main/apps/mobile/src/sync/engine.ts"
click node_phone_db "https://github.com/michaelchung888/audiostash/blob/main/apps/mobile/src/db/database.ts"
click node_phone_files "https://github.com/michaelchung888/audiostash/tree/main/apps/mobile/src/files"
click node_player "https://github.com/michaelchung888/audiostash/tree/main/apps/mobile/src/player"
click node_api_app "https://github.com/michaelchung888/audiostash/blob/main/apps/api/src/app.ts"
click node_api_context "https://github.com/michaelchung888/audiostash/blob/main/apps/api/src/context.ts"
click node_download_service "https://github.com/michaelchung888/audiostash/blob/main/apps/api/src/services/worker-jobs.ts"
click node_catalog_service "https://github.com/michaelchung888/audiostash/blob/main/apps/api/src/services/catalog.ts"
click node_api_storage "https://github.com/michaelchung888/audiostash/blob/main/apps/api/src/services/storage.ts"
click node_api_db "https://github.com/michaelchung888/audiostash/tree/main/apps/api/src/db"
click node_postgres "https://github.com/michaelchung888/audiostash/blob/main/packages/db/src/schema.ts"
click node_event_stream "https://github.com/michaelchung888/audiostash/tree/main/apps/api/src/realtime"
click node_queue "https://github.com/michaelchung888/audiostash/blob/main/packages/messaging/src/jobs.ts"
click node_catalog_clients "https://github.com/michaelchung888/audiostash/tree/main/packages/catalog/src"
click node_contracts "https://github.com/michaelchung888/audiostash/blob/main/packages/contracts/src/common.ts"
click node_core_logic "https://github.com/michaelchung888/audiostash/blob/main/packages/core/src/match.ts"
click node_worker_runtime "https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/jobs/item.ts"
click node_source_finder "https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/pipeline/find-source.ts"
click node_youtube_tool "https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/tools/ytdlp.ts"
click node_metadata "https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/pipeline/metadata.ts"
click node_audio_tools "https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/tools/ffmpeg.ts"
click node_worker_api "https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/api/client.ts"

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_mobile_ui,node_mobile_api,node_mobile_sync,node_phone_db,node_phone_files,node_player toneBlue
class node_api_app,node_api_context,node_download_service,node_catalog_service,node_api_storage,node_api_db,node_postgres,node_event_stream,node_object_store toneAmber
class node_worker_runtime,node_source_finder,node_youtube_tool,node_metadata,node_audio_tools,node_worker_api toneMint
class node_queue,node_catalog_clients,node_contracts,node_core_logic toneRose
class node_listener toneIndigo
```

## Components

### Android app

- [Library and discovery UI](https://github.com/michaelchung888/audiostash/tree/main/apps/mobile/src/app): `apps/mobile/src/app`
- [API client and queries](https://github.com/michaelchung888/audiostash/tree/main/apps/mobile/src/api): `apps/mobile/src/api`
- [Two-way sync engine](https://github.com/michaelchung888/audiostash/blob/main/apps/mobile/src/sync/engine.ts): `apps/mobile/src/sync/engine.ts`
- [Offline library database](https://github.com/michaelchung888/audiostash/blob/main/apps/mobile/src/db/database.ts): `apps/mobile/src/db/database.ts`
- [Music folder mirror](https://github.com/michaelchung888/audiostash/tree/main/apps/mobile/src/files): `apps/mobile/src/files`
- [Offline player and queue](https://github.com/michaelchung888/audiostash/tree/main/apps/mobile/src/player): `apps/mobile/src/player`

### API and data

- [HTTP API and routing](https://github.com/michaelchung888/audiostash/blob/main/apps/api/src/app.ts): `apps/api/src/app.ts`
- [Service composition](https://github.com/michaelchung888/audiostash/blob/main/apps/api/src/context.ts): `apps/api/src/context.ts`
- [Download orchestration](https://github.com/michaelchung888/audiostash/blob/main/apps/api/src/services/worker-jobs.ts): `apps/api/src/services/worker-jobs.ts`
- [Catalog services](https://github.com/michaelchung888/audiostash/blob/main/apps/api/src/services/catalog.ts): `apps/api/src/services/catalog.ts`
- [Object storage access](https://github.com/michaelchung888/audiostash/blob/main/apps/api/src/services/storage.ts): `apps/api/src/services/storage.ts`
- [Library and job data](https://github.com/michaelchung888/audiostash/tree/main/apps/api/src/db): `apps/api/src/db`
- [Postgres](https://github.com/michaelchung888/audiostash/blob/main/packages/db/src/schema.ts): `packages/db/src/schema.ts`
- [Live event stream](https://github.com/michaelchung888/audiostash/tree/main/apps/api/src/realtime): `apps/api/src/realtime`

### Home worker

- [Worker job runtime](https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/jobs/item.ts): `apps/worker/src/jobs/item.ts`
- [Source resolution](https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/pipeline/find-source.ts): `apps/worker/src/pipeline/find-source.ts`
- [YouTube downloader](https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/tools/ytdlp.ts): `apps/worker/src/tools/ytdlp.ts`
- [Metadata and lyrics](https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/pipeline/metadata.ts): `apps/worker/src/pipeline/metadata.ts`
- [Audio conversion and tagging](https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/tools/ffmpeg.ts): `apps/worker/src/tools/ffmpeg.ts`
- [Worker API client](https://github.com/michaelchung888/audiostash/blob/main/apps/worker/src/api/client.ts): `apps/worker/src/api/client.ts`

### Shared packages

- [Job queues and events](https://github.com/michaelchung888/audiostash/blob/main/packages/messaging/src/jobs.ts): `packages/messaging/src/jobs.ts`
- [Music catalog clients](https://github.com/michaelchung888/audiostash/tree/main/packages/catalog/src): `packages/catalog/src`
- [Shared request and event shapes](https://github.com/michaelchung888/audiostash/blob/main/packages/contracts/src/common.ts): `packages/contracts/src/common.ts`
- [Matching and path logic](https://github.com/michaelchung888/audiostash/blob/main/packages/core/src/match.ts): `packages/core/src/match.ts`

### Other components

- **Music listener**
- **Object storage**

## Connections

- Music listener → Library and discovery UI: requests music
- Library and discovery UI → API client and queries: requests downloads (evidence: `apps/mobile/src/app/(tabs)/search.tsx`)
- API client and queries → HTTP API and routing: calls API
- HTTP API and routing → Service composition: uses services (evidence: `apps/api/src/app.ts`)
- HTTP API and routing → Download orchestration: routes worker actions
- Download orchestration → Job queues and events: enqueues jobs
- Job queues and events → Worker job runtime: dispatches jobs
- Worker job runtime → Source resolution: finds source (evidence: `apps/worker/src/jobs/item.ts`)
- Source resolution → YouTube downloader: probes and downloads (evidence: `apps/worker/src/pipeline/find-source.ts`)
- Worker job runtime → Metadata and lyrics: looks up metadata (evidence: `apps/worker/src/jobs/item.ts`)
- Worker job runtime → Audio conversion and tagging: processes audio (evidence: `apps/worker/src/jobs/item.ts`)
- Worker job runtime → Worker API client: reports completion (evidence: `apps/worker/src/jobs/item.ts`)
- Worker API client → HTTP API and routing: posts worker updates (evidence: `apps/worker/src/api/client.ts`)
- Download orchestration → Library and job data: records results (evidence: `apps/api/src/services/worker-jobs.ts`)
- Library and job data → Postgres: reads and writes (evidence: `apps/api/src/db/items.ts`)
- Download orchestration → Object storage access: requests upload access (evidence: `apps/api/src/services/worker-jobs.ts`)
- Object storage access → Object storage: signs object access (evidence: `apps/api/src/services/storage.ts`)
- Worker job runtime → Object storage: uploads audio
- Download orchestration → Live event stream: publishes updates (evidence: `apps/api/src/context.ts`)
- Live event stream → API client and queries: streams events
- API client and queries → Two-way sync engine: syncs library (evidence: `apps/mobile/src/api/queries.ts`)
- Two-way sync engine → Offline library database: applies changes (evidence: `apps/mobile/src/sync/engine.ts`)
- Library and discovery UI → Music folder mirror: saves offline files
- Music folder mirror → Object storage: downloads audio
- Offline library database → Offline player and queue: supplies library
- Library and discovery UI → Catalog services: searches catalog
- Catalog services → Music catalog clients: queries providers
- Worker job runtime → Job queues and events: consumes jobs
- Worker job runtime → Shared request and event shapes: uses job shapes (evidence: `apps/worker/src/jobs/item.ts`)
- Two-way sync engine → Shared request and event shapes: uses sync shapes (evidence: `apps/mobile/src/sync/engine.ts`)
- Download orchestration → Matching and path logic: uses path logic (evidence: `apps/api/src/services/worker-jobs.ts`)
