# agnitanmay/library-management-system architecture

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

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

## Overview

##### Main Components
- Client/Browser: The frontend is built with HTML5, CSS3, Bootstrap 4, and jQuery. Views are served from the "views" folder (with subfolders for admin and user pages) and static content is housed in the "public" directory.
- Server/Application: The Node.js/Express application which acts as the backend. Entry point is "app.js" with separate directories for controllers, routes, middleware, utilities, and models.
- Database: MongoDB is used, accessed through Mongoose, with different models (activity, book, comment, issue, user) found in the "models" directory.
- Authentication & Session Management: Handled with Passport.js and session middleware; secrets and DB URL are configured via the ".env" file.

##### File Structure
- Top-Level Files: Includes the main application file ("app.js"), environmental configuration (".env"), and package scripts.
- Controllers: Located in the "controllers" folder (admin.js, auth.js, books.js, user.js) which coordinate between the models and views.
- Routes: Divided into components (admin, auth, books, index, users); routes direct HTTP requests to the appropriate controllers.
- Models: It contains the definitions for MongoDB collections (activity, book, comment, issue, user) denoting the “M” in MVC.
- Middleware: Contains custom middleware logic used across routes.
- Views: EJS templates (or plain HTML files) are used to render dynamic content for different modules (admin, user, public pages).
- Utilities: Helpers like the image deletion script under "utils".
- Public Assets: Resources such as CSS, JavaScript, images, and stylesheets that are used on the frontend.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        Client["Client (Browser)"]:::client
        FrontendViews["Frontend: Views"]:::views
        FrontendAssets["Frontend: Static Assets"]:::views
    end

    %% Application Server
    subgraph "Application Server (Express/Node.js)"
        APPEntry["Main Entry (app.js)"]:::server

        subgraph "Routes"
            Routes_Admin["Admin Routes"]:::server
            Routes_Auth["Auth Routes"]:::server
            Routes_Books["Books Routes"]:::server
            Routes_Index["Index Routes"]:::server
            Routes_Users["User Routes"]:::server
        end

        subgraph "Controllers"
            Controller_Admin["Admin Controller"]:::server
            Controller_Auth["Auth Controller"]:::server
            Controller_Books["Books Controller"]:::server
            Controller_User["User Controller"]:::server
        end

        Middleware["Middleware (index.js)"]:::server
        Utilities["Utilities (delete_image.js)"]:::server

        subgraph "Models"
            Model_Activity["Activity Model"]:::server
            Model_Book["Book Model"]:::server
            Model_Comment["Comment Model"]:::server
            Model_Issue["Issue Model"]:::server
            Model_User["User Model"]:::server
        end

        ViewsServer["Views (Templates)"]:::server
        AuthSession["Authentication & Session"]:::server
        EnvConfig["Env Config (.env)"]:::server

        subgraph "Modules"
            Module_Admin["Admin Module"]:::module
            Module_User["User Module"]:::module
            Module_Browse["Browse Books Module"]:::module
        end
    end

    %% Database
    MongoDB["MongoDB"]:::db

    %% Connections from Client to Application
    Client -->|"HTTP_Request"| APPEntry
    APPEntry --> Routes_Admin
    APPEntry --> Routes_Auth
    APPEntry --> Routes_Books
    APPEntry --> Routes_Index
    APPEntry --> Routes_Users

    %% Routes to Controllers / Views
    Routes_Admin --> Controller_Admin
    Routes_Auth --> Controller_Auth
    Routes_Books --> Controller_Books
    Routes_Users --> Controller_User
    Routes_Index --> ViewsServer

    %% Controllers to Modules
    Controller_Admin --> Module_Admin
    Controller_User --> Module_User
    Controller_Books --> Module_Browse

    %% Controllers to Middleware and Utilities (example for Auth)
    Controller_Auth --> Middleware
    Controller_Auth --> Utilities

    %% Controllers to Authentication
    Controller_Auth --> AuthSession

    %% Models interaction from Controllers (sample connections)
    Controller_Admin --> Model_Book
    Controller_Auth --> Model_User
    Controller_Books --> Model_Book
    Controller_User --> Model_User

    %% Models to Database
    Model_Activity -->|"CRUD"| MongoDB
    Model_Book -->|"CRUD"| MongoDB
    Model_Comment -->|"CRUD"| MongoDB
    Model_Issue -->|"CRUD"| MongoDB
    Model_User -->|"CRUD"| MongoDB

    %% Authentication configuration
    AuthSession --> EnvConfig

    %% Response rendering from Server Views to Client
    ViewsServer -->|"renders_HTML"| FrontendViews
    FrontendViews --> Client
    FrontendAssets --> Client

    %% Modules association from Routes and Controllers
    Routes_Admin --> Module_Admin
    Routes_Users --> Module_User
    Routes_Books --> Module_Browse
    Controller_Admin --> Module_Admin
    Controller_User --> Module_User
    Controller_Books --> Module_Browse

    %% Click Events
    click FrontendViews "https://github.com/agnitanmay/library-management-system/tree/master//views"
    click FrontendAssets "https://github.com/agnitanmay/library-management-system/tree/master//public"
    click APPEntry "https://github.com/agnitanmay/library-management-system/blob/master//app.js"
    click Routes_Admin "https://github.com/agnitanmay/library-management-system/blob/master//routes/admin.js"
    click Routes_Auth "https://github.com/agnitanmay/library-management-system/blob/master//routes/auth.js"
    click Routes_Books "https://github.com/agnitanmay/library-management-system/blob/master//routes/books.js"
    click Routes_Index "https://github.com/agnitanmay/library-management-system/blob/master//routes/index.js"
    click Routes_Users "https://github.com/agnitanmay/library-management-system/blob/master//routes/users.js"
    click Controller_Admin "https://github.com/agnitanmay/library-management-system/blob/master//controllers/admin.js"
    click Controller_Auth "https://github.com/agnitanmay/library-management-system/blob/master//controllers/auth.js"
    click Controller_Books "https://github.com/agnitanmay/library-management-system/blob/master//controllers/books.js"
    click Controller_User "https://github.com/agnitanmay/library-management-system/blob/master//controllers/user.js"
    click Middleware "https://github.com/agnitanmay/library-management-system/blob/master//middleware/index.js"
    click Utilities "https://github.com/agnitanmay/library-management-system/blob/master//utils/delete_image.js"
    click Model_Activity "https://github.com/agnitanmay/library-management-system/blob/master//models/activity.js"
    click Model_Book "https://github.com/agnitanmay/library-management-system/blob/master//models/book.js"
    click Model_Comment "https://github.com/agnitanmay/library-management-system/blob/master//models/comment.js"
    click Model_Issue "https://github.com/agnitanmay/library-management-system/blob/master//models/issue.js"
    click Model_User "https://github.com/agnitanmay/library-management-system/blob/master//models/user.js"
    click EnvConfig "https://github.com/agnitanmay/library-management-system/blob/master//.env"

    %% Styles
    classDef client fill:#a2d9ce,stroke:#1e8449,stroke-width:2px;
    classDef server fill:#f9e79f,stroke:#b7950b,stroke-width:2px;
    classDef db fill:#f5b7b1,stroke:#cb4335,stroke-width:2px;
    classDef module fill:#d7bde2,stroke:#8e44ad,stroke-width:2px;
    classDef views fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
```
