# flaidhack/sistem-peminjaman-buku architecture

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

- Interactive diagram: https://gitdiagram.com/flaidhack/sistem-peminjaman-buku
- Repository: https://github.com/flaidhack/sistem-peminjaman-buku

## Overview

This is a web library-loan system: a browser uses the gateway for login, browsing, borrowing, and returns. The gateway verifies JWTs for protected routes and proxies to three API-key-protected services. Auth owns users, catalog owns book availability, and loan owns active loans; the loan route coordinates user/book checks, database updates, and compensating rollback. The README documents health aggregation and loan limits/due dates. Edges reflect excerpts or README statements; service wiring not shown in excerpts is cited to the README.

Main entry points: [`api-gateway/routes/proxy.js`](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/api-gateway/routes/proxy.js) (Route proxy), [`loan-service/routes/loans.js`](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/loan-service/routes/loans.js) (Borrow and return), [`auth-service/routes/auth.js`](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/auth-service/routes/auth.js) (Login and users), [`catalog-service/routes/books.js`](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/catalog-service/routes/books.js) (Books and availability)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway access"]
  node_frontend["Web interface<br/>[script.js]"]
  node_gateway_proxy["Route proxy<br/>[proxy.js]"]
  node_jwt_check["JWT verification<br/>[verifyJwt.js]"]
  node_health["Health aggregation<br/>[server.js]"]
end

subgraph group_identity["Identity"]
  node_auth_routes["Login and users<br/>[auth.js]"]
  node_auth_db[("User database<br/>[db.js]")]
  node_auth_key["API key guard<br/>[apiKey.js]"]
end

subgraph group_catalog["Book catalog"]
  node_catalog_routes["Books and availability<br/>[books.js]"]
  node_catalog_db[("Book database<br/>[db.js]")]
  node_catalog_key["API key guard<br/>[apiKey.js]"]
end

subgraph group_loans["Loan circulation"]
  node_loan_routes["Borrow and return<br/>[loans.js]"]
  node_loan_db[("Loan database<br/>[db.js]")]
  node_loan_key["API key guard<br/>[apiKey.js]"]
  node_auth_client["User lookup client<br/>[authClient.js]"]
  node_catalog_client["Book lookup client<br/>[catalogClient.js]"]
end

node_reader(("Library user"))

node_reader -->|"uses"| node_frontend
node_frontend -->|"requests API"| node_gateway_proxy
node_gateway_proxy -->|"verifies protected routes"| node_jwt_check
node_gateway_proxy -->|"proxies auth routes"| node_auth_routes
node_gateway_proxy -->|"proxies book routes"| node_catalog_routes
node_gateway_proxy -->|"proxies loan routes"| node_loan_routes
node_gateway_proxy -->|"injects API key"| node_auth_key
node_gateway_proxy -->|"injects API key"| node_catalog_key
node_gateway_proxy -->|"injects API key"| node_loan_key
node_health -->|"checks health"| node_auth_routes
node_health -->|"checks health"| node_catalog_routes
node_health -->|"checks health"| node_loan_routes
node_auth_routes -->|"queries users"| node_auth_db
node_catalog_routes -->|"reads and updates"| node_catalog_db
node_loan_routes -->|"validates user"| node_auth_client
node_auth_client -->|"fetches user"| node_auth_routes
node_loan_routes -->|"checks book and status"| node_catalog_client
node_catalog_client -->|"fetches and updates"| node_catalog_routes
node_loan_routes -->|"records loans"| node_loan_db

