# ramazaneryigit/libraryhub architecture

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

- Interactive diagram: https://gitdiagram.com/ramazaneryigit/libraryhub
- Repository: https://github.com/ramazaneryigit/libraryhub

## Overview

LibraryHub is a multi-tenant library catalogue backend. Staff and administrators use its API to manage bibliographic records, identities, authorities, holdings and tenant settings; catalogues can also be imported from MARC or JSONL and discovered through keyword or semantic search. The graph highlights those workflows and the shared persistence layer. Several domain routes are represented at directory level because their source was not excerpted; their internal call paths are therefore omitted.

Main entry points: [`backend/app/api/v1/routes/search.py`](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/api/v1/routes/search.py) (Search routes), [`backend/app/main.py`](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/main.py) (API application), [`backend/app/api/v1/routes/ingest.py`](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/api/v1/routes/ingest.py) (MARC endpoints), [`backend/app/services/marc_ingest.py`](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/marc_ingest.py) (MARC ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_api_app["API application<br/>[main.py]"]
  node_access["Auth and tenant context<br/>[deps.py]"]
end

subgraph group_catalog["Catalogue domain"]
  node_domain_routes["Catalogue and tenant routes"]
  node_authority["Authority workflows<br/>[authority_queue.py]"]
end

subgraph group_ingestion["Import and export"]
  node_marc_routes["MARC endpoints<br/>[ingest.py]"]
  node_jsonl_routes["JSONL endpoints<br/>[ingestion.py]"]
  node_marc_ingest["MARC ingestion<br/>[marc_ingest.py]"]
  node_marc_codec["MARC parsing and mapping<br/>[marc.py]"]
  node_marc_export["MARC export<br/>[marc_export.py]"]
  node_jsonl_ingest["Source record ingestion<br/>[ingestion.py]"]
end

subgraph group_discovery["Search and reconciliation"]
  node_search_routes["Search routes<br/>[search.py]"]
  node_search_index["Search index<br/>[search_index.py]"]
  node_semantic_search["Semantic search<br/>[semantic_search.py]"]
  node_work_detail["Work details<br/>[work_detail.py]"]
  node_entity_merge["Entity merging<br/>[entity_merge.py]"]
  node_reconciliation["Reconciliation<br/>[reconciliation.py]"]
end

subgraph group_storage["Persistence"]
  node_identity["UUID generation<br/>[ids.py]"]
  node_text["Text normalization<br/>[text.py]"]
  node_db["Database sessions<br/>[session.py]"]
  node_models[("Catalogue and tenant data")]
  node_ingestion_model[("Ingestion batches<br/>[ingestion.py]")]
end

node_staff(("Library staff"))
node_admin(("Platform admin"))

node_api_app -->|"registers routes"| node_domain_routes
node_api_app -->|"registers routes"| node_search_routes
node_api_app -->|"registers routes"| node_marc_routes
node_api_app -->|"registers routes"| node_jsonl_routes
node_staff -.->|"manages catalogue"| node_domain_routes
node_admin -->|"imports catalogue"| node_marc_routes
node_marc_routes -->|"loads records"| node_marc_ingest
node_marc_routes -->|"exports catalogue"| node_marc_export
node_marc_ingest -->|"parses and maps"| node_marc_codec
node_marc_ingest -->|"writes records"| node_models
node_jsonl_routes -->|"submits records"| node_jsonl_ingest
node_jsonl_ingest -->|"tracks batches"| node_ingestion_model
node_search_routes -->|"queries index"| node_search_index
node_search_routes -->|"requests semantic matches"| node_semantic_search
node_search_routes -->|"loads work details"| node_work_detail
node_search_routes -->|"resolves merged entities"| node_entity_merge
node_search_index -->|"normalizes text"| node_text
node_work_detail -->|"uses merge logic"| node_entity_merge
node_access -->|"opens scoped sessions"| node_db
node_db -->|"loads ORM models"| node_models
node_ingestion_model -->|"generates IDs"| node_identity
node_authority -->|"uses generated IDs"| node_identity

click node_api_app "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/main.py"
click node_access "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/api/deps.py"
click node_domain_routes "https://github.com/ramazaneryigit/libraryhub/tree/master/backend/app/api/v1/routes"
click node_search_routes "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/api/v1/routes/search.py"
click node_marc_routes "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/api/v1/routes/ingest.py"
click node_jsonl_routes "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/api/v1/routes/ingestion.py"
click node_marc_ingest "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/marc_ingest.py"
click node_marc_codec "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/core/marc.py"
click node_marc_export "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/marc_export.py"
click node_jsonl_ingest "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/ingestion.py"
click node_search_index "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/search_index.py"
click node_semantic_search "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/semantic_search.py"
click node_work_detail "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/work_detail.py"
click node_entity_merge "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/entity_merge.py"
click node_reconciliation "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/reconciliation.py"
click node_authority "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/authority_queue.py"
click node_identity "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/core/ids.py"
click node_text "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/core/text.py"
click node_db "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/db/session.py"
click node_models "https://github.com/ramazaneryigit/libraryhub/tree/master/backend/app/db/models"
click node_ingestion_model "https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/db/models/ingestion.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_api_app,node_access toneBlue
class node_domain_routes,node_authority toneAmber
class node_marc_routes,node_jsonl_routes,node_marc_ingest,node_marc_codec,node_marc_export,node_jsonl_ingest toneMint
class node_search_routes,node_search_index,node_semantic_search,node_work_detail,node_entity_merge,node_reconciliation toneRose
class node_identity,node_text,node_db,node_models,node_ingestion_model,node_staff,node_admin toneIndigo
```

## Components

### API and access

- [API application](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/main.py): `backend/app/main.py`
- [Auth and tenant context](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/api/deps.py): `backend/app/api/deps.py`

### Catalogue domain

- [Catalogue and tenant routes](https://github.com/ramazaneryigit/libraryhub/tree/master/backend/app/api/v1/routes): `backend/app/api/v1/routes`
- [Authority workflows](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/authority_queue.py): `backend/app/services/authority_queue.py`

### Import and export

- [MARC endpoints](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/api/v1/routes/ingest.py): `backend/app/api/v1/routes/ingest.py`
- [JSONL endpoints](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/api/v1/routes/ingestion.py): `backend/app/api/v1/routes/ingestion.py`
- [MARC ingestion](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/marc_ingest.py): `backend/app/services/marc_ingest.py`
- [MARC parsing and mapping](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/core/marc.py): `backend/app/core/marc.py`
- [MARC export](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/marc_export.py): `backend/app/services/marc_export.py`
- [Source record ingestion](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/ingestion.py): `backend/app/services/ingestion.py`

### Search and reconciliation

- [Search routes](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/api/v1/routes/search.py): `backend/app/api/v1/routes/search.py`
- [Search index](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/search_index.py): `backend/app/services/search_index.py`
- [Semantic search](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/semantic_search.py): `backend/app/services/semantic_search.py`
- [Work details](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/work_detail.py): `backend/app/services/work_detail.py`
- [Entity merging](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/entity_merge.py): `backend/app/services/entity_merge.py`
- [Reconciliation](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/services/reconciliation.py): `backend/app/services/reconciliation.py`

### Persistence

- [UUID generation](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/core/ids.py): `backend/app/core/ids.py`
- [Text normalization](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/core/text.py): `backend/app/core/text.py`
- [Database sessions](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/db/session.py): `backend/app/db/session.py`
- [Catalogue and tenant data](https://github.com/ramazaneryigit/libraryhub/tree/master/backend/app/db/models): `backend/app/db/models`
- [Ingestion batches](https://github.com/ramazaneryigit/libraryhub/blob/master/backend/app/db/models/ingestion.py): `backend/app/db/models/ingestion.py`

### Other components

- **Library staff**
- **Platform admin**

## Connections

- API application → Catalogue and tenant routes: registers routes
- API application → Search routes: registers routes
- API application → MARC endpoints: registers routes
- API application → JSONL endpoints: registers routes
- Library staff → Catalogue and tenant routes: manages catalogue
- Platform admin → MARC endpoints: imports catalogue (evidence: `backend/app/api/v1/routes/ingest.py`)
- MARC endpoints → MARC ingestion: loads records (evidence: `backend/app/api/v1/routes/ingest.py`)
- MARC endpoints → MARC export: exports catalogue (evidence: `backend/app/api/v1/routes/ingest.py`)
- MARC ingestion → MARC parsing and mapping: parses and maps (evidence: `backend/app/services/marc_ingest.py`)
- MARC ingestion → Catalogue and tenant data: writes records (evidence: `backend/app/services/marc_ingest.py`)
- JSONL endpoints → Source record ingestion: submits records (evidence: `backend/app/api/v1/routes/ingestion.py`)
- Source record ingestion → Ingestion batches: tracks batches (evidence: `backend/app/services/ingestion.py`)
- Search routes → Search index: queries index (evidence: `backend/app/api/v1/routes/search.py`)
- Search routes → Semantic search: requests semantic matches (evidence: `backend/app/api/v1/routes/search.py`)
- Search routes → Work details: loads work details (evidence: `backend/app/api/v1/routes/search.py`)
- Search routes → Entity merging: resolves merged entities (evidence: `backend/app/api/v1/routes/search.py`)
- Search index → Text normalization: normalizes text (evidence: `backend/app/services/search_index.py`)
- Work details → Entity merging: uses merge logic (evidence: `backend/app/services/work_detail.py`)
- Auth and tenant context → Database sessions: opens scoped sessions (evidence: `backend/app/api/deps.py`)
- Database sessions → Catalogue and tenant data: loads ORM models
- Ingestion batches → UUID generation: generates IDs (evidence: `backend/app/db/models/ingestion.py`)
- Authority workflows → UUID generation: uses generated IDs (evidence: `backend/app/services/authority_queue.py`)
