# tranquangthanh902-source/library-management architecture

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

- Interactive diagram: https://gitdiagram.com/tranquangthanh902-source/library-management
- Repository: https://github.com/tranquangthanh902-source/library-management

## Overview

Thư Viện Số is an Express/EJS library-management web app backed by SQLite. A visitor can browse or search books publicly; an administrator signs in, manages books and readers, records loans and returns, and reviews overdue and usage statistics. The principal stages are authentication, catalog/member management, circulation, and reporting, with SQLite as the shared state layer. The graph follows the sampled server and route code; README capabilities such as responsive presentation and print reporting are represented by the relevant view layer, while unsampled details are not expanded.

Main entry points: [`server.js`](https://github.com/tranquangthanh902-source/library-management/blob/main/server.js) (Express server), [`database/init.js`](https://github.com/tranquangthanh902-source/library-management/blob/main/database/init.js) (SQLite library data), [`middleware/auth.js`](https://github.com/tranquangthanh902-source/library-management/blob/main/middleware/auth.js) (Login guard), [`routes/index.js`](https://github.com/tranquangthanh902-source/library-management/blob/main/routes/index.js) (Landing page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web runtime"]
  node_server["Express server<br/>[server.js]"]
  node_authmw["Login guard<br/>[auth.js]"]
  node_store[("SQLite library data<br/>[init.js]")]
  node_assets["Browser assets"]
end

subgraph group_access["Access and discovery"]
  node_auth["Authentication<br/>[auth.js]"]
  node_publicsearch["Public book search<br/>[search.js]"]
  node_landing["Landing page<br/>[index.js]"]
  node_searchview["Search screen<br/>[search.ejs]"]
end

subgraph group_catalog["Catalog and readers"]
  node_bookroutes["Book management<br/>[books.js]"]
  node_bookviews["Book screens"]
  node_readeroutes["Reader management<br/>[readers.js]"]
  node_readerviews["Reader screens"]
end

subgraph group_circulation["Circulation"]
  node_borrowroutes["Loan and return<br/>[borrow.js]"]
  node_borrowviews["Circulation screens"]
end

subgraph group_insights["Dashboard and reporting"]
  node_dashboard["Dashboard stats<br/>[index.js]"]
  node_dashboardview["Dashboard screen<br/>[dashboard.ejs]"]
  node_reports["Usage reports<br/>[reports.js]"]
  node_reportview["Report screen"]
end

node_browser(("Visitor or admin"))

node_browser -->|"sends requests"| node_server
node_server -->|"dispatches routes"| node_auth
node_server -->|"dispatches routes"| node_publicsearch
node_server -->|"dispatches routes"| node_landing
node_server -->|"guards admin"| node_authmw
node_server -->|"serves files"| node_assets
node_authmw -->|"allows access"| node_bookroutes
node_authmw -->|"allows access"| node_readeroutes
node_authmw -->|"allows access"| node_borrowroutes
node_authmw -->|"allows access"| node_reports
node_auth -->|"reads and writes"| node_store
node_publicsearch -->|"queries books"| node_store
node_publicsearch -->|"renders results"| node_searchview
node_landing -->|"queries counts"| node_store
node_landing -->|"renders landing"| node_landing
node_server -->|"dispatches routes"| node_bookroutes
node_bookroutes -->|"reads and writes"| node_store
node_bookroutes -->|"renders screens"| node_bookviews
node_server -->|"dispatches routes"| node_readeroutes
node_readeroutes -->|"reads and writes"| node_store
node_readeroutes -->|"renders screens"| node_readerviews
node_server -->|"dispatches routes"| node_borrowroutes
node_borrowroutes -->|"updates loans and stock"| node_store
node_borrowroutes -->|"renders screens"| node_borrowviews
node_server -->|"dispatches route"| node_dashboard
node_dashboard -->|"queries metrics"| node_store
node_dashboard -->|"renders dashboard"| node_dashboardview
node_server -->|"dispatches routes"| node_reports
node_reports -->|"queries statistics"| node_store
node_reports -->|"renders report"| node_reportview

click node_server "https://github.com/tranquangthanh902-source/library-management/blob/main/server.js"
click node_authmw "https://github.com/tranquangthanh902-source/library-management/blob/main/middleware/auth.js"
click node_store "https://github.com/tranquangthanh902-source/library-management/blob/main/database/init.js"
click node_auth "https://github.com/tranquangthanh902-source/library-management/blob/main/routes/auth.js"
click node_publicsearch "https://github.com/tranquangthanh902-source/library-management/blob/main/routes/search.js"
click node_landing "https://github.com/tranquangthanh902-source/library-management/blob/main/routes/index.js"
click node_bookroutes "https://github.com/tranquangthanh902-source/library-management/blob/main/routes/books.js"
click node_bookviews "https://github.com/tranquangthanh902-source/library-management/tree/main/views/books"
click node_readeroutes "https://github.com/tranquangthanh902-source/library-management/blob/main/routes/readers.js"
click node_readerviews "https://github.com/tranquangthanh902-source/library-management/tree/main/views/readers"
click node_borrowroutes "https://github.com/tranquangthanh902-source/library-management/blob/main/routes/borrow.js"
click node_borrowviews "https://github.com/tranquangthanh902-source/library-management/tree/main/views/borrow"
click node_dashboard "https://github.com/tranquangthanh902-source/library-management/blob/main/routes/index.js"
click node_dashboardview "https://github.com/tranquangthanh902-source/library-management/blob/main/views/dashboard.ejs"
click node_reports "https://github.com/tranquangthanh902-source/library-management/blob/main/routes/reports.js"
click node_reportview "https://github.com/tranquangthanh902-source/library-management/tree/main/views/reports"
click node_searchview "https://github.com/tranquangthanh902-source/library-management/blob/main/views/search.ejs"
click node_assets "https://github.com/tranquangthanh902-source/library-management/tree/main/public"

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_server,node_authmw,node_store,node_assets toneBlue
class node_auth,node_publicsearch,node_landing,node_searchview toneAmber
class node_bookroutes,node_bookviews,node_readeroutes,node_readerviews toneMint
class node_borrowroutes,node_borrowviews toneRose
class node_dashboard,node_dashboardview,node_reports,node_reportview,node_browser toneIndigo
```

## Components

### Web runtime

- [Express server](https://github.com/tranquangthanh902-source/library-management/blob/main/server.js): `server.js`
- [Login guard](https://github.com/tranquangthanh902-source/library-management/blob/main/middleware/auth.js): `middleware/auth.js`
- [SQLite library data](https://github.com/tranquangthanh902-source/library-management/blob/main/database/init.js): `database/init.js`
- [Browser assets](https://github.com/tranquangthanh902-source/library-management/tree/main/public): `public`

### Access and discovery

- [Authentication](https://github.com/tranquangthanh902-source/library-management/blob/main/routes/auth.js): `routes/auth.js`
- [Public book search](https://github.com/tranquangthanh902-source/library-management/blob/main/routes/search.js): `routes/search.js`
- [Landing page](https://github.com/tranquangthanh902-source/library-management/blob/main/routes/index.js): `routes/index.js`
- [Search screen](https://github.com/tranquangthanh902-source/library-management/blob/main/views/search.ejs): `views/search.ejs`

### Catalog and readers

- [Book management](https://github.com/tranquangthanh902-source/library-management/blob/main/routes/books.js): `routes/books.js`
- [Book screens](https://github.com/tranquangthanh902-source/library-management/tree/main/views/books): `views/books`
- [Reader management](https://github.com/tranquangthanh902-source/library-management/blob/main/routes/readers.js): `routes/readers.js`
- [Reader screens](https://github.com/tranquangthanh902-source/library-management/tree/main/views/readers): `views/readers`

### Circulation

- [Loan and return](https://github.com/tranquangthanh902-source/library-management/blob/main/routes/borrow.js): `routes/borrow.js`
- [Circulation screens](https://github.com/tranquangthanh902-source/library-management/tree/main/views/borrow): `views/borrow`

### Dashboard and reporting

- [Dashboard stats](https://github.com/tranquangthanh902-source/library-management/blob/main/routes/index.js): `routes/index.js`
- [Dashboard screen](https://github.com/tranquangthanh902-source/library-management/blob/main/views/dashboard.ejs): `views/dashboard.ejs`
- [Usage reports](https://github.com/tranquangthanh902-source/library-management/blob/main/routes/reports.js): `routes/reports.js`
- [Report screen](https://github.com/tranquangthanh902-source/library-management/tree/main/views/reports): `views/reports`

### Other components

- **Visitor or admin**

## Connections

- Visitor or admin → Express server: sends requests
- Express server → Authentication: dispatches routes
- Express server → Public book search: dispatches routes
- Express server → Landing page: dispatches routes
- Express server → Login guard: guards admin
- Express server → Browser assets: serves files
- Login guard → Book management: allows access
- Login guard → Reader management: allows access
- Login guard → Loan and return: allows access
- Login guard → Usage reports: allows access
- Authentication → SQLite library data: reads and writes
- Public book search → SQLite library data: queries books
- Public book search → Search screen: renders results
- Landing page → SQLite library data: queries counts
- Landing page → Landing page: renders landing
- Express server → Book management: dispatches routes
- Book management → SQLite library data: reads and writes
- Book management → Book screens: renders screens
- Express server → Reader management: dispatches routes
- Reader management → SQLite library data: reads and writes
- Reader management → Reader screens: renders screens
- Express server → Loan and return: dispatches routes
- Loan and return → SQLite library data: updates loans and stock
- Loan and return → Circulation screens: renders screens
- Express server → Dashboard stats: dispatches route
- Dashboard stats → SQLite library data: queries metrics
- Dashboard stats → Dashboard screen: renders dashboard
- Express server → Usage reports: dispatches routes
- Usage reports → SQLite library data: queries statistics
- Usage reports → Report screen: renders report
