# keval144/litlib architecture

> Architecture diagram of the GitHub repository keval144/litlib, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/keval144/litlib
- Repository: https://github.com/keval144/litlib

## Overview

##### Project type and purpose
- LitLib is a full-stack web application—a modern library management system—built on Next.js 14 App Router.
- It provides a responsive dashboard for managing book inventory, members, analytics, role-based access, notifications, backups, and more.

##### File structure
- Top-level folders:
- app/ – Next.js “App Router” entry points (page.tsx, layout.tsx, error.tsx, providers.tsx).
- components/ – UI primitives and shared elements (Navbar, Footer, ThemeSwitch, etc.).
- config/ – site-wide constants (fonts, theming).
- prisma/ – schema.prisma defining the MySQL data model.
- public/ – static assets (logos, manifest.json).
- styles/ – global CSS (Tailwind).
- types/ – shared TypeScript types.
- Config/build files: next.config.js, tsconfig.json, tailwind.config.js, eslint.config.mjs.
- package.json / lock file list dependencies: Next.js, Prisma, NextAuth, HeroUI, Shadcn UI, etc.

##### Key insights from README
- Tech stack: Next.js 14 App Router, TypeScript, Tailwind CSS + Variants, HeroUI v2, Shadcn UI, Framer Motion, Prisma + MySQL, NextAuth.js.
- Core features: inventory CRUD, role-based auth, analytics dashboard, theme switch, image uploads, email notifications, rate limiting, backups.

##### Main components & their interactions
a. Client (Browser)
- React / Next.js pages & components (SSR / SSG / CSR).
- Tailwind / HeroUI / Shadcn UI for styling and layout.
- Framer Motion for animations.
b. Next.js Server (Node.js)
- App Router handlers (app/api/…) exposing REST/JSON endpoints.
- NextAuth.js for authentication & session management.
- Business logic for books, members, borrowing, fines, backups, rate limiting.
c. Database Layer
- Prisma ORM translating queries to MySQL.
- Entities: User, Role, Book, Loan, Backup, Notification, etc.
d. External Services
- SMTP or transactional email provider (SendGrid/Mailer) for notifications.
- Optional file storage or DB-backups (could be local or S3).

##### Architectural patterns & principles
- Next.js App Router pattern (Layouts → Pages → Server/Client Components).
- Provider pattern (app/providers.tsx) to inject theme, auth context.
- Atomic UI components under components/primitives.ts.
- ORM layer (Prisma) separating data access from business logic.
- Modular config via config/*.
- Role-based access controls and middleware at route layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Layer
    subgraph "Browser (Client)" 
        direction TB
        Browser["Browser"]:::frontend
        subgraph "UI Components"
            direction TB
            Primitives["UI Primitives"]:::frontend
            Navbar["Navbar"]:::frontend
            Footer["Footer"]:::frontend
            ThemeSwitch["ThemeSwitch"]:::frontend
            ScrollToTop["ScrollToTop"]:::frontend
        end
    end

    %% Next.js Server Layer
    subgraph "Next.js Server (Node.js, TypeScript)"
        direction TB
        subgraph "App Router (Layouts & Pages)"
            direction TB
            LayoutsPages["Layouts & Pages"]:::backend
            ErrorPage["Error Page"]:::backend
            PageHome["Home Page"]:::backend
        end
        Providers["Providers (Auth & Theme)"]:::backend
        Auth["NextAuth.js (Auth & Session)"]:::backend
        subgraph "Business Logic Services"
            direction TB
            InventoryService["Inventory Service"]:::backend
            AnalyticsService["Analytics Service"]:::backend
            NotificationService["Notification Service"]:::backend
            BackupService["Backup Service"]:::backend
        end
    end

    %% Data Layers
    Prisma["Prisma ORM"]:::orm
    MySQL["MySQL Database"]:::db

    %% External Services
    EmailService["Email Service"]:::external
    FileStorage["File/Backup Storage"]:::external

    %% Config
    Config["Site Configuration"]:::config

    %% Connections
    Browser -->|"HTTPS"| LayoutsPages
    Primitives -->|used by| LayoutsPages
    Navbar -->|used by| LayoutsPages
    Footer -->|used by| LayoutsPages
    ThemeSwitch -->|used by| LayoutsPages
    ScrollToTop -->|used by| LayoutsPages

    LayoutsPages -->|provides context| Providers
    Providers -->|manages| Auth
    Auth -->|secures| LayoutsPages

    LayoutsPages -->|calls API| InventoryService
    LayoutsPages -->|calls API| AnalyticsService
    LayoutsPages -->|calls API| NotificationService
    LayoutsPages -->|calls API| BackupService

    InventoryService -->|sync| Prisma
    AnalyticsService -->|sync| Prisma
    NotificationService -->|sync| Prisma
    BackupService -->|sync| Prisma

    Prisma -->|SQL queries| MySQL

    NotificationService -.->|SMTP/API| EmailService
    BackupService -.->|read/write| FileStorage

    Config -->|feeds| LayoutsPages
    Config -->|feeds| InventoryService

    %% Click Events
    click LayoutsPages "https://github.com/keval144/litlib/blob/main/app/layout.tsx"
    click ErrorPage "https://github.com/keval144/litlib/blob/main/app/error.tsx"
    click PageHome "https://github.com/keval144/litlib/blob/main/app/page.tsx"
    click Providers "https://github.com/keval144/litlib/blob/main/app/providers.tsx"
    click Primitives "https://github.com/keval144/litlib/blob/main/components/primitives.ts"
    click Navbar "https://github.com/keval144/litlib/blob/main/components/navbar.tsx"
    click Footer "https://github.com/keval144/litlib/blob/main/components/footer.tsx"
    click ThemeSwitch "https://github.com/keval144/litlib/blob/main/components/theme-switch.tsx"
    click ScrollToTop "https://github.com/keval144/litlib/blob/main/components/scrolltotop.tsx"
    click Config "https://github.com/keval144/litlib/blob/main/config/fonts.ts"
    click Config "https://github.com/keval144/litlib/blob/main/config/site.ts"
    click Prisma "https://github.com/keval144/litlib/blob/main/prisma/schema.prisma"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#E6FFEA,stroke:#28A745,color:#28A745;
    classDef db fill:#FFF5D7,stroke:#E67700,color:#E67700;
    classDef orm fill:#F0EFF5,stroke:#6F42C1,color:#6F42C1;
    classDef external fill:#FFEFF0,stroke:#D73A49,color:#D73A49;
    classDef config fill:#FFF0B3,stroke:#FFD33D,color:#8A6E00;
```
