# arn101/ssh-library-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/arn101/ssh-library-management-system
- Repository: https://github.com/arn101/ssh-library-management-system

## Overview

#### Purpose and deployment shape
SSH Library Management System is a role-based full-stack application for library circulation and reading-room seating. React/Vite is deployed separately from an Express API, with hosting configuration for Netlify and Render: `netlify.toml`, `render.yaml`, `docs/DEPLOYMENT.md`. MySQL 8 is the system of record, defined in `db/schema.sql`.

#### Application entry points
The frontend boots React from `frontend/src/main.jsx` into `frontend/src/App.jsx`; route composition is centralized in `frontend/src/routes/Routes.jsx` with separate student and administrator route definitions. The API server starts from `backend/index.js`, initializes the database pool through `backend/config/db.js`, and mounts auth, book, reservation, and seat routers.

#### Identity, roles, and protected navigation
Authentication is JWT-based, with bcrypt credential handling and refresh-token cookie support. Backend identity endpoints and token mechanics live in `backend/routes/authRoutes.js`, `backend/controllers/authController.js`, and `backend/utils/tokens.js`. `backend/middleware/authMiddleware.js` establishes authenticated request context, while `backend/middleware/roleMiddleware.js` gates librarian-only operations. On the client, auth state and API mutations are managed by `frontend/src/redux/features/auth/authSlice.js` and `frontend/src/redux/features/auth/authApi.js`; `frontend/src/components/layout/ProtectedRoute.jsx` protects role-specific screens.

#### API-to-client data boundary
The frontend uses Redux Toolkit with RTK Query as its API boundary. `frontend/src/redux/api/baseApi.js` supplies the shared API client; domain endpoints are injected by `frontend/src/redux/features/book/bookApi.js`, `frontend/src/redux/features/reservation/reservationApi.js`, and `frontend/src/redux/features/seat/seatApi.js`. API base URL is environment-controlled, allowing the Vite client to target local Express or deployed Render services.

#### Library catalog and inventory
Books flow from MySQL through the book router/controller layer to distinct student catalog and librarian inventory views. Core server endpoints are in `backend/routes/bookRoutes.js` and `backend/controllers/bookController.js`; output shaping is handled by `backend/utils/bookMapper.js`. Students browse/filter the catalog at `frontend/src/pages/BookCatalog.jsx`; librarians perform inventory administration from `frontend/src/pages/BookInventory.jsx`. Seed data and cover acquisition support the initial catalog via `backend/data/books-seed.js` and `backend/scripts/seed-books.js`.

#### Reservation circulation workflow
Reservations are the circulation state machine: students create and cancel pending requests; librarians issue or mark returned reservations. Server-side request handling is separated into `backend/routes/reservationRoutes.js`, `backend/controllers/reservationController.js`, and `backend/utils/reservationMapper.js`. The student-facing history/action surface is `frontend/src/pages/MyReservations.jsx`; librarian approval and lifecycle control is `frontend/src/pages/ReservationPanel.jsx`. Authorization boundaries ensure student actions apply to their own reservations and librarians manage circulation transitions.

#### Reading-room seating
Seat booking is a separate resource flow from book reservations. The Express seat API (`backend/routes/seatRoutes.js`, `backend/controllers/seatController.js`) reads and updates seating state persisted in MySQL. Students use the live-polled seat grid at `frontend/src/pages/ReadingRoom.jsx`; librarians observe occupancy and occupant information at `frontend/src/pages/SeatingMonitor.jsx`. RTK Query seat endpoints in `frontend/src/redux/features/seat/seatApi.js` provide client fetch/mutation and polling integration.

#### Static assets and operational boundaries
Book cover images are local static assets under `frontend/public/covers`, produced by `backend/scripts/download-covers.js`; client URL resolution is isolated in `frontend/src/utils/coverUrl.js`. Backend public storage also exists at `backend/public/covers`, creating an operational asset boundary separate from API/database data. Environment files configure DB credentials, JWT secrets, and frontend API origin: `backend/.env.example`, `frontend/.env.example`.

