# pat-jj/textbookkg architecture

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

- Interactive diagram: https://gitdiagram.com/pat-jj/textbookkg
- Repository: https://github.com/pat-jj/textbookkg

## Overview

##### Project Type and Purpose
- TextbookKG is a client-side, web-based application developed primarily in JavaScript/React. Its purpose is to transform any PDF (or selected pages from a PDF) into an interactive knowledge graph.
- It supports functionalities such as PDF upload, page addition/deletion, user login/authentication (using Firebase), and dynamic graph operations (including node/edge manipulation and clustering).
- The project is “full-stack” in the sense that while most of the processing happens in the browser via React, it leverages external services (like Firebase for authentication and possibly persistence) and includes a rich set of static assets (via the public folder) for demonstration and textbook data.

##### Analyzing the File Structure
- The top-level structure has key directories:
- The public folder holds the static assets including demo gifs, PDF textbooks, archived textbook chapters, HTML files, and JSON data (e.g., knowledge graphs, page info).
- The src directory contains the core front-end code (React components such as App.js, wikiSearchBox.js, paperSearch.js) and configuration files (firebaseConfig.js) necessary for integrating with authentication and possibly other external services.
- There are configuration files like package.json and package-lock.json that indicate usage of Node and typical web build scripts.
- The structure suggests an architecture driven by a modern JavaScript framework (React) with additional modules for handling PDF processing and knowledge graph visualization.

##### Components and Their Responsibilities
- User Interface (UI) Layer:
- Built with React. Includes components for uploading PDFs, searching (wikiSearchBox and paperSearch), and displaying the knowledge graph.
- Contains the main user interaction logic (starting at App.js, with separate components for graph display and user feedback).
- PDF Management Module:
- Handles PDF uploads, page addition, and deletion.
- Interacts with the UI and likely processes PDFs into a format suitable for graph generation.
- Knowledge Graph Generation Engine:
- Supports operations such as node/edge clustering, editing, and visualization.
- Modules for node edge operations and clustering are hinted at in the demo gifs.
- Authentication & Persistence Component:
- Defined by firebaseConfig.js and login related demo features.
- Manages user authentication (possibly via Google) and saving/loading projects.
- Static Data and Assets:
- The many archived textbook chapters and associated JSON files under public provide context and sample content for transforming textbook data into a graph.
- External integrations:
- Firebase for login and possibly saving projects.
- External libraries for PDF parsing and graph rendering (even if not explicitly mentioned, they are likely part of the dependencies defined in package.json).

##### Relationships and Interactions
- The user interacts with the UI to perform tasks like uploading a PDF.
- The PDF Management Module processes input files and feeds them into the Knowledge Graph Engine.
- The Knowledge Graph Engine parses the data into nodes, edges, and clusters, handing the results back to the UI for visualization.
- The Authentication Component ensures that certain features are available only to authorized users.
- Data flows from the PDF processing step to the graph generator, which then outputs an interactive graphic. Additionally, saving and loading projects bridge the UI and a persistence layer (via Firebase).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    U("User"):::user

    %% UI Components Subgraph
    subgraph "UI Components"
        RA("React App"):::frontend
        WSB("Wiki Search Box"):::frontend
        PS("Paper Search"):::frontend
    end

    %% Business Logic Modules
    PM("PDF Management Module"):::module
    KG("Knowledge Graph Generation Engine"):::module
    AP("Authentication & Persistence Module"):::auth

    %% Static Assets
    SA("Static Assets"):::assets

    %% Interactions
    U -->|"interacts"| RA
    RA -->|"triggers_PDFUpload"| PM
    RA -->|"sends_AuthRequest"| AP
    RA -->|"loads_Data"| SA
    PM -->|"processes_PDF"| KG
    KG -->|"produces_GraphData"| RA
    RA -->|"initiates_SaveLoad"| AP

    %% Click Events
    click RA "https://github.com/pat-jj/textbookkg/blob/main/src/App.js"
    click WSB "https://github.com/pat-jj/textbookkg/blob/main/src/wikiSearchBox.js"
    click PS "https://github.com/pat-jj/textbookkg/blob/main/src/paperSearch.js"
    click AP "https://github.com/pat-jj/textbookkg/blob/main/src/firebaseConfig.js"
    click SA "https://github.com/pat-jj/textbookkg/tree/main/public/"
    click PM "https://github.com/pat-jj/textbookkg/tree/main/public/"
    click KG "https://github.com/pat-jj/textbookkg/tree/main/public/knowledge_graphs"

    %% Styles
    classDef frontend fill:#a7d8f7,stroke:#333,stroke-width:2px;
    classDef module fill:#f7d6a7,stroke:#333,stroke-width:2px;
    classDef auth fill:#f7a7d6,stroke:#333,stroke-width:2px;
    classDef assets fill:#f7efa7,stroke:#333,stroke-width:2px;
    classDef user fill:#d6a7f7,stroke:#333,stroke-width:2px;
```
