# anhvanhoa/ebook architecture

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

- Interactive diagram: https://gitdiagram.com/anhvanhoa/ebook
- Repository: https://github.com/anhvanhoa/ebook

## Overview

##### Main Components
- Frontend UI Layers:
– Public UI: Contains static resources (fonts, images, PDF/EPUB files) available under the public folder.
– Layouts & Shared Components: In the src/app directory (and inside src/components), you see base layouts (e.g., global, header, footer) that wrap pages and enforce consistency.
– Page Groups: Multiple route groups such as:
- (auth) – Handles login and sign‑up for user authentication.
- (client) – Displays category and book details, reviews, and general client browsing.
- (read) – Provides specialized reading interfaces including different subcomponents (EpubViewer, PDF view, HTML view, etc.).
- Core Utility Libraries:
– lib folder: Contains helper functions (for EPUB processing, font management, and other utilities).
– hooks folder: Custom hooks like useTriggerPdf likely assist with dynamic content loading or state management related to PDF processing.
- Context & Providers:
– provider/pdf: Provides PDF-related context using React Context API for state sharing and functionality among components that handle PDF interactions.
- Configurations & Tooling:
– Various configuration files (e.g., eslint.config.mjs, next.config.ts, postcss.config.mjs, tsconfig.json) that define code linting, build parameters, and styling.

##### Relationships and Interactions
- Navigation Flow:
– The (client) components allow users to browse book categories and individual books. Upon selection, navigation occurs to the (read) section which loads a detailed reading interface.
– The (auth) section is accessed for signing up or logging in; successful auth likely unlocks further functionalities or personalizations on the client and read routes.
- Component Reusability:
– Shared elements such as headers, footers, and theme providers (e.g., ThemeProvider, ModeToggle) are used across the application, linking various pages.
- Data Flow:
– Utility functions (from lib) support content processing in reader components.
- Routing & Layout:

##### Architectural Patterns & Design Principles
- Next‑JS File Based Routing & Nested Layouts:
– Emphasize the modular structure provided by Next.js where route-based directories govern the layout and behavior of each section.
- Separation of Concerns:
– Authentication, content browsing, and reading functionalities are separated into different route folders.
– UI components are kept in their own directories (e.g., src/components and src/app/(client)/_components).
- Component Reusability:
– The presence of shared components (like header, button, card, and various display components) shows a reusable UI library design.

##### Relevant Technologies & Frameworks
- Next.js for React‑based server‑side rendering and routing.
- React Context API (as seen in the pdf provider) to manage state across the app.
- ESLint for code quality (configured via eslint.config.mjs).
- Tailwind or PostCSS (as implied by postcss.config.mjs) for styling.
- Utility libraries and hooks for managing UI state and content processing.

##### Instructing the Principal Software Engineer – What
– Label high-level route groups: “Authentication”, “Client Content”, “Reading Interface”.
– Label shared components (e.g., Header, Footer, ThemeProvider) and utility modules (e.g., lib, hooks).
– Show navigation flow (e.g., from the Client Content to the Reading Interface).
– For example:
○ Rectangles for layout containers.
○ Circles for reusable UI components.
- Be as Detailed as Possible:
– Start by drawing a big picture: pages grouped by function (Auth, Client, Read).
– Drill down to show internal components in each group (e.g., within the “Reading Interface”—list each subcomponent from the _components folder).
– Include external dependencies (Next.js, React Context API, build tools) to provide context on how the application is structured and deployed.

## Diagram (Mermaid)

