# yousefshihan152-rgb/last-book architecture

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

- Interactive diagram: https://gitdiagram.com/yousefshihan152-rgb/last-book
- Repository: https://github.com/yousefshihan152-rgb/last-book

## Overview

Last Book is a session-based online bookstore. Shoppers browse categories and books, register or sign in, manage a cart, and submit delivery orders. The main request path runs through Express routing and controllers; the controllers handle catalog, account, cart, and order operations against MySQL. The graph separates these domain responsibilities even though they share one controller file. Source excerpts show the main routing and database interactions; unsampled view behavior and schema details are not inferred.

Main entry points: [`router/router.js`](https://github.com/yousefshihan152-rgb/last-book/blob/main/router/router.js) (Route dispatch), [`model/db.js`](https://github.com/yousefshihan152-rgb/last-book/blob/main/model/db.js) (MySQL pool), [`index.js`](https://github.com/yousefshihan152-rgb/last-book/blob/main/index.js) (Express app), [`controllers/controllers.js`](https://github.com/yousefshihan152-rgb/last-book/blob/main/controllers/controllers.js) (Catalog handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP application"]
  node_app["Express app<br/>[index.js]"]
  node_routes["Route dispatch<br/>[router.js]"]
  node_views["Page views"]
end

subgraph group_catalog["Book catalog"]
  node_catalog_handlers["Catalog handlers<br/>[controllers.js]"]
  node_categories["Category definitions<br/>[categories.js]"]
end

subgraph group_accounts["Accounts and sessions"]
  node_account_handlers["Account handlers<br/>[controllers.js]"]
  node_login_guard["Login guards<br/>[auth.js]"]
  node_session_setup["Session setup<br/>[index.js]"]
end

subgraph group_commerce["Cart and orders"]
  node_cart_handlers["Cart handlers<br/>[controllers.js]"]
  node_order_handlers["Order handlers<br/>[controllers.js]"]
end

subgraph group_support["Shared services"]
  node_mysql_pool[("MySQL pool<br/>[db.js]")]
  node_security_check["Input checks<br/>[security.js]"]
  node_error_handling["Error handling<br/>[error.js]"]
end

node_shopper(("Shopper"))

node_shopper -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_routes
node_app -->|"checks inputs"| node_security_check
node_app -->|"handles errors"| node_error_handling
node_routes -->|"dispatches catalog"| node_catalog_handlers
node_routes -->|"dispatches account"| node_account_handlers
node_routes -->|"dispatches cart"| node_cart_handlers
node_routes -->|"dispatches orders"| node_order_handlers
node_routes -->|"guards private routes"| node_login_guard
node_catalog_handlers -->|"looks up categories"| node_categories
node_catalog_handlers -->|"queries books"| node_mysql_pool
node_catalog_handlers -->|"serves pages"| node_views
node_account_handlers -->|"reads and writes users"| node_mysql_pool
node_account_handlers -->|"serves login page"| node_views
node_cart_handlers -->|"reads and writes cart"| node_mysql_pool
node_order_handlers -->|"creates orders"| node_mysql_pool
node_session_setup -->|"stores sessions"| node_mysql_pool
node_account_handlers -->|"wraps async errors"| node_error_handling
node_security_check -->|"forwards rejected input"| node_error_handling

click node_app "https://github.com/yousefshihan152-rgb/last-book/blob/main/index.js"
click node_routes "https://github.com/yousefshihan152-rgb/last-book/blob/main/router/router.js"
click node_views "https://github.com/yousefshihan152-rgb/last-book/tree/main/views"
click node_catalog_handlers "https://github.com/yousefshihan152-rgb/last-book/blob/main/controllers/controllers.js"
click node_categories "https://github.com/yousefshihan152-rgb/last-book/blob/main/model/categories.js"
click node_account_handlers "https://github.com/yousefshihan152-rgb/last-book/blob/main/controllers/controllers.js"
click node_login_guard "https://github.com/yousefshihan152-rgb/last-book/blob/main/middlewares/auth.js"
click node_session_setup "https://github.com/yousefshihan152-rgb/last-book/blob/main/index.js"
click node_cart_handlers "https://github.com/yousefshihan152-rgb/last-book/blob/main/controllers/controllers.js"
click node_order_handlers "https://github.com/yousefshihan152-rgb/last-book/blob/main/controllers/controllers.js"
click node_mysql_pool "https://github.com/yousefshihan152-rgb/last-book/blob/main/model/db.js"
click node_security_check "https://github.com/yousefshihan152-rgb/last-book/blob/main/middlewares/security.js"
click node_error_handling "https://github.com/yousefshihan152-rgb/last-book/blob/main/middlewares/error.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_app,node_routes,node_views toneBlue
class node_catalog_handlers,node_categories toneAmber
class node_account_handlers,node_login_guard,node_session_setup toneMint
class node_cart_handlers,node_order_handlers toneRose
class node_mysql_pool,node_security_check,node_error_handling,node_shopper toneIndigo
```

## Components

### HTTP application

- [Express app](https://github.com/yousefshihan152-rgb/last-book/blob/main/index.js): `index.js`
- [Route dispatch](https://github.com/yousefshihan152-rgb/last-book/blob/main/router/router.js): `router/router.js`
- [Page views](https://github.com/yousefshihan152-rgb/last-book/tree/main/views): `views`

### Book catalog

- [Catalog handlers](https://github.com/yousefshihan152-rgb/last-book/blob/main/controllers/controllers.js): `controllers/controllers.js`
- [Category definitions](https://github.com/yousefshihan152-rgb/last-book/blob/main/model/categories.js): `model/categories.js`

### Accounts and sessions

- [Account handlers](https://github.com/yousefshihan152-rgb/last-book/blob/main/controllers/controllers.js): `controllers/controllers.js`
- [Login guards](https://github.com/yousefshihan152-rgb/last-book/blob/main/middlewares/auth.js): `middlewares/auth.js`
- [Session setup](https://github.com/yousefshihan152-rgb/last-book/blob/main/index.js): `index.js`

### Cart and orders

- [Cart handlers](https://github.com/yousefshihan152-rgb/last-book/blob/main/controllers/controllers.js): `controllers/controllers.js`
- [Order handlers](https://github.com/yousefshihan152-rgb/last-book/blob/main/controllers/controllers.js): `controllers/controllers.js`

### Shared services

- [MySQL pool](https://github.com/yousefshihan152-rgb/last-book/blob/main/model/db.js): `model/db.js`
- [Input checks](https://github.com/yousefshihan152-rgb/last-book/blob/main/middlewares/security.js): `middlewares/security.js`
- [Error handling](https://github.com/yousefshihan152-rgb/last-book/blob/main/middlewares/error.js): `middlewares/error.js`

### Other components

- **Shopper**

## Connections

- Shopper → Express app: sends requests
- Express app → Route dispatch: mounts routes (evidence: `index.js`)
- Express app → Input checks: checks inputs (evidence: `index.js`)
- Express app → Error handling: handles errors (evidence: `index.js`)
- Route dispatch → Catalog handlers: dispatches catalog (evidence: `router/router.js`)
- Route dispatch → Account handlers: dispatches account (evidence: `router/router.js`)
- Route dispatch → Cart handlers: dispatches cart (evidence: `router/router.js`)
- Route dispatch → Order handlers: dispatches orders (evidence: `router/router.js`)
- Route dispatch → Login guards: guards private routes (evidence: `router/router.js`)
- Catalog handlers → Category definitions: looks up categories (evidence: `controllers/controllers.js`)
- Catalog handlers → MySQL pool: queries books (evidence: `controllers/controllers.js`)
- Catalog handlers → Page views: serves pages (evidence: `controllers/controllers.js`)
- Account handlers → MySQL pool: reads and writes users (evidence: `controllers/controllers.js`)
- Account handlers → Page views: serves login page (evidence: `controllers/controllers.js`)
- Cart handlers → MySQL pool: reads and writes cart (evidence: `controllers/controllers.js`)
- Order handlers → MySQL pool: creates orders (evidence: `controllers/controllers.js`)
- Session setup → MySQL pool: stores sessions (evidence: `index.js`)
- Account handlers → Error handling: wraps async errors (evidence: `controllers/controllers.js`)
- Input checks → Error handling: forwards rejected input (evidence: `middlewares/security.js`)