click node_frontend "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/frontend/script.js"
click node_gateway_proxy "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/api-gateway/routes/proxy.js"
click node_jwt_check "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/api-gateway/middleware/verifyJwt.js"
click node_health "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/api-gateway/server.js"
click node_auth_routes "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/auth-service/routes/auth.js"
click node_auth_db "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/auth-service/db.js"
click node_auth_key "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/auth-service/middleware/apiKey.js"
click node_catalog_routes "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/catalog-service/routes/books.js"
click node_catalog_db "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/catalog-service/db.js"
click node_catalog_key "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/catalog-service/middleware/apiKey.js"
click node_loan_routes "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/loan-service/routes/loans.js"
click node_loan_db "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/loan-service/db.js"
click node_loan_key "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/loan-service/middleware/apiKey.js"
click node_auth_client "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/loan-service/services/authClient.js"
click node_catalog_client "https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/loan-service/services/catalogClient.js"

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_frontend,node_gateway_proxy,node_jwt_check,node_health,node_reader toneBlue
class node_auth_routes,node_auth_db,node_auth_key toneAmber
class node_catalog_routes,node_catalog_db,node_catalog_key toneMint
class node_loan_routes,node_loan_db,node_loan_key,node_auth_client,node_catalog_client toneRose
```

## Components

### Gateway access

- [Web interface](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/frontend/script.js): `frontend/script.js`
- [Route proxy](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/api-gateway/routes/proxy.js): `api-gateway/routes/proxy.js`
- [JWT verification](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/api-gateway/middleware/verifyJwt.js): `api-gateway/middleware/verifyJwt.js`
- [Health aggregation](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/api-gateway/server.js): `api-gateway/server.js`

### Identity

- [Login and users](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/auth-service/routes/auth.js): `auth-service/routes/auth.js`
- [User database](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/auth-service/db.js): `auth-service/db.js`
- [API key guard](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/auth-service/middleware/apiKey.js): `auth-service/middleware/apiKey.js`

### Book catalog

- [Books and availability](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/catalog-service/routes/books.js): `catalog-service/routes/books.js`
- [Book database](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/catalog-service/db.js): `catalog-service/db.js`
- [API key guard](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/catalog-service/middleware/apiKey.js): `catalog-service/middleware/apiKey.js`

### Loan circulation

- [Borrow and return](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/loan-service/routes/loans.js): `loan-service/routes/loans.js`
- [Loan database](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/loan-service/db.js): `loan-service/db.js`
- [API key guard](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/loan-service/middleware/apiKey.js): `loan-service/middleware/apiKey.js`
- [User lookup client](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/loan-service/services/authClient.js): `loan-service/services/authClient.js`
- [Book lookup client](https://github.com/flaidhack/sistem-peminjaman-buku/blob/main/loan-service/services/catalogClient.js): `loan-service/services/catalogClient.js`

### Other components

- **Library user**

## Connections

- Library user → Web interface: uses (evidence: `README.md`)
- Web interface → Route proxy: requests API (evidence: `README.md`)
- Route proxy → JWT verification: verifies protected routes (evidence: `api-gateway/routes/proxy.js`)
- Route proxy → Login and users: proxies auth routes (evidence: `README.md`)
- Route proxy → Books and availability: proxies book routes (evidence: `api-gateway/routes/proxy.js`)
- Route proxy → Borrow and return: proxies loan routes (evidence: `api-gateway/routes/proxy.js`)
- Route proxy → API key guard: injects API key (evidence: `README.md`)
- Route proxy → API key guard: injects API key (evidence: `api-gateway/routes/proxy.js`)
- Route proxy → API key guard: injects API key (evidence: `README.md`)
- Health aggregation → Login and users: checks health (evidence: `api-gateway/server.js`)
- Health aggregation → Books and availability: checks health (evidence: `api-gateway/server.js`)
- Health aggregation → Borrow and return: checks health (evidence: `api-gateway/server.js`)
- Login and users → User database: queries users (evidence: `auth-service/routes/auth.js`)
- Books and availability → Book database: reads and updates (evidence: `catalog-service/routes/books.js`)
- Borrow and return → User lookup client: validates user (evidence: `loan-service/routes/loans.js`)
- User lookup client → Login and users: fetches user (evidence: `README.md`)
- Borrow and return → Book lookup client: checks book and status (evidence: `loan-service/routes/loans.js`)
- Book lookup client → Books and availability: fetches and updates (evidence: `loan-service/services/catalogClient.js`)
- Borrow and return → Loan database: records loans (evidence: `loan-service/routes/loans.js`)