Main entry points: [`frontend/src/routes/Routes.jsx`](https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/routes/Routes.jsx) (Role-based routes), [`backend/index.js`](https://github.com/arn101/ssh-library-management-system/blob/main/backend/index.js) (Express server), [`frontend/src/redux/api/baseApi.js`](https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/redux/api/baseApi.js) (RTK Query client), [`backend/middleware/authMiddleware.js`](https://github.com/arn101/ssh-library-management-system/blob/main/backend/middleware/authMiddleware.js) (Auth and role gates)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React/Vite client"]
  node_client_boot["React bootstrap<br/>React entry<br/>[main.jsx]"]
  node_client_routes["Role-based routes<br/>route composition<br/>[Routes.jsx]"]
  node_auth_client["Auth state<br/>Redux auth<br/>[authSlice.js]"]
  node_protected_routes["Protected navigation<br/>route guard<br/>[ProtectedRoute.jsx]"]
  node_rtk_api["RTK Query client<br/>API boundary<br/>[baseApi.js]"]
  node_student_catalog["Student catalog<br/>student screen<br/>[BookCatalog.jsx]"]
  node_student_reservations["My reservations<br/>student screen<br/>[MyReservations.jsx]"]
  node_reading_room["Reading room<br/>student screen<br/>[ReadingRoom.jsx]"]
  node_librarian_screens["Librarian operations<br/>admin screens<br/>[BookInventory.jsx]"]
end

subgraph group_backend["Express API"]
  node_api_server["Express server<br/>API entry<br/>[index.js]"]
  node_auth_api["Auth controller<br/>identity API<br/>[authController.js]"]
  node_access_control["Auth and role gates<br/>middleware<br/>[authMiddleware.js]"]
  node_book_api["Book API<br/>catalog API<br/>[bookController.js]"]
  node_reservation_api["Reservation API<br/>circulation API"]
  node_seat_api["Seat API<br/>seating API<br/>[seatController.js]"]
end

subgraph group_data["Data and assets"]
  node_mysql[("MySQL 8<br/>system of record<br/>[schema.sql]")]
  node_cover_assets["Book cover assets<br/>static media"]
end

subgraph group_deploy["Deployment"]
  node_netlify{{"Netlify frontend<br/>client hosting<br/>[netlify.toml]"}}
  node_render{{"Render API service<br/>API hosting<br/>[render.yaml]"}}
end

node_client_boot -->|"renders"| node_client_routes
node_client_routes -->|"guards role screens"| node_protected_routes
node_auth_client -->|"supplies session state"| node_protected_routes
node_client_routes -->|"student route"| node_student_catalog
node_client_routes -->|"student route"| node_student_reservations
node_client_routes -->|"student route"| node_reading_room
node_client_routes -->|"librarian routes"| node_librarian_screens
node_student_catalog -->|"book queries"| node_rtk_api
node_student_reservations -->|"reservation mutations"| node_rtk_api
node_reading_room -->|"seat polling"| node_rtk_api
node_librarian_screens -->|"admin operations"| node_rtk_api
node_auth_client -->|"login and refresh"| node_api_server
node_rtk_api -->|"HTTP API"| node_api_server
node_api_server -->|"auth routes"| node_auth_api
node_api_server -->|"protected requests"| node_access_control
node_access_control -->|"authorizes inventory"| node_book_api
node_access_control -->|"authorizes circulation"| node_reservation_api
node_access_control -->|"authorizes seating"| node_seat_api
node_auth_api -->|"users and tokens"| node_mysql
node_book_api -->|"books and inventory"| node_mysql
node_reservation_api -->|"reservation state"| node_mysql
node_seat_api -->|"seat state"| node_mysql
node_student_catalog -->|"cover URLs"| node_cover_assets
node_netlify -->|"serves client"| node_client_boot
node_render -->|"runs API"| node_api_server

click node_client_boot "https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/main.jsx"
click node_client_routes "https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/routes/Routes.jsx"
click node_auth_client "https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/redux/features/auth/authSlice.js"
click node_protected_routes "https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/components/layout/ProtectedRoute.jsx"
click node_rtk_api "https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/redux/api/baseApi.js"
click node_student_catalog "https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/pages/BookCatalog.jsx"
click node_student_reservations "https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/pages/MyReservations.jsx"
click node_reading_room "https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/pages/ReadingRoom.jsx"
click node_librarian_screens "https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/pages/BookInventory.jsx"
click node_api_server "https://github.com/arn101/ssh-library-management-system/blob/main/backend/index.js"
click node_auth_api "https://github.com/arn101/ssh-library-management-system/blob/main/backend/controllers/authController.js"
click node_access_control "https://github.com/arn101/ssh-library-management-system/blob/main/backend/middleware/authMiddleware.js"
click node_book_api "https://github.com/arn101/ssh-library-management-system/blob/main/backend/controllers/bookController.js"
click node_reservation_api "https://github.com/arn101/ssh-library-management-system/blob/main/backend/controllers/reservationController.js"
click node_seat_api "https://github.com/arn101/ssh-library-management-system/blob/main/backend/controllers/seatController.js"
click node_mysql "https://github.com/arn101/ssh-library-management-system/blob/main/db/schema.sql"
click node_cover_assets "https://github.com/arn101/ssh-library-management-system/tree/main/frontend/public/covers"
click node_netlify "https://github.com/arn101/ssh-library-management-system/blob/main/netlify.toml"
click node_render "https://github.com/arn101/ssh-library-management-system/blob/main/render.yaml"

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_client_boot,node_client_routes,node_auth_client,node_protected_routes,node_rtk_api,node_student_catalog,node_student_reservations,node_reading_room,node_librarian_screens toneBlue
class node_api_server,node_auth_api,node_access_control,node_book_api,node_reservation_api,node_seat_api toneAmber
class node_mysql,node_cover_assets toneMint
class node_netlify,node_render toneRose
```

## Components

### React/Vite client

- [React bootstrap](https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/main.jsx): React entry · `frontend/src/main.jsx`
- [Role-based routes](https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/routes/Routes.jsx): route composition · Composes separate student and administrator screens. · `frontend/src/routes/Routes.jsx`
- [Auth state](https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/redux/features/auth/authSlice.js): Redux auth · `frontend/src/redux/features/auth/authSlice.js`
- [Protected navigation](https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/components/layout/ProtectedRoute.jsx): route guard · `frontend/src/components/layout/ProtectedRoute.jsx`
- [RTK Query client](https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/redux/api/baseApi.js): API boundary · Shared environment-configured API client. · `frontend/src/redux/api/baseApi.js`
- [Student catalog](https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/pages/BookCatalog.jsx): student screen · `frontend/src/pages/BookCatalog.jsx`
- [My reservations](https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/pages/MyReservations.jsx): student screen · `frontend/src/pages/MyReservations.jsx`
- [Reading room](https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/pages/ReadingRoom.jsx): student screen · Live-polled seat grid. · `frontend/src/pages/ReadingRoom.jsx`
- [Librarian operations](https://github.com/arn101/ssh-library-management-system/blob/main/frontend/src/pages/BookInventory.jsx): admin screens · Inventory, circulation, and seating oversight. · `frontend/src/pages/BookInventory.jsx`

### Express API

- [Express server](https://github.com/arn101/ssh-library-management-system/blob/main/backend/index.js): API entry · Mounts auth, book, reservation, and seat routers. · `backend/index.js`
- [Auth controller](https://github.com/arn101/ssh-library-management-system/blob/main/backend/controllers/authController.js): identity API · Handles credentials, JWTs, and refresh-token cookies. · `backend/controllers/authController.js`
- [Auth and role gates](https://github.com/arn101/ssh-library-management-system/blob/main/backend/middleware/authMiddleware.js): middleware · Establishes request identity and restricts librarian operations. · `backend/middleware/authMiddleware.js`
- [Book API](https://github.com/arn101/ssh-library-management-system/blob/main/backend/controllers/bookController.js): catalog API · Routes and shapes catalog and inventory data. · `backend/controllers/bookController.js`
- [Reservation API](https://github.com/arn101/ssh-library-management-system/blob/main/backend/controllers/reservationController.js): circulation API · Enforces student ownership and librarian lifecycle transitions. · `backend/controllers/reservationController.js`
- [Seat API](https://github.com/arn101/ssh-library-management-system/blob/main/backend/controllers/seatController.js): seating API · Reads and updates reading-room occupancy. · `backend/controllers/seatController.js`

### Data and assets

- [MySQL 8](https://github.com/arn101/ssh-library-management-system/blob/main/db/schema.sql): system of record · Stores identities, books, reservations, and seating state. · `db/schema.sql`
- [Book cover assets](https://github.com/arn101/ssh-library-management-system/tree/main/frontend/public/covers): static media · Local client and backend cover storage. · `frontend/public/covers`

### Deployment

- [Netlify frontend](https://github.com/arn101/ssh-library-management-system/blob/main/netlify.toml): client hosting · `netlify.toml`
- [Render API service](https://github.com/arn101/ssh-library-management-system/blob/main/render.yaml): API hosting · `render.yaml`

## Connections

- React bootstrap → Role-based routes: renders
- Role-based routes → Protected navigation: guards role screens
- Auth state → Protected navigation: supplies session state
- Role-based routes → Student catalog: student route
- Role-based routes → My reservations: student route
- Role-based routes → Reading room: student route
- Role-based routes → Librarian operations: librarian routes
- Student catalog → RTK Query client: book queries
- My reservations → RTK Query client: reservation mutations
- Reading room → RTK Query client: seat polling
- Librarian operations → RTK Query client: admin operations
- Auth state → Express server: login and refresh
- RTK Query client → Express server: HTTP API
- Express server → Auth controller: auth routes
- Express server → Auth and role gates: protected requests
- Auth and role gates → Book API: authorizes inventory
- Auth and role gates → Reservation API: authorizes circulation
- Auth and role gates → Seat API: authorizes seating
- Auth controller → MySQL 8: users and tokens
- Book API → MySQL 8: books and inventory
- Reservation API → MySQL 8: reservation state
- Seat API → MySQL 8: seat state
- Student catalog → Book cover assets: cover URLs
- Netlify frontend → React bootstrap: serves client
- Render API service → Express server: runs API
