How pat-jj/textbookkg works
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).