# winsharp/music-api architecture

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

- Interactive diagram: https://gitdiagram.com/winsharp/music-api
- Repository: https://github.com/winsharp/music-api

## Overview

#### Purpose and runtime
This is a Vite-powered React/TypeScript single-page application for building and showcasing personal music collections: users browse releases and artists, search catalog data, rate/collect releases, and present profile-based music taste. Browser startup flows from `src/main.tsx` into `src/App.tsx`; global presentation begins in `src/index.css`.

#### Application shell and navigation
`src/App.tsx` is the top-level composition point for route-level pages and shared application structure. `src/components/NavBar.tsx` provides primary navigation, while `src/components/ProtectedRoute.tsx` enforces authenticated access around private profile/settings flows. Pages are independently responsible for their screen-level fetches, state, loading, and errors.

#### Authentication and identity boundary
Authentication state is centralized through `src/contexts/AuthContext.tsx`, with consumers using `src/hooks/useAuth.ts` and the typed contract in `src/types/AuthContextValue.ts`. Backend-facing sign-in, registration, and session operations are isolated in `src/services/authService.ts`. `src/pages/LoginPage.tsx` and `src/pages/RegisterPage.tsx` initiate anonymous-user flows; profile routing includes `src/pages/MyProfileRedirect.tsx`.

#### Discogs integration
Discogs is the material external catalog/identity provider. OAuth configuration and authorization exchange logic live in `src/services/discogsConfig.ts` and `src/services/discogsOAuthService.ts`; callback completion is handled by `src/pages/DiscogsCallbackPage.tsx`. Connection credentials/state are persisted separately in `src/services/discogsAuthStorage.ts`, and Discogs user data is accessed/cached via `src/services/discogsUserService.ts` and `src/services/discogsUserCache.ts`. UI connection state is exposed through `src/hooks/useDiscogsConnection.ts` and `src/components/ConnectDiscogsButton.tsx`.

#### Catalog discovery and release detail
Catalog browsing, search, release detail, artist pages, and home features are separate page/service verticals:
- Browse: `src/pages/BrowseCatalogPage.tsx`, `src/services/browseService.ts`
- Search: `src/pages/SearchPage.tsx`, `src/services/searchService.ts`
- Release detail: `src/pages/ReleasePage.tsx`, `src/services/releaseService.ts`
- Artist detail: `src/pages/ArtistPage.tsx`, `src/services/artistService.ts`
- Featured/home data: `src/pages/HomePage.tsx`, `src/services/homeService.ts`

Services form the remote-data boundary and map responses into domain types under `src/types/`, including `src/types/discogsRelease.ts`, `src/types/search.ts`, and `src/types/artist.ts`. Reusable filtering/pagination UI uses genre/style constants from `src/constants/genres.ts` and `src/constants/styles.ts`.

#### Collection and profile domain
User-owned collection actions are separated from catalog retrieval. `src/services/releaseCollectionService.ts` manages rating/collection-related release operations, and `src/services/wantlistService.ts` manages wanted releases. `src/components/RateAndCollect.tsx` is the primary release-action UI. Profile rendering is organized through `src/pages/ProfilePage.tsx` and `src/pages/ProfileSectionPage.tsx`, with `src/pages/SettingsPage.tsx` covering account/integration settings.

#### UI state and resilience
Shared presentation components render catalog cards, lists, search results, filters, and pagination, notably `src/components/ReleaseGrid.tsx`, `src/components/SearchResultView.tsx`, and `src/components/Pagination.tsx`. Asynchronous request state is normalized by `src/hooks/useAsyncStatus.ts`; page query pagination is managed by `src/hooks/usePageParam.ts`. Loading boundaries use dedicated skeletons such as `src/components/skeletons/ReleaseDetailSkeleton.tsx` and `src/components/skeletons/ProfilePageSkeleton.tsx`. API errors are converted for display through `src/utils/getApiErrorMessage.ts`.

