# yousseffe/university-library-management-system architecture

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

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

## Overview

##### Project Type and Purpose
- This is a full-stack University Library Management System built with Next.js (app router), TypeScript, and a modern tech stack.
- It provides a public-facing site (book browsing, borrowing, user onboarding) and an admin panel (user/book management, workflows, analytics).

##### File Structure
- Top-level “app” folder (Next 13+ App Router):
- (root) → public pages: home, books listing, book detail, my-profile
- (auth) → sign-in/sign-up flows
- admin → admin dashboard, books CRUD, layouts
- api → Next.js API routes (auth, ImageKit, workflows)
- “components” and “components/admin”: shared and admin-specific UI components
- “lib” and “lib/admin”: business logic / action functions for public and admin
- “database”: Drizzle ORM config, Redis, schema, migrations, seed data
- “middleware.ts”: rate limiting, DDoS protection
- Config files for Next.js, Tailwind, ESLint, TypeScript

##### Key Insights from README
- Public features: book discovery (filter, search, pagination), profiles, receipts, reminders
- Admin features: user/book management, workflows, analytics dashboard
- External services: PostgreSQL (Neon), Upstash Redis, ImageKit (media), QStash (workflows), Resend (email)
- Uses NextAuth for authentication, Drizzle ORM for DB, Tailwind & ShadCN for UI

##### Main Components & Their Relationships
a. Frontend
- Browser clients (public & admin)
- Next.js React pages (server & client components)
- Shared UI library (components/ui)
b. Backend & API
- Next.js API routes under app/api
- Business logic in lib/actions and lib/admin/actions
- Authentication via NextAuth (app/api/auth)
- Rate-limit middleware (middleware.ts)
c. Data Stores
- PostgreSQL (Drizzle ORM)
- Upstash Redis (caching, rate limiting, workflow triggers)
d. External Services
- ImageKit (image/video optimization)
- Resend (email sending)
- QStash (workflow scheduling)

