# chandraprakash-tripathi/bookwise architecture

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

- Interactive diagram: https://gitdiagram.com/chandraprakash-tripathi/bookwise
- Repository: https://github.com/chandraprakash-tripathi/bookwise

## Overview

##### Project Type and Purpose
- This is a full-stack Next.js App Router application for managing books, borrowing, user profiles, an admin panel, and library workflows.
- It bundles:
– A React/Next.js front end (app/, components/)
– Serverless API routes (app/api/)
– Database layer (db/, migrations/)
– Business logic libraries (lib/actions, lib/admin, lib/library)
– Authentication via NextAuth (app/api/auth)
– External services (ImageKit, workflows)

##### File Structure
- app/
– (root) pages: home, book listings, profile
– (auth) sign-in, sign-up flows
– admin/ panel pages for book CRUD
– library/ pages for borrowing, members, receipts
– api/ serverless endpoints: auth, imagekit, workflows
- components/ UI building blocks separated by domain (admin, library, ui)
- db/ Drizzle ORM schema, Redis for caching/rate-limiting, seed scripts
- lib/ domain services calling db modules, validations, rate limiter, workflows
- migrations/ SQL files plus Drizzle meta snapshots
- next.config.ts, tsconfig.json, postcss.config for build and deployment

a. Main Components
– Browser/Client
– Next.js App Router (app/)
- Client Components (React)
- Server Components (data-fetching React components)
– API Layer (app/api/*) as serverless functions
– Auth Service (NextAuth)
– Business Logic Layer (lib/actions, lib/admin, lib/library)
– Data Layer
- Relational DB (PostgreSQL or MySQL via Drizzle ORM)
- Redis (Rate limite r, session caching)
– External Services
- ImageKit (file uploads)
- Onboarding Workflows (app/api/workflows)
– Deployment/Hosting (Vercel, Node runtime)

b. Relationships & Data Flows
1. User → React UI pages in Next.js
2. UI invokes getServerSideProps or client hooks → Server Components → fetch data via API or direct server calls to lib/actions
3. API routes receive HTTP requests → NextAuth handles authentication → business logic functions
4. Business logic layer uses Drizzle ORM to query/write data in RDBMS; uses Redis for rate-limit checks and caching
5. Image uploads → ImageKit endpoint → returns URL → stored in DB
6. Workflows endpoint orchestrates onboarding steps via lib/workflow

c. Architectural Patterns & Principles
– Layered Architecture: UI → API/Server Components → Business Logic → Data Access
– Separation of Concerns: components vs. pages vs. API routes vs. lib vs. db
– Serverless Functions for scalability (on-demand API)
– Domain-driven modules: admin vs. library actions
– Infrastructure as Code: migrations for reproducible schema

d. Key Technologies & Frameworks
– Next.js 13 App Router (React Server & Client Components)
– TypeScript throughout
– NextAuth for authentication
– Drizzle ORM + migrations for relational DB
– Redis for caching and rate-limiting
– ImageKit for media storage
– Node.js serverless (Vercel)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Zone
    subgraph "Frontend" 
        direction TB
        Browser["User Browser"]:::external
        AppRouter["Next.js App Router<br/>(app/)"]:::frontend
        Browser -->|navigates| AppRouter

        subgraph "Root UI Pages" 
            direction TB
            Home["Home Page<br/>(app/(root)/page.tsx)"]:::frontend
            BookDetails["Book Details Page<br/>(app/(root)/book/[id]/page.tsx)"]:::frontend
            Profile["Profile Page<br/>(app/(root)/my-profile/page.tsx)"]:::frontend
            LayoutRoot["Root Layout<br/>(app/(root)/layout.tsx)"]:::frontend
        end

        subgraph "Auth UI Pages"
            direction TB
            SignIn["Sign-In Page<br/>(app/(auth)/sign-in/page.tsx)"]:::frontend
            SignUp["Sign-Up Page<br/>(app/(auth)/sign-up/page.tsx)"]:::frontend
            LayoutAuth["Auth Layout<br/>(app/(auth)/layout.tsx)"]:::frontend
        end

        subgraph "Admin Panel Pages"
            direction TB
            AdminHome["Admin Home<br/>(app/admin/page.tsx)"]:::frontend
            LayoutAdmin["Admin Layout<br/>(app/admin/layout.tsx)"]:::frontend
            AdminBooks["Admin Book List<br/>(app/admin/books/page.tsx)"]:::frontend
            NewBook["New Book Page<br/>(app/admin/books/new/page.tsx)"]:::frontend
        end

        subgraph "Library Section Pages"
            direction TB
            LibraryHome["Library Home<br/>(app/library/page.tsx)"]:::frontend
            LayoutLib["Library Layout<br/>(app/library/layout.tsx)"]:::frontend
            LibBooks["Library Book List<br/>(app/library/books/page.tsx)"]:::frontend
            Borrow["Borrow Page<br/>(app/library/borrow/page.tsx)"]:::frontend
            Members["Members Page<br/>(app/library/members/page.tsx)"]:::frontend
        end

        TooFast["Rate-Limit Warning<br/>(app/too-fast/page.tsx)"]:::frontend

        AppRouter --> Home
        AppRouter --> BookDetails
        AppRouter --> Profile
        AppRouter --> SignIn
        AppRouter --> SignUp
        AppRouter --> AdminHome
        AppRouter --> LibraryHome
        AppRouter --> TooFast
    end

    %% Backend Zone
    subgraph "Backend" 
        direction TB
        subgraph "Serverless API Layer" 
            direction TB
            AuthAPI["NextAuth API<br/>(app/api/auth/[...nextauth]/route.ts)"]:::api
            ImageKitAPI["ImageKit API<br/>(app/api/imagekit/route.ts)"]:::api
            WorkflowsAPI["Onboarding Workflow API<br/>(app/api/workflows/onboarding/route.ts)"]:::api
        end

        subgraph "Business Logic Layer" 
            direction TB
            AuthActions["Auth Actions<br/>(lib/actions/auth.ts)"]:::logic
            BookActions["Book Actions<br/>(lib/actions/book.ts)"]:::logic
            ProfileActions["Profile Actions<br/>(lib/actions/profile.ts)"]:::logic
            AdminBookActions["Admin Book Actions<br/>(lib/admin/actions/book.ts)"]:::logic
            LibraryBookActions["Library Book Actions<br/>(lib/library/actions/book.ts)"]:::logic
            WorkflowLib["Workflow Orchestration<br/>(lib/workflow.ts)"]:::logic
            RateLimitLib["Rate Limiting<br/>(lib/ratelimit.ts)"]:::logic
        end

        subgraph "Data Layer" 
            direction TB
            DB["Relational Database<br/>(db/schema.ts, db/drizzle.ts)"]:::data
            Redis["Redis Cache/Rate-Limit<br/>(db/redis.ts)"]:::data
            Seed["Seed Script<br/>(db/seed.ts)"]:::data
            Migrations["Migrations<br/>(migrations/)"]:::data
        end

        subgraph "External Services"
            ImageKit["ImageKit Service"]:::external
        end

        %% Flows
        Home -->|requests data|getData[/"get data"/] 
        getData --> AuthAPI
        BookDetails -->|fetch book|getData
        Profile -->|fetch profile|getData
        SignIn -->|submit credentials| AuthAPI
        AuthAPI -->|"verify"| AuthActions
        AuthActions -->|read/write| DB
        AuthActions -->|cache sessions| Redis

        AdminHome -->|manage books| AuthAPI
        AdminHome -->|"book CRUD"| AdminBookActions
        AdminBookActions -->|db ops| DB

        LibraryHome -->|view books| LibraryBookActions
        LibraryBookActions -->|db ops| DB
        Borrow -->|borrow workflow| WorkflowsAPI
        WorkflowsAPI -->|orchestrate| WorkflowLib
        WorkflowLib -->|db ops| DB

        RateLimitLib -->|check| Redis
        TooFast -->|warn| Redis

        ImageKitAPI -->|upload image| ImageKit
        ImageKitAPI -->|return URL| DB

        AuthAPI -->|call| AuthActions
        ImageKitAPI -->|call| BookActions
        WorkflowsAPI -->|call| WorkflowLib
    end

    %% Click events - Frontend
    click AppRouter "https://github.com/chandraprakash-tripathi/bookwise/tree/main/app/"
    click Home "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/(root)/page.tsx"
    click BookDetails "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/(root)/book/[id]/page.tsx"
    click Profile "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/(root)/my-profile/page.tsx"
    click LayoutRoot "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/(root)/layout.tsx"
    click SignIn "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/(auth)/sign-in/page.tsx"
    click SignUp "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/(auth)/sign-up/page.tsx"
    click LayoutAuth "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/(auth)/layout.tsx"
    click AdminHome "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/admin/page.tsx"
    click LayoutAdmin "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/admin/layout.tsx"
    click AdminBooks "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/admin/books/page.tsx"
    click NewBook "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/admin/books/new/page.tsx"
    click LibraryHome "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/library/page.tsx"
    click LayoutLib "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/library/layout.tsx"
    click LibBooks "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/library/books/page.tsx"
    click Borrow "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/library/borrow/page.tsx"
    click Members "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/library/members/page.tsx"
    click TooFast "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/too-fast/page.tsx"

    %% Click events - API
    click AuthAPI "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/api/auth/[...nextauth]/route.ts"
    click ImageKitAPI "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/api/imagekit/route.ts"
    click WorkflowsAPI "https://github.com/chandraprakash-tripathi/bookwise/blob/main/app/api/workflows/onboarding/route.ts"

    %% Click events - Business Logic
    click AuthActions "https://github.com/chandraprakash-tripathi/bookwise/blob/main/lib/actions/auth.ts"
    click BookActions "https://github.com/chandraprakash-tripathi/bookwise/blob/main/lib/actions/book.ts"
    click ProfileActions "https://github.com/chandraprakash-tripathi/bookwise/blob/main/lib/actions/profile.ts"
    click AdminBookActions "https://github.com/chandraprakash-tripathi/bookwise/blob/main/lib/admin/actions/book.ts"
    click LibraryBookActions "https://github.com/chandraprakash-tripathi/bookwise/blob/main/lib/library/actions/book.ts"
    click WorkflowLib "https://github.com/chandraprakash-tripathi/bookwise/blob/main/lib/workflow.ts"
    click RateLimitLib "https://github.com/chandraprakash-tripathi/bookwise/blob/main/lib/ratelimit.ts"

    %% Click events - Data Layer
    click DB "https://github.com/chandraprakash-tripathi/bookwise/blob/main/db/schema.ts"
    click Redis "https://github.com/chandraprakash-tripathi/bookwise/blob/main/db/redis.ts"
    click Seed "https://github.com/chandraprakash-tripathi/bookwise/blob/main/db/seed.ts"
    click Migrations "https://github.com/chandraprakash-tripathi/bookwise/tree/main/migrations/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef api fill:#DFFFE0,stroke:#057A04,color:#057A04;
    classDef logic fill:#FFF4D0,stroke:#D48F00,color:#D48F00;
    classDef data fill:#F4D0FF,stroke:#7A0394,color:#7A0394;
    classDef external fill:#E0E0E0,stroke:#666666,color:#333333;
```
