# dgahagan/shelf architecture

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

- Interactive diagram: https://gitdiagram.com/dgahagan/shelf
- Repository: https://github.com/dgahagan/shelf

## Overview

Shelf is a self-hosted, multi-user home-library catalog. The principal workflow is scanning a barcode or searching a title, resolving metadata and artwork, then adding the item to a persistent collection. The graph also preserves photo intake, browsing, lending, inventory, collection maintenance, integrations, and valuation. Source excerpts and the index support the central routing, persistence, metadata, and cover relationships; README-based edges represent documented capabilities where implementation excerpts were not provided.

Main entry points: [`app/routers/items.py`](https://github.com/dgahagan/shelf/blob/main/app/routers/items.py) (Item workflows), [`app/database.py`](https://github.com/dgahagan/shelf/blob/main/app/database.py) (SQLite catalog), [`app/main.py`](https://github.com/dgahagan/shelf/blob/main/app/main.py) (Application routes), [`app/routers/items_common.py`](https://github.com/dgahagan/shelf/blob/main/app/routers/items_common.py) (Lookup and scan logic)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Web experience"]
  node_web_ui["Web interface<br/>[app.js]"]
  node_scan_ui["Scanning interface<br/>[scan.js]"]
  node_browse_ui["Browse interface<br/>[browse.js]"]
  node_app_routes["Application routes<br/>[main.py]"]
end

subgraph group_catalog["Catalog workflows"]
  node_item_routes["Item workflows<br/>[items.py]"]
  node_item_helpers["Lookup and scan logic<br/>[items_common.py]"]
  node_item_writes["Item persistence logic<br/>[item_write.py]"]
  node_cover_review["Cover review queue<br/>[cover_review.py]"]
  node_intake["Photo intake<br/>[intake.py]"]
  node_browse["Browse and search<br/>[items_catalog.py]"]
  node_lending["Lending and checkouts<br/>[checkouts.py]"]
  node_inventory["Locations and inventory<br/>[locations.py]"]
  node_collection_ops["Collection management"]
  node_valuation["Collection valuation<br/>[valuation.py]"]
end

subgraph group_metadata["Metadata and media"]
  node_metadata_providers["Metadata providers"]
  node_cover_service["Cover search and storage<br/>[covers.py]"]
end

subgraph group_platform["Identity and persistence"]
  node_auth["Authentication and roles<br/>[auth.py]"]
  node_database[("SQLite catalog<br/>[database.py]")]
end

node_household(("Household user"))
node_external_metadata{{"Metadata services"}}

node_household -->|"uses"| node_web_ui
node_web_ui -->|"requests pages"| node_app_routes
node_scan_ui -->|"submits scans"| node_item_routes
node_browse_ui -->|"browses catalog"| node_browse
node_app_routes -->|"authenticates"| node_auth
node_app_routes -->|"mounts routes"| node_item_routes
node_auth -->|"reads users"| node_database
node_item_routes -->|"delegates lookup"| node_item_helpers
node_item_helpers -->|"looks up metadata"| node_metadata_providers
node_item_helpers -->|"finds artwork"| node_cover_service
node_item_routes -->|"writes items"| node_item_writes
node_item_writes -->|"persists records"| node_database
node_metadata_providers -.->|"queries providers"| node_external_metadata
node_cover_service -->|"fetches artwork"| node_external_metadata
node_household -->|"imports shelf photos"| node_intake
node_intake -->|"adds confirmed items"| node_item_writes
node_household -->|"reviews covers"| node_cover_review
node_cover_review -->|"searches candidates"| node_cover_service
node_household -->|"lends and returns"| node_lending
node_household -->|"audits locations"| node_inventory
node_household -->|"manages collection"| node_collection_ops
node_household -->|"requests valuation"| node_valuation
node_browse -.->|"queries catalog"| node_database
node_lending -->|"tracks loans"| node_database

click node_web_ui "https://github.com/dgahagan/shelf/blob/main/static/js/app.js"
click node_scan_ui "https://github.com/dgahagan/shelf/blob/main/static/js/scan.js"
click node_browse_ui "https://github.com/dgahagan/shelf/blob/main/static/js/browse.js"
click node_app_routes "https://github.com/dgahagan/shelf/blob/main/app/main.py"
click node_auth "https://github.com/dgahagan/shelf/blob/main/app/auth.py"
click node_database "https://github.com/dgahagan/shelf/blob/main/app/database.py"
click node_item_routes "https://github.com/dgahagan/shelf/blob/main/app/routers/items.py"
click node_item_helpers "https://github.com/dgahagan/shelf/blob/main/app/routers/items_common.py"
click node_item_writes "https://github.com/dgahagan/shelf/blob/main/app/services/item_write.py"
click node_metadata_providers "https://github.com/dgahagan/shelf/tree/main/app/services"
click node_cover_service "https://github.com/dgahagan/shelf/blob/main/app/services/covers.py"
click node_cover_review "https://github.com/dgahagan/shelf/blob/main/app/routers/cover_review.py"
click node_intake "https://github.com/dgahagan/shelf/blob/main/app/routers/intake.py"
click node_browse "https://github.com/dgahagan/shelf/blob/main/app/routers/items_catalog.py"
click node_lending "https://github.com/dgahagan/shelf/blob/main/app/routers/checkouts.py"
click node_inventory "https://github.com/dgahagan/shelf/blob/main/app/routers/locations.py"
click node_collection_ops "https://github.com/dgahagan/shelf/tree/main/app/routers"
click node_valuation "https://github.com/dgahagan/shelf/blob/main/app/routers/valuation.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_ui,node_scan_ui,node_browse_ui,node_app_routes,node_household toneBlue
class node_item_routes,node_item_helpers,node_item_writes,node_cover_review,node_intake,node_browse,node_lending,node_inventory,node_collection_ops,node_valuation toneAmber
class node_metadata_providers,node_cover_service toneMint
class node_auth,node_database toneRose
class node_external_metadata toneIndigo
```

## Components

### Web experience

- [Web interface](https://github.com/dgahagan/shelf/blob/main/static/js/app.js): `static/js/app.js`
- [Scanning interface](https://github.com/dgahagan/shelf/blob/main/static/js/scan.js): `static/js/scan.js`
- [Browse interface](https://github.com/dgahagan/shelf/blob/main/static/js/browse.js): `static/js/browse.js`
- [Application routes](https://github.com/dgahagan/shelf/blob/main/app/main.py): `app/main.py`

### Catalog workflows

- [Item workflows](https://github.com/dgahagan/shelf/blob/main/app/routers/items.py): `app/routers/items.py`
- [Lookup and scan logic](https://github.com/dgahagan/shelf/blob/main/app/routers/items_common.py): `app/routers/items_common.py`
- [Item persistence logic](https://github.com/dgahagan/shelf/blob/main/app/services/item_write.py): `app/services/item_write.py`
- [Cover review queue](https://github.com/dgahagan/shelf/blob/main/app/routers/cover_review.py): `app/routers/cover_review.py`
- [Photo intake](https://github.com/dgahagan/shelf/blob/main/app/routers/intake.py): `app/routers/intake.py`
- [Browse and search](https://github.com/dgahagan/shelf/blob/main/app/routers/items_catalog.py): `app/routers/items_catalog.py`
- [Lending and checkouts](https://github.com/dgahagan/shelf/blob/main/app/routers/checkouts.py): `app/routers/checkouts.py`
- [Locations and inventory](https://github.com/dgahagan/shelf/blob/main/app/routers/locations.py): `app/routers/locations.py`
- [Collection management](https://github.com/dgahagan/shelf/tree/main/app/routers): `app/routers`
- [Collection valuation](https://github.com/dgahagan/shelf/blob/main/app/routers/valuation.py): `app/routers/valuation.py`

### Metadata and media

- [Metadata providers](https://github.com/dgahagan/shelf/tree/main/app/services): `app/services`
- [Cover search and storage](https://github.com/dgahagan/shelf/blob/main/app/services/covers.py): `app/services/covers.py`

### Identity and persistence

- [Authentication and roles](https://github.com/dgahagan/shelf/blob/main/app/auth.py): `app/auth.py`
- [SQLite catalog](https://github.com/dgahagan/shelf/blob/main/app/database.py): `app/database.py`

### Other components

- **Household user**
- **Metadata services**

## Connections

- Household user → Web interface: uses
- Web interface → Application routes: requests pages (evidence: `app/main.py`)
- Scanning interface → Item workflows: submits scans
- Browse interface → Browse and search: browses catalog
- Application routes → Authentication and roles: authenticates (evidence: `app/main.py`)
- Application routes → Item workflows: mounts routes (evidence: `app/main.py`)
- Authentication and roles → SQLite catalog: reads users (evidence: `app/auth.py`)
- Item workflows → Lookup and scan logic: delegates lookup (evidence: `app/routers/items.py`)
- Lookup and scan logic → Metadata providers: looks up metadata (evidence: `app/routers/items_common.py`)
- Lookup and scan logic → Cover search and storage: finds artwork (evidence: `app/routers/items_common.py`)
- Item workflows → Item persistence logic: writes items (evidence: `app/routers/items.py`)
- Item persistence logic → SQLite catalog: persists records (evidence: `app/services/item_write.py`)
- Metadata providers → Metadata services: queries providers
- Cover search and storage → Metadata services: fetches artwork (evidence: `app/services/covers.py`)
- Household user → Photo intake: imports shelf photos
- Photo intake → Item persistence logic: adds confirmed items
- Household user → Cover review queue: reviews covers
- Cover review queue → Cover search and storage: searches candidates (evidence: `app/routers/cover_review.py`)
- Household user → Lending and checkouts: lends and returns
- Household user → Locations and inventory: audits locations
- Household user → Collection management: manages collection
- Household user → Collection valuation: requests valuation
- Browse and search → SQLite catalog: queries catalog
- Lending and checkouts → SQLite catalog: tracks loans (evidence: `app/routers/checkouts.py`)