Main entry points: [`src/App.tsx`](https://github.com/winsharp/music-api/blob/main/src/App.tsx) (App routes & shell), [`src/pages/BrowseCatalogPage.tsx`](https://github.com/winsharp/music-api/blob/main/src/pages/BrowseCatalogPage.tsx) (Discovery pages), [`src/pages/ProfilePage.tsx`](https://github.com/winsharp/music-api/blob/main/src/pages/ProfilePage.tsx) (Profiles & settings), [`src/contexts/AuthContext.tsx`](https://github.com/winsharp/music-api/blob/main/src/contexts/AuthContext.tsx) (Auth state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application shell"]
  node_main(("Browser entry<br/>Vite React entry<br/>[main.tsx]"))
  node_app_shell["App routes &amp; shell<br/>React composition<br/>[App.tsx]"]
  node_navbar["Primary navigation<br/>shared component<br/>[NavBar.tsx]"]
  node_async_ui["Async state &amp; loading UI<br/>hooks and skeletons<br/>[useAsyncStatus.ts]"]
end

subgraph group_identity["Identity &amp; access"]
  node_auth_context["Auth state<br/>React context<br/>[AuthContext.tsx]"]
  node_auth_hook["Auth consumer API<br/>React hook<br/>[useAuth.ts]"]
  node_auth_service{{"Authentication API<br/>backend service<br/>[authService.ts]"}}
  node_access_pages["Login &amp; registration<br/>route pages<br/>[LoginPage.tsx]"]
  node_protected_route["Private-route guard<br/>route component<br/>[ProtectedRoute.tsx]"]
end

subgraph group_discogs["Discogs integration"]
  node_discogs_connection{{"Discogs OAuth &amp; credentials<br/>integration boundary"}}
  node_discogs_callback["Discogs callback<br/>route page"]
  node_discogs_user[("Discogs user data<br/>cached service")]
end

subgraph group_catalog["Catalog &amp; discovery"]
  node_catalog_services{{"Catalog data services<br/>remote-data services<br/>[browseService.ts]"}}
  node_discovery_pages["Discovery pages<br/>route pages"]
  node_catalog_types["Catalog domain types<br/>TypeScript models<br/>[discogsRelease.ts]"]
  node_catalog_ui["Catalog result UI<br/>shared components<br/>[ReleaseGrid.tsx]"]
end

subgraph group_collection["Collection &amp; profiles"]
  node_collection_actions{{"Collection &amp; wantlist API<br/>user-data services"}}
  node_rate_collect["Rate &amp; collect UI<br/>release-action component<br/>[RateAndCollect.tsx]"]
  node_profile_pages["Profiles &amp; settings<br/>private route pages<br/>[ProfilePage.tsx]"]
end

node_main -->|"mounts"| node_app_shell
node_app_shell -->|"renders"| node_navbar
node_app_shell -->|"routes to"| node_access_pages
node_app_shell -->|"routes to"| node_discovery_pages
node_app_shell -->|"wraps private routes"| node_protected_route
node_protected_route -->|"permits"| node_profile_pages
node_auth_context -->|"session operations"| node_auth_service
node_auth_hook -->|"consumes"| node_auth_context
node_access_pages -->|"starts auth flows"| node_auth_context
node_discogs_callback -->|"completes OAuth"| node_discogs_connection
node_discogs_connection -->|"authorizes access"| node_discogs_user
node_profile_pages -->|"manages connection"| node_discogs_connection
node_discovery_pages -->|"fetches catalog data"| node_catalog_services
node_catalog_services -->|"maps responses to"| node_catalog_types
node_discovery_pages -->|"renders results with"| node_catalog_ui
node_discovery_pages -->|"uses request state"| node_async_ui
node_rate_collect -->|"updates collection"| node_collection_actions
node_profile_pages -->|"loads user music data"| node_collection_actions
node_profile_pages -->|"loads Discogs identity"| node_discogs_user

click node_main "https://github.com/winsharp/music-api/blob/main/src/main.tsx"
click node_app_shell "https://github.com/winsharp/music-api/blob/main/src/App.tsx"
click node_navbar "https://github.com/winsharp/music-api/blob/main/src/components/NavBar.tsx"
click node_auth_context "https://github.com/winsharp/music-api/blob/main/src/contexts/AuthContext.tsx"
click node_auth_hook "https://github.com/winsharp/music-api/blob/main/src/hooks/useAuth.ts"
click node_auth_service "https://github.com/winsharp/music-api/blob/main/src/services/authService.ts"
click node_access_pages "https://github.com/winsharp/music-api/blob/main/src/pages/LoginPage.tsx"
click node_protected_route "https://github.com/winsharp/music-api/blob/main/src/components/ProtectedRoute.tsx"
click node_discogs_connection "https://github.com/winsharp/music-api/blob/main/src/services/discogsOAuthService.ts"
click node_discogs_callback "https://github.com/winsharp/music-api/blob/main/src/pages/DiscogsCallbackPage.tsx"
click node_discogs_user "https://github.com/winsharp/music-api/blob/main/src/services/discogsUserService.ts"
click node_catalog_services "https://github.com/winsharp/music-api/blob/main/src/services/browseService.ts"
click node_discovery_pages "https://github.com/winsharp/music-api/blob/main/src/pages/BrowseCatalogPage.tsx"
click node_catalog_types "https://github.com/winsharp/music-api/blob/main/src/types/discogsRelease.ts"
click node_catalog_ui "https://github.com/winsharp/music-api/blob/main/src/components/ReleaseGrid.tsx"
click node_collection_actions "https://github.com/winsharp/music-api/blob/main/src/services/releaseCollectionService.ts"
click node_rate_collect "https://github.com/winsharp/music-api/blob/main/src/components/RateAndCollect.tsx"
click node_profile_pages "https://github.com/winsharp/music-api/blob/main/src/pages/ProfilePage.tsx"
click node_async_ui "https://github.com/winsharp/music-api/blob/main/src/hooks/useAsyncStatus.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_main,node_app_shell,node_navbar,node_async_ui toneBlue
class node_auth_context,node_auth_hook,node_auth_service,node_access_pages,node_protected_route toneAmber
class node_discogs_connection,node_discogs_callback,node_discogs_user toneMint
class node_catalog_services,node_discovery_pages,node_catalog_types,node_catalog_ui toneRose
class node_collection_actions,node_rate_collect,node_profile_pages toneIndigo
```

## Components

### Application shell

- [Browser entry](https://github.com/winsharp/music-api/blob/main/src/main.tsx): Vite React entry · `src/main.tsx`
- [App routes & shell](https://github.com/winsharp/music-api/blob/main/src/App.tsx): React composition · Composes route pages and shared structure. · `src/App.tsx`
- [Primary navigation](https://github.com/winsharp/music-api/blob/main/src/components/NavBar.tsx): shared component · `src/components/NavBar.tsx`
- [Async state & loading UI](https://github.com/winsharp/music-api/blob/main/src/hooks/useAsyncStatus.ts): hooks and skeletons · Normalizes request states and loading boundaries. · `src/hooks/useAsyncStatus.ts`

### Identity & access

- [Auth state](https://github.com/winsharp/music-api/blob/main/src/contexts/AuthContext.tsx): React context · Central authenticated identity state. · `src/contexts/AuthContext.tsx`
- [Auth consumer API](https://github.com/winsharp/music-api/blob/main/src/hooks/useAuth.ts): React hook · `src/hooks/useAuth.ts`
- [Authentication API](https://github.com/winsharp/music-api/blob/main/src/services/authService.ts): backend service · Handles sign-in, registration, and sessions. · `src/services/authService.ts`
- [Login & registration](https://github.com/winsharp/music-api/blob/main/src/pages/LoginPage.tsx): route pages · `src/pages/LoginPage.tsx`
- [Private-route guard](https://github.com/winsharp/music-api/blob/main/src/components/ProtectedRoute.tsx): route component · `src/components/ProtectedRoute.tsx`

### Discogs integration

- [Discogs OAuth & credentials](https://github.com/winsharp/music-api/blob/main/src/services/discogsOAuthService.ts): integration boundary · Authorizes Discogs and persists connection state. · `src/services/discogsOAuthService.ts`
- [Discogs callback](https://github.com/winsharp/music-api/blob/main/src/pages/DiscogsCallbackPage.tsx): route page · `src/pages/DiscogsCallbackPage.tsx`
- [Discogs user data](https://github.com/winsharp/music-api/blob/main/src/services/discogsUserService.ts): cached service · `src/services/discogsUserService.ts`

### Catalog & discovery

- [Catalog data services](https://github.com/winsharp/music-api/blob/main/src/services/browseService.ts): remote-data services · Browse, search, release, artist, and home data. · `src/services/browseService.ts`
- [Discovery pages](https://github.com/winsharp/music-api/blob/main/src/pages/BrowseCatalogPage.tsx): route pages · Browse, search, home, release, and artist screens fetch their own data. · `src/pages/BrowseCatalogPage.tsx`
- [Catalog domain types](https://github.com/winsharp/music-api/blob/main/src/types/discogsRelease.ts): TypeScript models · `src/types/discogsRelease.ts`
- [Catalog result UI](https://github.com/winsharp/music-api/blob/main/src/components/ReleaseGrid.tsx): shared components · Release grids, search results, filters, and pagination. · `src/components/ReleaseGrid.tsx`

### Collection & profiles

- [Collection & wantlist API](https://github.com/winsharp/music-api/blob/main/src/services/releaseCollectionService.ts): user-data services · Separates owned-release actions from catalog retrieval. · `src/services/releaseCollectionService.ts`
- [Rate & collect UI](https://github.com/winsharp/music-api/blob/main/src/components/RateAndCollect.tsx): release-action component · `src/components/RateAndCollect.tsx`
- [Profiles & settings](https://github.com/winsharp/music-api/blob/main/src/pages/ProfilePage.tsx): private route pages · Renders profile sections and account/integration settings. · `src/pages/ProfilePage.tsx`

## Connections

- Browser entry → App routes & shell: mounts
- App routes & shell → Primary navigation: renders
- App routes & shell → Login & registration: routes to
- App routes & shell → Discovery pages: routes to
- App routes & shell → Private-route guard: wraps private routes
- Private-route guard → Profiles & settings: permits
- Auth state → Authentication API: session operations
- Auth consumer API → Auth state: consumes
- Login & registration → Auth state: starts auth flows
- Discogs callback → Discogs OAuth & credentials: completes OAuth
- Discogs OAuth & credentials → Discogs user data: authorizes access
- Profiles & settings → Discogs OAuth & credentials: manages connection
- Discovery pages → Catalog data services: fetches catalog data
- Catalog data services → Catalog domain types: maps responses to
- Discovery pages → Catalog result UI: renders results with
- Discovery pages → Async state & loading UI: uses request state
- Rate & collect UI → Collection & wantlist API: updates collection
- Profiles & settings → Collection & wantlist API: loads user music data
- Profiles & settings → Discogs user data: loads Discogs identity
