# vaidik-410/library-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/vaidik-410/library-management-system
- Repository: https://github.com/vaidik-410/library-management-system

## Overview

This is a library-management API: users register and authenticate, books are managed, and admins record borrowing and returns while users can view their loans. Supporting capabilities include password recovery, email notifications, admin/user management, and cleanup of unverified accounts. The graph follows the Express routes into controllers and their model/service dependencies. Some route and service links rely on SOURCE INDEX references rather than excerpts; external database and mail configuration are represented only where the shown code supports them.

Main entry points: [`app.js`](https://github.com/vaidik-410/library-management-system/blob/main/app.js) (Express application), [`controllers/authController.js`](https://github.com/vaidik-410/library-management-system/blob/main/controllers/authController.js) (Account workflows), [`controllers/borrowController.js`](https://github.com/vaidik-410/library-management-system/blob/main/controllers/borrowController.js) (Borrow and return), [`models/userModels.js`](https://github.com/vaidik-410/library-management-system/blob/main/models/userModels.js) (User records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_app["Express application<br/>[app.js]"]
  node_auth_routes["Auth routes<br/>[authRouter.js]"]
  node_book_routes["Book routes<br/>[bookRouter.js]"]
  node_borrow_routes["Borrow routes<br/>[borrowRouter.js]"]
  node_user_routes["User routes<br/>[user.Router.js]"]
end

subgraph group_identity["Identity and users"]
  node_auth_middleware["Authentication<br/>[authMiddleware.js]"]
  node_auth_controller["Account workflows<br/>[authController.js]"]
  node_user_controller["User administration<br/>[userController.js]"]
  node_user_model[("User records<br/>[userModels.js]")]
end

subgraph group_catalog["Catalog and borrowing"]
  node_book_controller["Book management<br/>[bookController.js]"]
  node_borrow_controller["Borrow and return"]
  node_book_model[("Book records<br/>[bookModels.js]")]
  node_borrow_model[("Borrow records<br/>[borrowModels.js]")]
  node_fine_calculator["Fine calculator<br/>[fineCalculator.js]"]
end

subgraph group_support["Persistence and services"]
  node_database["Database connection<br/>[db.js]"]
  node_notify["Borrow notifications<br/>[notifyUsers.js]"]
  node_cleanup["Unverified cleanup"]
  node_verification_email["Verification email"]
  node_email_templates["Email templates<br/>[emailTemplates.js]"]
  node_email_sender["Email delivery<br/>[sendEmial.js]"]
  node_token_sender["Token response<br/>[sendToken.js]"]
  node_async_errors["Async error wrapper"]
  node_error_handler["Error handling"]
end

node_client(("API client"))
node_cloudinary{{"Cloudinary"}}
node_smtp{{"SMTP service"}}

node_client -->|"sends requests"| node_app
node_app -->|"mounts auth"| node_auth_routes
node_app -->|"mounts books"| node_book_routes
node_app -->|"mounts borrowing"| node_borrow_routes
node_app -->|"mounts users"| node_user_routes
node_app -->|"connects database"| node_database
node_app -->|"starts service"| node_notify
node_app -->|"starts cleanup"| node_cleanup
node_app -->|"registers errors"| node_error_handler
node_auth_routes -->|"routes requests"| node_auth_controller
node_book_routes -->|"checks access"| node_auth_middleware
node_book_routes -->|"routes requests"| node_book_controller
node_borrow_routes -->|"checks access"| node_auth_middleware
node_borrow_routes -->|"routes requests"| node_borrow_controller
node_user_routes -->|"checks access"| node_auth_middleware
node_user_routes -->|"routes requests"| node_user_controller
node_auth_middleware -->|"loads user"| node_user_model
node_auth_controller -->|"reads and writes"| node_user_model
node_auth_controller -->|"sends verification"| node_verification_email
node_auth_controller -->|"sends recovery email"| node_email_sender
node_auth_controller -->|"builds recovery email"| node_email_templates
node_auth_controller -->|"issues token response"| node_token_sender
node_user_controller -->|"reads and creates"| node_user_model
node_user_controller -.->|"uploads avatar"| node_cloudinary
node_book_controller -->|"manages books"| node_book_model
node_borrow_controller -->|"updates availability"| node_book_model
node_borrow_controller -->|"updates loans"| node_user_model
node_borrow_controller -->|"records transactions"| node_borrow_model
node_borrow_controller -->|"calculates fine"| node_fine_calculator
node_notify -->|"reads loans"| node_borrow_model
node_notify -->|"reads users"| node_user_model
node_notify -->|"sends notifications"| node_email_sender
node_cleanup -->|"removes accounts"| node_user_model
node_verification_email -->|"builds message"| node_email_templates
node_verification_email -->|"delivers message"| node_email_sender
node_email_sender -.->|"sends mail"| node_smtp
node_auth_controller -->|"wraps handlers"| node_async_errors
node_borrow_controller -->|"wraps handlers"| node_async_errors
node_book_controller -->|"wraps handlers"| node_async_errors
node_user_controller -->|"wraps handlers"| node_async_errors

click node_app "https://github.com/vaidik-410/library-management-system/blob/main/app.js"
click node_auth_routes "https://github.com/vaidik-410/library-management-system/blob/main/routes/authRouter.js"
click node_book_routes "https://github.com/vaidik-410/library-management-system/blob/main/routes/bookRouter.js"
click node_borrow_routes "https://github.com/vaidik-410/library-management-system/blob/main/routes/borrowRouter.js"
click node_user_routes "https://github.com/vaidik-410/library-management-system/blob/main/routes/user.Router.js"
click node_auth_middleware "https://github.com/vaidik-410/library-management-system/blob/main/middlewares/authMiddleware.js"
click node_auth_controller "https://github.com/vaidik-410/library-management-system/blob/main/controllers/authController.js"
click node_user_controller "https://github.com/vaidik-410/library-management-system/blob/main/controllers/userController.js"
click node_user_model "https://github.com/vaidik-410/library-management-system/blob/main/models/userModels.js"
click node_book_controller "https://github.com/vaidik-410/library-management-system/blob/main/controllers/bookController.js"
click node_borrow_controller "https://github.com/vaidik-410/library-management-system/blob/main/controllers/borrowController.js"
click node_book_model "https://github.com/vaidik-410/library-management-system/blob/main/models/bookModels.js"
click node_borrow_model "https://github.com/vaidik-410/library-management-system/blob/main/models/borrowModels.js"
click node_fine_calculator "https://github.com/vaidik-410/library-management-system/blob/main/utils/fineCalculator.js"
click node_database "https://github.com/vaidik-410/library-management-system/blob/main/database/db.js"
click node_notify "https://github.com/vaidik-410/library-management-system/blob/main/services/notifyUsers.js"
click node_cleanup "https://github.com/vaidik-410/library-management-system/blob/main/services/removeUnverifiedAccounts.js"
click node_verification_email "https://github.com/vaidik-410/library-management-system/blob/main/utils/sendVerificationCode.js"
click node_email_templates "https://github.com/vaidik-410/library-management-system/blob/main/utils/emailTemplates.js"
click node_email_sender "https://github.com/vaidik-410/library-management-system/blob/main/utils/sendEmial.js"
click node_token_sender "https://github.com/vaidik-410/library-management-system/blob/main/utils/sendToken.js"
click node_async_errors "https://github.com/vaidik-410/library-management-system/blob/main/middlewares/catchAsyncErrors.js"
click node_error_handler "https://github.com/vaidik-410/library-management-system/blob/main/middlewares/errorMiddlewares.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_auth_routes,node_book_routes,node_borrow_routes,node_user_routes,node_client toneBlue
class node_auth_middleware,node_auth_controller,node_user_controller,node_user_model toneAmber
class node_book_controller,node_borrow_controller,node_book_model,node_borrow_model,node_fine_calculator toneMint
class node_database,node_notify,node_cleanup,node_verification_email,node_email_templates,node_email_sender,node_token_sender,node_async_errors,node_error_handler toneRose
class node_cloudinary,node_smtp toneIndigo
```

## Components

### API entry

- [Express application](https://github.com/vaidik-410/library-management-system/blob/main/app.js): `app.js`
- [Auth routes](https://github.com/vaidik-410/library-management-system/blob/main/routes/authRouter.js): `routes/authRouter.js`
- [Book routes](https://github.com/vaidik-410/library-management-system/blob/main/routes/bookRouter.js): `routes/bookRouter.js`
- [Borrow routes](https://github.com/vaidik-410/library-management-system/blob/main/routes/borrowRouter.js): `routes/borrowRouter.js`
- [User routes](https://github.com/vaidik-410/library-management-system/blob/main/routes/user.Router.js): `routes/user.Router.js`

### Identity and users

- [Authentication](https://github.com/vaidik-410/library-management-system/blob/main/middlewares/authMiddleware.js): `middlewares/authMiddleware.js`
- [Account workflows](https://github.com/vaidik-410/library-management-system/blob/main/controllers/authController.js): `controllers/authController.js`
- [User administration](https://github.com/vaidik-410/library-management-system/blob/main/controllers/userController.js): `controllers/userController.js`
- [User records](https://github.com/vaidik-410/library-management-system/blob/main/models/userModels.js): `models/userModels.js`

### Catalog and borrowing

- [Book management](https://github.com/vaidik-410/library-management-system/blob/main/controllers/bookController.js): `controllers/bookController.js`
- [Borrow and return](https://github.com/vaidik-410/library-management-system/blob/main/controllers/borrowController.js): `controllers/borrowController.js`
- [Book records](https://github.com/vaidik-410/library-management-system/blob/main/models/bookModels.js): `models/bookModels.js`
- [Borrow records](https://github.com/vaidik-410/library-management-system/blob/main/models/borrowModels.js): `models/borrowModels.js`
- [Fine calculator](https://github.com/vaidik-410/library-management-system/blob/main/utils/fineCalculator.js): `utils/fineCalculator.js`

### Persistence and services

- [Database connection](https://github.com/vaidik-410/library-management-system/blob/main/database/db.js): `database/db.js`
- [Borrow notifications](https://github.com/vaidik-410/library-management-system/blob/main/services/notifyUsers.js): `services/notifyUsers.js`
- [Unverified cleanup](https://github.com/vaidik-410/library-management-system/blob/main/services/removeUnverifiedAccounts.js): `services/removeUnverifiedAccounts.js`
- [Verification email](https://github.com/vaidik-410/library-management-system/blob/main/utils/sendVerificationCode.js): `utils/sendVerificationCode.js`
- [Email templates](https://github.com/vaidik-410/library-management-system/blob/main/utils/emailTemplates.js): `utils/emailTemplates.js`
- [Email delivery](https://github.com/vaidik-410/library-management-system/blob/main/utils/sendEmial.js): `utils/sendEmial.js`
- [Token response](https://github.com/vaidik-410/library-management-system/blob/main/utils/sendToken.js): `utils/sendToken.js`
- [Async error wrapper](https://github.com/vaidik-410/library-management-system/blob/main/middlewares/catchAsyncErrors.js): `middlewares/catchAsyncErrors.js`
- [Error handling](https://github.com/vaidik-410/library-management-system/blob/main/middlewares/errorMiddlewares.js): `middlewares/errorMiddlewares.js`

### Other components

- **API client**
- **Cloudinary**
- **SMTP service**

## Connections

- API client → Express application: sends requests (evidence: `app.js`)
- Express application → Auth routes: mounts auth (evidence: `app.js`)
- Express application → Book routes: mounts books (evidence: `app.js`)
- Express application → Borrow routes: mounts borrowing (evidence: `app.js`)
- Express application → User routes: mounts users (evidence: `app.js`)
- Express application → Database connection: connects database (evidence: `app.js`)
- Express application → Borrow notifications: starts service (evidence: `app.js`)
- Express application → Unverified cleanup: starts cleanup (evidence: `app.js`)
- Express application → Error handling: registers errors (evidence: `app.js`)
- Auth routes → Account workflows: routes requests (evidence: `routes/authRouter.js`)
- Book routes → Authentication: checks access (evidence: `routes/bookRouter.js`)
- Book routes → Book management: routes requests (evidence: `routes/bookRouter.js`)
- Borrow routes → Authentication: checks access (evidence: `routes/borrowRouter.js`)
- Borrow routes → Borrow and return: routes requests (evidence: `routes/borrowRouter.js`)
- User routes → Authentication: checks access (evidence: `routes/user.Router.js`)
- User routes → User administration: routes requests (evidence: `routes/user.Router.js`)
- Authentication → User records: loads user (evidence: `middlewares/authMiddleware.js`)
- Account workflows → User records: reads and writes (evidence: `controllers/authController.js`)
- Account workflows → Verification email: sends verification (evidence: `controllers/authController.js`)
- Account workflows → Email delivery: sends recovery email (evidence: `controllers/authController.js`)
- Account workflows → Email templates: builds recovery email (evidence: `controllers/authController.js`)
- Account workflows → Token response: issues token response (evidence: `controllers/authController.js`)
- User administration → User records: reads and creates (evidence: `controllers/userController.js`)
- User administration → Cloudinary: uploads avatar
- Book management → Book records: manages books (evidence: `controllers/bookController.js`)
- Borrow and return → Book records: updates availability (evidence: `controllers/borrowController.js`)
- Borrow and return → User records: updates loans (evidence: `controllers/borrowController.js`)
- Borrow and return → Borrow records: records transactions (evidence: `controllers/borrowController.js`)
- Borrow and return → Fine calculator: calculates fine (evidence: `controllers/borrowController.js`)
- Borrow notifications → Borrow records: reads loans (evidence: `services/notifyUsers.js`)
- Borrow notifications → User records: reads users (evidence: `services/notifyUsers.js`)
- Borrow notifications → Email delivery: sends notifications (evidence: `services/notifyUsers.js`)
- Unverified cleanup → User records: removes accounts (evidence: `services/removeUnverifiedAccounts.js`)
- Verification email → Email templates: builds message (evidence: `utils/sendVerificationCode.js`)
- Verification email → Email delivery: delivers message (evidence: `utils/sendVerificationCode.js`)
- Email delivery → SMTP service: sends mail
- Account workflows → Async error wrapper: wraps handlers (evidence: `controllers/authController.js`)
- Borrow and return → Async error wrapper: wraps handlers (evidence: `controllers/borrowController.js`)
- Book management → Async error wrapper: wraps handlers (evidence: `controllers/bookController.js`)
- User administration → Async error wrapper: wraps handlers (evidence: `controllers/userController.js`)
