# alimotassem164/library-management-api architecture

> Architecture diagram of the GitHub repository alimotassem164/library-management-api, 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/alimotassem164/library-management-api
- Repository: https://github.com/alimotassem164/library-management-api

## Overview

Bibliotheca is a full-stack library system: users register or log in, then browse and administer books, borrow and return copies, and view account or monitoring information. The browser UI calls the FastAPI application, whose routers delegate domain operations to services and persist records through SQLAlchemy. Authentication and role checks protect these workflows; Redis caching is optional, while monitoring exposes in-memory metrics and logs. The graph uses README and indexed source references; unsampled module internals and some wiring are therefore not asserted beyond those references.

Main entry points: [`backend/app/main.py`](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/main.py) (Application and routes), [`backend/app/auth/routes.py`](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/auth/routes.py) (Authentication routes), [`backend/app/books/routes.py`](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/books/routes.py) (Book endpoints), [`backend/app/borrow/routes.py`](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/borrow/routes.py) (Borrow endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_entry["Login and register<br/>[index.html]"]
  node_dashboard_ui["Library dashboard<br/>[dashboard.html]"]
  node_controller["Dashboard controller<br/>[dashboard.js]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_api["API and access"]
  node_fastapi["Application and routes<br/>[main.py]"]
  node_auth_routes["Authentication routes<br/>[routes.py]"]
  node_auth_service["Authentication service<br/>[service.py]"]
  node_jwt["JWT security<br/>[security.py]"]
  node_access["Authentication and roles<br/>[dependencies.py]"]
  node_user_model["User records<br/>[user.py]"]
end

subgraph group_library["Library workflows"]
  node_books_routes["Book endpoints<br/>[routes.py]"]
  node_books_service["Book operations<br/>[service.py]"]
  node_book_model["Book records<br/>[model.py]"]
  node_borrow_routes["Borrow endpoints<br/>[routes.py]"]
  node_borrow_service["Borrow lifecycle<br/>[service.py]"]
  node_borrow_permissions["Borrow permissions<br/>[permissions.py]"]
  node_borrow_model["Borrow records<br/>[model.py]"]
end

subgraph group_ops["Monitoring and infrastructure"]
  node_database["Database sessions<br/>[database.py]"]
  node_settings["Application settings<br/>[config.py]"]
  node_postgres[("SQL database")]
  node_redis[("Redis cache")]
  node_cache["Cache access<br/>[cache.py]"]
  node_metrics["Metrics store<br/>[metrics.py]"]
  node_logger["Logging<br/>[logger.py]"]
  node_monitoring["Monitoring dashboard<br/>[routes.py]"]
end

node_patron(("Library user"))

node_patron -->|"starts account"| node_entry
node_patron -->|"uses library"| node_dashboard_ui
node_entry -->|"requests API"| node_api_client
node_dashboard_ui -->|"loads controller"| node_controller
node_controller -->|"calls"| node_api_client
node_api_client -->|"sends requests"| node_fastapi
node_fastapi -->|"registers routes"| node_auth_routes
node_fastapi -->|"registers routes"| node_books_routes
node_fastapi -->|"registers routes"| node_borrow_routes
node_fastapi -->|"registers routes"| node_monitoring
node_auth_routes -->|"delegates"| node_auth_service
node_auth_routes -->|"creates tokens"| node_jwt
node_auth_routes -->|"checks identity"| node_access
node_auth_service -->|"uses users"| node_user_model
node_access -->|"loads user"| node_user_model
node_access -->|"reads JWT config"| node_settings
node_books_routes -->|"delegates"| node_books_service
node_books_routes -->|"requires access"| node_access
node_books_routes -->|"uses cache"| node_cache
node_books_service -->|"operates on"| node_book_model
node_borrow_routes -->|"delegates"| node_borrow_service
node_borrow_routes -->|"requires access"| node_access
node_borrow_routes -->|"uses cache"| node_cache
node_borrow_service -->|"manages records"| node_borrow_model
node_borrow_service -->|"checks availability"| node_book_model
node_borrow_service -->|"checks permissions"| node_borrow_permissions
node_borrow_model -->|"relates user"| node_user_model
node_borrow_model -->|"relates book"| node_book_model
node_fastapi -->|"initializes schema"| node_database
node_database -->|"reads database config"| node_settings
node_database -.->|"stores records"| node_postgres
node_books_routes -.->|"optional cache"| node_redis
node_borrow_routes -.->|"optional cache"| node_redis
node_cache -->|"reads cache config"| node_settings
node_monitoring -->|"reads metrics"| node_metrics
node_monitoring -->|"reads logs"| node_logger
node_fastapi -->|"logs requests"| node_logger
node_auth_routes -->|"records auth events"| node_metrics
node_auth_routes -->|"logs auth events"| node_logger

click node_entry "https://github.com/alimotassem164/library-management-api/blob/main/frontend/index.html"
click node_dashboard_ui "https://github.com/alimotassem164/library-management-api/blob/main/frontend/dashboard.html"
click node_controller "https://github.com/alimotassem164/library-management-api/blob/main/frontend/js/dashboard.js"
click node_api_client "https://github.com/alimotassem164/library-management-api/blob/main/frontend/js/api.js"
click node_fastapi "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/main.py"
click node_auth_routes "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/auth/routes.py"
click node_auth_service "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/auth/service.py"
click node_jwt "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/auth/security.py"
click node_access "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/auth/dependencies.py"
click node_books_routes "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/books/routes.py"
click node_books_service "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/books/service.py"
click node_book_model "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/books/model.py"
click node_borrow_routes "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/borrow/routes.py"
click node_borrow_service "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/borrow/service.py"
click node_borrow_permissions "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/borrow/permissions.py"
click node_borrow_model "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/borrow/model.py"
click node_user_model "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/models/user.py"
click node_database "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/core/database.py"
click node_settings "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/core/config.py"
click node_cache "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/system/cache.py"
click node_metrics "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/system/metrics.py"
click node_logger "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/system/logger.py"
click node_monitoring "https://github.com/alimotassem164/library-management-api/blob/main/backend/app/dashboard/routes.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_entry,node_dashboard_ui,node_controller,node_api_client,node_patron toneBlue
class node_fastapi,node_auth_routes,node_auth_service,node_jwt,node_access,node_user_model toneAmber
class node_books_routes,node_books_service,node_book_model,node_borrow_routes,node_borrow_service,node_borrow_permissions,node_borrow_model toneMint
class node_database,node_settings,node_postgres,node_redis,node_cache,node_metrics,node_logger,node_monitoring toneRose
```

## Components

### Web client

- [Login and register](https://github.com/alimotassem164/library-management-api/blob/main/frontend/index.html): `frontend/index.html`
- [Library dashboard](https://github.com/alimotassem164/library-management-api/blob/main/frontend/dashboard.html): `frontend/dashboard.html`
- [Dashboard controller](https://github.com/alimotassem164/library-management-api/blob/main/frontend/js/dashboard.js): `frontend/js/dashboard.js`
- [API client](https://github.com/alimotassem164/library-management-api/blob/main/frontend/js/api.js): `frontend/js/api.js`

### API and access

- [Application and routes](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication routes](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/auth/routes.py): `backend/app/auth/routes.py`
- [Authentication service](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/auth/service.py): `backend/app/auth/service.py`
- [JWT security](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/auth/security.py): `backend/app/auth/security.py`
- [Authentication and roles](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/auth/dependencies.py): `backend/app/auth/dependencies.py`
- [User records](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/models/user.py): `backend/app/models/user.py`

### Library workflows

- [Book endpoints](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/books/routes.py): `backend/app/books/routes.py`
- [Book operations](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/books/service.py): `backend/app/books/service.py`
- [Book records](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/books/model.py): `backend/app/books/model.py`
- [Borrow endpoints](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/borrow/routes.py): `backend/app/borrow/routes.py`
- [Borrow lifecycle](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/borrow/service.py): `backend/app/borrow/service.py`
- [Borrow permissions](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/borrow/permissions.py): `backend/app/borrow/permissions.py`
- [Borrow records](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/borrow/model.py): `backend/app/borrow/model.py`

### Monitoring and infrastructure

- [Database sessions](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/core/database.py): `backend/app/core/database.py`
- [Application settings](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/core/config.py): `backend/app/core/config.py`
- **SQL database**
- **Redis cache**
- [Cache access](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/system/cache.py): `backend/app/system/cache.py`
- [Metrics store](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/system/metrics.py): `backend/app/system/metrics.py`
- [Logging](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/system/logger.py): `backend/app/system/logger.py`
- [Monitoring dashboard](https://github.com/alimotassem164/library-management-api/blob/main/backend/app/dashboard/routes.py): `backend/app/dashboard/routes.py`

### Other components

- **Library user**

## Connections

- Library user → Login and register: starts account (evidence: `README.md`)
- Library user → Library dashboard: uses library (evidence: `README.md`)
- Login and register → API client: requests API (evidence: `README.md`)
- Library dashboard → Dashboard controller: loads controller (evidence: `README.md`)
- Dashboard controller → API client: calls (evidence: `frontend/js/dashboard.js`)
- API client → Application and routes: sends requests (evidence: `README.md`)
- Application and routes → Authentication routes: registers routes (evidence: `backend/app/main.py`)
- Application and routes → Book endpoints: registers routes (evidence: `backend/app/main.py`)
- Application and routes → Borrow endpoints: registers routes (evidence: `backend/app/main.py`)
- Application and routes → Monitoring dashboard: registers routes (evidence: `backend/app/main.py`)
- Authentication routes → Authentication service: delegates (evidence: `backend/app/auth/routes.py`)
- Authentication routes → JWT security: creates tokens (evidence: `backend/app/auth/routes.py`)
- Authentication routes → Authentication and roles: checks identity (evidence: `backend/app/auth/routes.py`)
- Authentication service → User records: uses users (evidence: `backend/app/auth/service.py`)
- Authentication and roles → User records: loads user (evidence: `backend/app/auth/dependencies.py`)
- Authentication and roles → Application settings: reads JWT config (evidence: `backend/app/auth/dependencies.py`)
- Book endpoints → Book operations: delegates (evidence: `backend/app/books/routes.py`)
- Book endpoints → Authentication and roles: requires access (evidence: `backend/app/books/routes.py`)
- Book endpoints → Cache access: uses cache (evidence: `backend/app/books/routes.py`)
- Book operations → Book records: operates on (evidence: `backend/app/books/service.py`)
- Borrow endpoints → Borrow lifecycle: delegates (evidence: `backend/app/borrow/routes.py`)
- Borrow endpoints → Authentication and roles: requires access (evidence: `backend/app/borrow/routes.py`)
- Borrow endpoints → Cache access: uses cache (evidence: `backend/app/borrow/routes.py`)
- Borrow lifecycle → Borrow records: manages records (evidence: `backend/app/borrow/service.py`)
- Borrow lifecycle → Book records: checks availability (evidence: `backend/app/borrow/service.py`)
- Borrow lifecycle → Borrow permissions: checks permissions (evidence: `backend/app/borrow/service.py`)
- Borrow records → User records: relates user (evidence: `backend/app/borrow/model.py`)
- Borrow records → Book records: relates book (evidence: `backend/app/borrow/model.py`)
- Application and routes → Database sessions: initializes schema (evidence: `backend/app/main.py`)
- Database sessions → Application settings: reads database config (evidence: `backend/app/core/database.py`)
- Database sessions → SQL database: stores records (evidence: `README.md`)
- Book endpoints → Redis cache: optional cache (evidence: `README.md`)
- Borrow endpoints → Redis cache: optional cache (evidence: `README.md`)
- Cache access → Application settings: reads cache config (evidence: `backend/app/system/cache.py`)
- Monitoring dashboard → Metrics store: reads metrics (evidence: `backend/app/dashboard/routes.py`)
- Monitoring dashboard → Logging: reads logs (evidence: `backend/app/dashboard/routes.py`)
- Application and routes → Logging: logs requests (evidence: `backend/app/main.py`)
- Authentication routes → Metrics store: records auth events (evidence: `backend/app/auth/routes.py`)
- Authentication routes → Logging: logs auth events (evidence: `backend/app/auth/routes.py`)