##### Architectural Patterns & Design Principles
- Layered architecture:
- Presentation (app pages, components)
- API/Business logic (lib/actions)
- Data access (Drizzle ORM, Redis)
- Micro-feature grouping in the App Router (route segment grouping for auth, admin, root)
- Single Next.js monolith handling frontend SSR/SSG + API routes
- Separation of concerns: public vs. admin code paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Public Site & Admin Panel)"
        direction TB
        Home["Home Page"]:::frontend
        BookListing["Book Listing"]:::frontend
        BookDetail["Book Detail"]:::frontend
        UserProfile["User Profile"]:::frontend
        SignIn["Sign-In Page"]:::frontend
        SignUp["Sign-Up Page"]:::frontend
        AdminLayout["Admin Dashboard Layout"]:::frontend
        AdminHome["Admin Home"]:::frontend
        AdminBooksList["Admin Books List"]:::frontend
        AdminBookNew["New Book Form"]:::frontend
    end

    %% Server & API Layer
    subgraph "Next.js Server & API Routes"
        direction TB
        NextAuthRoute["NextAuth API Route"]:::server
        ImageKitPublic["ImageKit Upload/Optimization Route"]:::server
        ImageKitAuth["Auth-Protected ImageKit Route"]:::server
        WorkflowOnboarding["Workflow Trigger Route"]:::server
        Middleware["Global Middleware (rate-limit, DDoS)"]:::server
    end

    %% Business Logic Layer
    subgraph "Business Logic (Server Actions)"
        direction TB
        PublicAuthActions["lib/actions/auth.ts"]:::biz
        PublicBookActions["lib/actions/book.ts"]:::biz
        AdminBookActions["lib/admin/actions/book.ts"]:::biz
        WorkflowUtil["lib/workflow.ts"]:::biz
        RateLimitLogic["lib/ratelimit.ts"]:::biz
    end

    %% Data & External Services Layer
    subgraph "Data Stores & External Services"
        direction TB
        Postgres[(PostgreSQL via Drizzle ORM)]:::data
        Redis[(Upstash Redis)]:::data
        ImageKitExt[/"ImageKit Service"/]:::data
        Resend[/"Resend Email Service"/]:::data
        QStash[/"QStash Workflow Scheduler"/]:::data
    end

    %% Connections: Frontend to Server/API
    Home -->|HTTP/API| NextAuthRoute
    BookListing -->|HTTP/API| WorkflowOnboarding
    BookListing -->|HTTP/API| PublicBookActions
    BookDetail -->|HTTP/API| PublicBookActions
    UserProfile -->|HTTP/API| PublicAuthActions
    SignIn -->|HTTP/API| NextAuthRoute
    SignUp -->|HTTP/API| NextAuthRoute
    AdminHome -->|HTTP/API| NextAuthRoute
    AdminBooksList -->|HTTP/API| AdminBookActions
    AdminBookNew -->|HTTP/API| AdminBookActions

    %% Server/API to Business Logic
    NextAuthRoute -->|calls| PublicAuthActions
    ImageKitPublic -->|calls| WorkflowUtil
    ImageKitAuth -->|calls| WorkflowUtil
    WorkflowOnboarding -->|schedules| WorkflowUtil
    WorkflowOnboarding -->|uses| RateLimitLogic
    Middleware -->|enforces| RateLimitLogic

    %% Business Logic to Data Stores
    PublicAuthActions -->|queries| Postgres
    PublicBookActions -->|queries| Postgres
    AdminBookActions -->|queries| Postgres
    RateLimitLogic -->|stores/tracks| Redis
    WorkflowUtil -->|triggers| Redis

    %% Server/API to External Services
    ImageKitPublic -->|uploads| ImageKitExt
    ImageKitAuth -->|uploads| ImageKitExt
    WorkflowUtil -->|emails via| Resend
    WorkflowUtil -->|schedules via| QStash

    %% Click Events for component mapping
    click Home "https://github.com/yousseffe/university-library-management-system/blob/main/app/(root)/page.tsx"
    click BookListing "https://github.com/yousseffe/university-library-management-system/tree/main/app/(root)/books"
    click BookDetail "https://github.com/yousseffe/university-library-management-system/blob/main/app/(root)/books/[id]/page.tsx"
    click UserProfile "https://github.com/yousseffe/university-library-management-system/blob/main/app/(root)/my-profile/page.tsx"
    click SignIn "https://github.com/yousseffe/university-library-management-system/blob/main/app/(auth)/sign-in/page.tsx"
    click SignUp "https://github.com/yousseffe/university-library-management-system/blob/main/app/(auth)/sign-up/page.tsx"
    click NextAuthRoute "https://github.com/yousseffe/university-library-management-system/blob/main/app/api/auth/[...nextauth]/route.ts"
    click AdminLayout "https://github.com/yousseffe/university-library-management-system/blob/main/app/admin/layout.tsx"
    click AdminHome "https://github.com/yousseffe/university-library-management-system/blob/main/app/admin/page.tsx"
    click AdminBooksList "https://github.com/yousseffe/university-library-management-system/blob/main/app/admin/books/page.tsx"
    click AdminBookNew "https://github.com/yousseffe/university-library-management-system/blob/main/app/admin/books/new/page.tsx"
    click PublicAuthActions "https://github.com/yousseffe/university-library-management-system/blob/main/lib/actions/auth.ts"
    click PublicBookActions "https://github.com/yousseffe/university-library-management-system/blob/main/lib/actions/book.ts"
    click AdminBookActions "https://github.com/yousseffe/university-library-management-system/blob/main/lib/admin/actions/book.ts"
    click WorkflowUtil "https://github.com/yousseffe/university-library-management-system/blob/main/lib/workflow.ts"
    click RateLimitLogic "https://github.com/yousseffe/university-library-management-system/blob/main/lib/ratelimit.ts"
    click Postgres "https://github.com/yousseffe/university-library-management-system/blob/main/database/drizzle.ts"
    click Redis "https://github.com/yousseffe/university-library-management-system/blob/main/database/redis.ts"
    click ImageKitPublic "https://github.com/yousseffe/university-library-management-system/blob/main/app/api/imagekit/route.ts"
    click ImageKitAuth "https://github.com/yousseffe/university-library-management-system/blob/main/app/api/auth/imagekit/route.ts"
    click WorkflowOnboarding "https://github.com/yousseffe/university-library-management-system/blob/main/app/api/workflows/onboarding/route.ts"

    %% Styles
    classDef frontend fill:#E0F2FE,stroke:#0284C7,stroke-width:1px
    classDef server fill:#DCFCE7,stroke:#15803D,stroke-width:1px
    classDef biz fill:#FEF9C3,stroke:#F59E0B,stroke-width:1px
    classDef data fill:#FED7AA,stroke:#C2410C,stroke-width:1px
```