```mermaid
graph TD
    A["Next.js Application"]:::app

    subgraph "Public Assets"
        B["Public UI Resources"]:::public
    end

    subgraph "Global Layout & Shared Styles"
        CL1["App Layout"]:::layout
        CL2["Global Styles"]:::layout
    end

    subgraph "Authentication Routes & Layout"
        D1["Auth Layout"]:::auth
        D2["Login Page"]:::auth
        D3["Sign‑Up Page"]:::auth
    end

    subgraph "Client Content Browsing"
        E1["Categories Component"]:::client
    end

    subgraph "Reading Interface & Reader Engine"
        F1["EpubViewer"]:::read
        F2["PDF Viewer"]:::read
        F3["HTML Viewer"]:::read
        F4["Image Viewer"]:::read
        F5["Controll"]:::read
        F6["Zoom"]:::read
    end

    subgraph "Core Utility Libraries"
        G1["epub.ts"]:::utility
        G2["font.ts"]:::utility
        G3["utils.ts"]:::utility
    end

    H["Custom Hook: useTriggerPdf"]:::hook

    I["PDF Context Provider"]:::provider

    subgraph "Shared UI Components"
        J1["ModeToggle"]:::shared
        J2["ThemeProvider"]:::shared
        J3["UI Library Components"]:::shared
    end

    subgraph "Configuration & Tooling"
        K1["ESLint Config"]:::config
        K2["Next Config"]:::config
        K3["PostCSS Config"]:::config
        K4["TS Config"]:::config
    end

    %% High-Level Connections
    A --> B
    A --> CL1
    A --> CL2
    A --> D1
    A --> D2
    A --> D3
    A --> E1
    A --> F1
    A --> F2
    A --> F3
    A --> F4
    A --> F5
    A --> F6
    A --> G1
    A --> G2
    A --> G3
    A --> H
    A --> I
    A --> J1
    A --> J2
    A --> J3
    A --> K1
    A --> K2
    A --> K3
    A --> K4

    %% Inter-Component Data Flow
    E1 -->|"SelectBook"| F1
    E1 -->|"SelectBook"| F2
    I -->|"PDFState"| F2
    G1 -->|"Utility"| F1
    G2 -->|"Utility"| F2
    H -->|"TriggerPDF"| F2
    J1 & J2 & J3 -->|"ProvidesTheme"| CL1

    %% Click Events
    click B "https://github.com/anhvanhoa/ebook/tree/main/public"
    click CL1 "https://github.com/anhvanhoa/ebook/blob/main/src/app/layout.tsx"
    click CL2 "https://github.com/anhvanhoa/ebook/blob/main/src/app/globals.css"
    click D1 "https://github.com/anhvanhoa/ebook/blob/main/src/app/(auth)/layout.tsx"
    click D2 "https://github.com/anhvanhoa/ebook/blob/main/src/app/(auth)/login/page.tsx"
    click D3 "https://github.com/anhvanhoa/ebook/blob/main/src/app/(auth)/sign‑up/page.tsx"
    click E1 "https://github.com/anhvanhoa/ebook/blob/main/src/app/(client)/_components/Categories.tsx"
    click F1 "https://github.com/anhvanhoa/ebook/blob/main/src/app/(read)/EpubViewer.tsx"
    click F2 "https://github.com/anhvanhoa/ebook/blob/main/src/app/(read)/PDF.tsx"
    click F3 "https://github.com/anhvanhoa/ebook/blob/main/src/app/(read)/HtmlViewer.tsx"
    click F4 "https://github.com/anhvanhoa/ebook/blob/main/src/app/(read)/ImgViewer.tsx"
    click F5 "https://github.com/anhvanhoa/ebook/blob/main/src/app/(read)/Controll.tsx"
    click F6 "https://github.com/anhvanhoa/ebook/blob/main/src/app/(read)/Zoom.tsx"
    click G1 "https://github.com/anhvanhoa/ebook/blob/main/src/lib/epub.ts"
    click G2 "https://github.com/anhvanhoa/ebook/blob/main/src/lib/font.ts"
    click G3 "https://github.com/anhvanhoa/ebook/blob/main/src/lib/utils.ts"
    click H "https://github.com/anhvanhoa/ebook/blob/main/src/hooks/useTriggerPdf.tsx"
    click I "https://github.com/anhvanhoa/ebook/blob/main/src/provider/pdf/context.tsx"
    click J1 "https://github.com/anhvanhoa/ebook/blob/main/src/components/ModeToggle.tsx"
    click J2 "https://github.com/anhvanhoa/ebook/blob/main/src/components/ThemeProvider.tsx"
    click J3 "https://github.com/anhvanhoa/ebook/tree/main/src/components/ui"
    click K1 "https://github.com/anhvanhoa/ebook/blob/main/eslint.config.mjs"
    click K2 "https://github.com/anhvanhoa/ebook/blob/main/next.config.ts"
    click K3 "https://github.com/anhvanhoa/ebook/blob/main/postcss.config.mjs"
    click K4 "https://github.com/anhvanhoa/ebook/blob/main/tsconfig.json"

    %% Class Definitions
    classDef app fill:#FFEBBD,stroke:#333,stroke-width:2px;
    classDef public fill:#CCE5FF,stroke:#333,stroke-width:2px;
    classDef layout fill:#FFFFCC,stroke:#333,stroke-width:2px;
    classDef auth fill:#D4EDDA,stroke:#333,stroke-width:2px;
    classDef client fill:#D1ECF1,stroke:#333,stroke-width:2px;
    classDef read fill:#F8D7DA,stroke:#333,stroke-width:2px;
    classDef utility fill:#E2E3E5,stroke:#333,stroke-width:2px;
    classDef hook fill:#F5C6CB,stroke:#333,stroke-width:2px;
    classDef provider fill:#D6D8D9,stroke:#333,stroke-width:2px;
    classDef shared fill:#C3E6CB,stroke:#333,stroke-width:2px;
    classDef config fill:#FFEeba,stroke:#333,stroke-width:2px;
```
