# ericgalbarn/univeristy-library-webapp architecture

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

- Interactive diagram: https://gitdiagram.com/ericgalbarn/univeristy-library-webapp
- Repository: https://github.com/ericgalbarn/univeristy-library-webapp

## Overview

##### Main Components
- Admin UI (Frontend Pages) – These are the Next.js admin pages located in the folder structure under “app/admin”. They include:
- Dashboard components (e.g. activities, dashboard-stats)
- Account requests (e.g. account-requests pages)
- Book addition and book management (e.g. book-addition-requests, books with pages for new/edit and details)
- Borrow-request management (e.g. book-requests, borrow-requests)
- User management (e.g. users pages for listing/editing)
- Admin API Endpoints – These are found under “app/api/admin”. They serve as the backend “controller” layer for all admin actions:
- Endpoints for account requests, books (including export and borrowers), borrow requests (with routes for return and export), dashboard stats, and user-related export endpoints.
- Admin Business Logic & Actions – The business rules for handling admin workflows reside in:
- “lib/admin” (such as actions for book and user management)
- “components/admin” that provide specialized UI elements (e.g., Sidebar, Header, Book and User lists with modals).
- Database and Infrastructure – The shared database resources and migration scripts in the “db” and “migrations” directories show how the admin actions persist, update, or query data.
- Auxiliary Services – Optionally, include other supporting elements used in admin (for instance, email notification templates or exports) if they tie into admin functions.

##### Relationships & Interactions
- The Admin UI sends requests (using fetch calls, API actions, or Next.js routing) to respective Admin API endpoints.
- Admin API endpoints, after validating requests (possibly using middleware/authentication), trigger the business logic provided in “lib/admin” to process actions.
- The Business Logic interacts with the Database (via “db” and migration scripts) to read or modify persistent state (like account requests, book records, and user details).

##### Architectural Patterns & Design Principles
- MVC/Component Separation: The Next.js pages under “app/admin” (View) are cleanly separated from the API “controller” layer (the business logic) and the database (Model). Show these three layers distinctly.
- Modularization: Highlight that the admin case is split into various modules (account-requests, book-addition-requests, books, users, activities, and borrow-requests), which are separately maintained in the file tree. Each module has its dedicated set of pages, API endpoints, and even specialized components.

##### Putting It All Together
- Link the API endpoints to a “Business Logic / Admin Actions” module.
- Finally, connect the Business Logic to a “Database” component representing the persistent data store.
- To add any supporting flows (like data exports) on side branches and include labels for clarity.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Admin UI (Next.js Pages)"
        A1["Dashboard - Activities"]:::ui
        A2["Account Requests UI"]:::ui
        A3["Book Addition Requests UI"]:::ui
        A4["Books Management UI"]:::ui
        A5["Borrow-Request Management UI"]:::ui
        A6["User Management UI"]:::ui
    end

    subgraph "Admin API Endpoints"
        B1["Dashboard Stats API"]:::api
        B2["Account Requests API"]:::api
        B3["Account Requests Export API"]:::api
        B4["Books API"]:::api
        B5["Books Export API"]:::api
        B6["Book Detail API"]:::api
        B7["Borrowers API"]:::api
        B8["Borrow Requests API"]:::api
        B9["Borrow Requests Export API"]:::api
        B10["Return API"]:::api
        B11["Users Export API"]:::api
    end

    subgraph "Admin Business Logic/Actions"
        C1["Admin Logic (lib/admin)"]:::logic
        C2["Book Action Logic"]:::logic
        C3["User Action Logic"]:::logic
        C4["Admin Components (UI)"]:::logic
        C5["Header Component"]:::logic
        C6["Sidebar Component"]:::logic
    end

    subgraph "Database Layer"
        D1["Database (db)"]:::db
        D2["Migration Scripts"]:::db
    end

    %% UI to API calls
    A1 -->|"fetch"| B1
    A2 -->|"fetch"| B2
    A2 -->|"export"| B3
    A3 -->|"submit"| B4
    A4 -->|"update"| B4
    A4 -->|"export"| B5
    A4 -->|"detail"| B6
    A4 -->|"borrowers"| B7
    A5 -->|"request"| B8
    A5 -->|"export"| B9
    A5 -->|"return"| B10
    A6 -->|"export"| B11

    %% API to Business Logic
    B1 --> C1
    B2 --> C1
    B3 --> C1
    B4 --> C1
    B5 --> C1
    B6 --> C1
    B7 --> C1
    B8 --> C1
    B9 --> C1
    B10 --> C1
    B11 --> C1

    %% Business Logic internal delegations
    C1 --> C2
    C1 --> C3
    C1 --> C4
    C4 --> C5
    C4 --> C6

    %% Business Logic to Database operations
    C1 -->|"query/update"| D1
    D1 -->|"schema"| D2

    %% API responses back to UI
    B1 -->|"response"| A1
    B2 -->|"response"| A2
    B3 -->|"file"| A2
    B4 -->|"response"| A3
    B5 -->|"file"| A4
    B6 -->|"response"| A4
    B7 -->|"response"| A4
    B8 -->|"response"| A5
    B9 -->|"file"| A5
    B10 -->|"update"| A5
    B11 -->|"file"| A6

    %% Click Events for Admin UI
    click A1 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/admin/activities/page.tsx"
    click A2 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/admin/account-requests/page.tsx"
    click A3 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/admin/book-addition-requests/page.tsx"
    click A4 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/admin/books/page.tsx"
    click A5 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/admin/book-requests/page.tsx"
    click A6 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/admin/users/page.tsx"

    %% Click Events for Admin API Endpoints
    click B1 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/api/admin/dashboard-stats/route.ts"
    click B2 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/api/admin/account-requests/route.ts"
    click B3 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/api/admin/account-requests/export/route.ts"
    click B4 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/api/admin/books/route.ts"
    click B5 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/api/admin/books/export/route.ts"
    click B6 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/api/admin/books/[id]/route.ts"
    click B7 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/api/admin/books/[id]/borrowers/route.ts"
    click B8 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/api/admin/borrow-requests/route.ts"
    click B9 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/api/admin/borrow-requests/export/route.ts"
    click B10 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/api/admin/borrow-requests/[id]/return/route.ts"
    click B11 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/app/api/admin/users/export/route.ts"

    %% Click Events for Business Logic & Actions
    click C1 "https://github.com/ericgalbarn/univeristy-library-webapp/tree/main/lib/admin"
    click C2 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/lib/admin/actions/book.ts"
    click C3 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/lib/admin/actions/user/index.ts"
    click C4 "https://github.com/ericgalbarn/univeristy-library-webapp/tree/main/components/admin"
    click C5 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/components/admin/Header.tsx"
    click C6 "https://github.com/ericgalbarn/univeristy-library-webapp/blob/main/components/admin/Sidebar.tsx"

    %% Click Events for Database and Migrations
    click D1 "https://github.com/ericgalbarn/univeristy-library-webapp/tree/main/db"
    click D2 "https://github.com/ericgalbarn/univeristy-library-webapp/tree/main/migrations"

    %% Styles
    classDef ui fill:#ffefba,stroke:#bd7,stroke-width:2px;
    classDef api fill:#bae1ff,stroke:#369,stroke-width:2px;
    classDef logic fill:#d4f4be,stroke:#484,stroke-width:2px;
    classDef db fill:#ffe4e1,stroke:#a55,stroke-width:2px;
```
