How mahadevaperuka/notebookreader works
Purpose and Entry Points
This is a Next.js App Router application for document-grounded chat: users upload documents, index them into searchable chunks, and converse through chat sessions. Browser entry points are the landing page at app/page.tsx and per-chat routes at app/chat/[chatId]/page.tsx; shared application shell and providers live in app/layout.tsx and app/providers.tsx.
UI and Session Navigation
The UI creates or opens chat-specific views under /chat/[chatId], isolating each conversation by chat ID. Client-side state/service integration is established through the app provider boundary. Relevant paths: app/chat/[chatId]/page.tsx, app/providers.tsx, app/globals.css.
HTTP API Boundary
Next.js route handlers expose the server-side workflow:
• app/api/upload/route.ts accepts source documents.
• app/api/index-chat/route.ts associates/indexes document content for a chat.
• app/api/search/route.ts retrieves relevant indexed content.
• app/api/chat/[...slug]/route.ts handles chat/agent requests.
These handlers are the boundary between browser interactions and persistence, parsing, retrieval, and model inference.
Document Ingestion and Indexing
Uploaded PDFs are parsed through lib/pdf.ts, then represented as documents and chunks in Convex. The indexing stage persists document metadata/content, partitions text into retrieval units, and builds chat-scoped index records. Core storage modules are convex/documents.ts, convex/chunks.ts, and convex/chatIndex.ts.
Retrieval-Augmented Agent Flow
Chat requests are orchestrated by lib/agent.ts. The expected control flow is: resolve the target chat, retrieve matching indexed chunks through the search/index layer, construct grounded model context, and return the generated response. lib/ollama.ts provides the local/model-service integration boundary, while app/api/search/route.ts exposes retrieval independently where needed.
Persistent Backend and Infrastructure
Convex is the primary application backend, configured by convex.config.ts and modeled in convex/schema.ts. It holds chats, source documents, chunks, and chat-index relationships; query/mutation logic is separated into convex/chats.ts, convex/documents.ts, convex/chunks.ts, and convex/chatIndex.ts. Generated Convex bindings under convex/_generated/ connect typed frontend/server code to that backend.
Material Runtime Boundaries
The application runs on Next.js/React with App Router API routes. Convex supplies persistent server-side data operations and reactive application state. Ollama is the external/local LLM runtime accessed via lib/ollama.ts; PDF parsing is isolated behind lib/pdf.ts. This separation keeps model inference and file parsing outside UI components and makes API handlers the orchestration layer.
Main entry points: page.tsx Chat view · schema.ts Data schema · route.ts Index chat API · agent.ts Grounded agent
Components 17
Next.js UI
- Landing page · Browser entry for starting or opening chats.
app/page.tsx - Chat view · Conversation UI isolated by chat ID.
app/chat/[chatId]/page.tsx - App providers · Connects client state and services.
app/providers.tsx - App shell
app/layout.tsx
API workflow
- Upload API
app/api/upload/route.ts - Index chat API
app/api/index-chat/route.ts - Search API · Independent retrieval endpoint.
app/api/search/route.ts - Chat agent API
app/api/chat/[...slug]/route.ts - Grounded agent · Builds context from chat-scoped retrieval and generates replies.
lib/agent.ts
Convex backend
- Data schema · Models chats, documents, chunks, and index relationships.
convex/schema.ts - Chats
convex/chats.ts - Documents · Persists source document metadata and content.
convex/documents.ts - Chunks · Partitions and retrieves text units.
convex/chunks.ts - Chat index · Maintains chat-scoped document/chunk associations.
convex/chatIndex.ts - Typed Convex bindings
Runtime integrations
- PDF parser
lib/pdf.ts - Ollama · Local or external model-service boundary.
lib/ollama.ts
Connections 24
- App shell → App providers: wraps
- App providers → Landing page: supports
- App providers → Chat view: supports
- Landing page → Chat view: opens /chat/[chatId]
- Chat view → Upload API: uploads documents
- Chat view → Index chat API: indexes for chat
- Chat view → Search API: retrieves context
- Chat view → Chat agent API: sends messages
- Upload API → PDF parser: parses PDF
- Upload API → Documents: stores source
- Index chat API → Documents: reads source
- Index chat API → Chunks: creates chunks
- Index chat API → Chat index: associates with chat
- Search API → Chat index: resolves chat scope
- Search API → Chunks: returns matching chunks
- Chat agent API → Grounded agent: orchestrates request
- Grounded agent → Chats: resolves chat
- Grounded agent → Chat index: retrieves indexed context
- Grounded agent → Ollama: generates response
- Typed Convex bindings → Data schema: typed from
- Chats → Data schema: uses
- Documents → Data schema: uses
- Chunks → Data schema: uses
- Chat index → Data schema: uses