# zain-ahma12/kitabghar architecture

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

- Interactive diagram: https://gitdiagram.com/zain-ahma12/kitabghar
- Repository: https://github.com/zain-ahma12/kitabghar

## Overview

KitabGhar is a FastAPI REST API for a book-lending service. Clients call book and member endpoints to browse and manage the catalogue, register members, and borrow or return books; route handlers use domain models and database sessions to validate and persist changes. The API also exposes liveness and a customized Swagger UI. The README documents SQLite, endpoint capabilities, and the request flow; source excerpts show route and domain interactions. Unsampled implementation details are not inferred.

Main entry points: [`main.py`](https://github.com/zain-ahma12/kitabghar/blob/main/main.py) (FastAPI App), [`routes/book_routes.py`](https://github.com/zain-ahma12/kitabghar/blob/main/routes/book_routes.py) (Book Endpoints), [`routes/users_routes.py`](https://github.com/zain-ahma12/kitabghar/blob/main/routes/users_routes.py) (User Endpoints), [`database.py`](https://github.com/zain-ahma12/kitabghar/blob/main/database.py) (Session and Tables)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API Surface"]
  node_app["FastAPI App<br/>[main.py]"]
  node_book_routes["Book Endpoints<br/>[book_routes.py]"]
  node_user_routes["User Endpoints<br/>[users_routes.py]"]
  node_health["Health Check<br/>[main.py]"]
end

subgraph group_domain["Lending Domain"]
  node_books["Book State and Lending<br/>[books.py]"]
  node_users["Member Records<br/>[users.py]"]
end

subgraph group_infra["Persistence and Access"]
  node_auth["API Key Check<br/>[auth.py]"]
  node_database["Session and Tables<br/>[database.py]"]
  node_sqlite[("SQLite Store")]
end

subgraph group_docs["API Docs"]
  node_docs_ui["Custom Swagger UI<br/>[docs_ui.py]"]
end

node_client(("API Client"))
node_uvicorn["Uvicorn Server"]

node_client -->|"sends requests"| node_uvicorn
node_uvicorn -->|"serves app"| node_app
node_app -->|"registers router"| node_book_routes
node_app -->|"registers router"| node_user_routes
node_client -->|"requests liveness"| node_health
node_app -->|"routes health"| node_health
node_book_routes -->|"calls lending rules"| node_books
node_user_routes -->|"converts member data"| node_users
node_book_routes -->|"requests sessions"| node_database
node_user_routes -->|"requests sessions"| node_database
node_book_routes -->|"checks protected routes"| node_auth
node_user_routes -->|"checks protected routes"| node_auth
node_books -->|"links borrower"| node_users
node_users -->|"relates borrowed books"| node_books
node_app -->|"creates tables"| node_database
node_database -->|"stores records"| node_sqlite
node_app -->|"configures docs"| node_docs_ui
node_client -->|"views API docs"| node_docs_ui

click node_app "https://github.com/zain-ahma12/kitabghar/blob/main/main.py"
click node_book_routes "https://github.com/zain-ahma12/kitabghar/blob/main/routes/book_routes.py"
click node_user_routes "https://github.com/zain-ahma12/kitabghar/blob/main/routes/users_routes.py"
click node_health "https://github.com/zain-ahma12/kitabghar/blob/main/main.py"
click node_books "https://github.com/zain-ahma12/kitabghar/blob/main/models/books.py"
click node_users "https://github.com/zain-ahma12/kitabghar/blob/main/models/users.py"
click node_auth "https://github.com/zain-ahma12/kitabghar/blob/main/auth.py"
click node_database "https://github.com/zain-ahma12/kitabghar/blob/main/database.py"
click node_docs_ui "https://github.com/zain-ahma12/kitabghar/blob/main/custom_docs_ui/docs_ui.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_app,node_book_routes,node_user_routes,node_health,node_client toneBlue
class node_books,node_users toneAmber
class node_auth,node_database,node_sqlite,node_uvicorn toneMint
class node_docs_ui toneRose
```

## Components

### API Surface

- [FastAPI App](https://github.com/zain-ahma12/kitabghar/blob/main/main.py): `main.py`
- [Book Endpoints](https://github.com/zain-ahma12/kitabghar/blob/main/routes/book_routes.py): `routes/book_routes.py`
- [User Endpoints](https://github.com/zain-ahma12/kitabghar/blob/main/routes/users_routes.py): `routes/users_routes.py`
- [Health Check](https://github.com/zain-ahma12/kitabghar/blob/main/main.py): `main.py`

### Lending Domain

- [Book State and Lending](https://github.com/zain-ahma12/kitabghar/blob/main/models/books.py): `models/books.py`
- [Member Records](https://github.com/zain-ahma12/kitabghar/blob/main/models/users.py): `models/users.py`

### Persistence and Access

- [API Key Check](https://github.com/zain-ahma12/kitabghar/blob/main/auth.py): `auth.py`
- [Session and Tables](https://github.com/zain-ahma12/kitabghar/blob/main/database.py): `database.py`
- **SQLite Store**

### API Docs

- [Custom Swagger UI](https://github.com/zain-ahma12/kitabghar/blob/main/custom_docs_ui/docs_ui.py): `custom_docs_ui/docs_ui.py`

### Other components

- **API Client**
- **Uvicorn Server**

## Connections

- API Client → Uvicorn Server: sends requests (evidence: `README.md`)
- Uvicorn Server → FastAPI App: serves app (evidence: `README.md`)
- FastAPI App → Book Endpoints: registers router (evidence: `main.py`)
- FastAPI App → User Endpoints: registers router (evidence: `main.py`)
- API Client → Health Check: requests liveness (evidence: `README.md`)
- FastAPI App → Health Check: routes health (evidence: `main.py`)
- Book Endpoints → Book State and Lending: calls lending rules (evidence: `routes/book_routes.py`)
- User Endpoints → Member Records: converts member data (evidence: `routes/users_routes.py`)
- Book Endpoints → Session and Tables: requests sessions (evidence: `routes/book_routes.py`)
- User Endpoints → Session and Tables: requests sessions (evidence: `routes/users_routes.py`)
- Book Endpoints → API Key Check: checks protected routes (evidence: `routes/book_routes.py`)
- User Endpoints → API Key Check: checks protected routes (evidence: `routes/users_routes.py`)
- Book State and Lending → Member Records: links borrower (evidence: `models/books.py`)
- Member Records → Book State and Lending: relates borrowed books (evidence: `models/users.py`)
- FastAPI App → Session and Tables: creates tables (evidence: `main.py`)
- Session and Tables → SQLite Store: stores records (evidence: `README.md`)
- FastAPI App → Custom Swagger UI: configures docs (evidence: `main.py`)
- API Client → Custom Swagger UI: views API docs (evidence: `README.md`)
