Overview
What this repository is doing
The codebase combines a public acquisition funnel with a private workspace that syncs files, runs AI, and keeps usage and billing in sync.
Public surface
The landing page, signup flow, subscription page, and credit pack page are all geared toward getting a user into the product and keeping the credit meter moving.
Workspace surface
The authenticated workspace is where the product actually lives: file tree, inline editor, graph view, chat panel, upload flows, and OCR-backed document navigation.
Routing
User-facing pages
These are the routes people actually see. Each one is backed by a page file under app/.
/
Landing page
Public marketing funnel and the first entry point into the product.
/signup
Signup
Firebase sign-up overlay that provisions the user record and free credits.
/subscribe
Subscribe
Razorpay subscription checkout with trial setup and billing state updates.
/credits
Credits
One-time credit pack purchase flow with Razorpay order creation and verification.
/app
Workspace
Authenticated file explorer, editor, graph view, and chat panel.
/manual
Manual parser
Parses pasted text or JSON into locate-compatible video and PDF matches.
/locate
Locate
OCR-backed page browser and passage finder for scanned pages and notes.
/cost
Cost analysis
Token, cost, and credit accounting across sessions and API calls.
/view/[sessionId]
Session trace
Redirects to the local session viewer for a single chat session.
Backend
API route groups
Most of the app's behavior is routed through app/api/*. These groups are the main clusters the UI and agent depend on.
Identity and billing
Workspace storage
Locate, OCR, graph
Agent and history
Workspace
Files, explorer, and the main editing loop
The file explorer is a lightweight file manager with direct edit, move, rename, duplicate, and sync operations.
Core UI files
app/app/page.tsxmounts the workspace.app/components/file-explorer/FileExplorer.tsxowns the layout.app/components/chat/ChatPanel.tsxhandles agent chat.
Key abilities
- Rename, move, delete, duplicate, and create files or folders.
- Upload textbook PDFs and handwritten notes.
- Preview text, code, images, PDFs, videos, and graphs.
Shortcuts
Cmd/Ctrl+B
Toggle the file explorer sidebar.
Cmd/Ctrl+S
Save every dirty file in the workspace.
Shift+Tab
Cycle the thinking level in chat.
/chat ...
First message can restart the agent in general mode.
Agent
Chat, sessions, and the SSE control plane
The agent backend is separated into route handling, session management, custom tools, and request-scoped context. That separation is intentional.
Agent files
app/api/agent/route.tsexposes SSE plus session commands.app/api/agent/sessions.tsowns lifecycle, persistence, and tool wiring.app/api/agent/custom-tools.tsdefines the tool registry.app/api/agent/context.tsinjects request-scoped uid and session ids.
Session flow
start
Create a new in-memory agent session and attach a DB session id.
resume
Recreate an in-memory session for an existing DB session.
command
Send a model, thinking, or prompt command to the live agent.
kill
Terminate an agent session.
abort
Abort the currently running turn.
Locate
OCR, passage matching, and manual parsing
One of the most distinctive parts of the app: split PDFs into page images, OCR those pages, and then find the best contiguous passage for a query.
Locate flow
/api/files/split-pdfrenders PDFs into numbered page PNGs./api/vision/polygonsOCRs page images and writes boundary JSON./api/locate/embedprecomputes embeddings for scoped pages./api/locate/findasks Gemini to select one contiguous match.
Manual parser
The /manual page feeds free-form text into a Groq-backed parser that extracts PDF and video matches into the same locate result shape used by chat and the file explorer.
Graph
Graph view and data model
The app stores both relational records and graph edges. The graph viewer is a visual front end over Neo4j.
Graph surfaces
/api/graphreturns nodes and edges for the viewer.app/components/file-explorer/viewer/GraphViewer.tsxrenders the force graph.- Tools like
graph_query,cypher_query, andinsert_relationshipmutate it.
Prisma schema
User,CreditTransaction,ChatSession, andChatMessagepower billing and chat history.FsNode,FsSnapshot,SyncEvent, andTreeIndexsupport file indexing and sync history.ApiCallLogtracks token usage and provider/model costs for reporting.
Billing
Auth, credits, subscription, and webhook flow
Firebase provides identity, Prisma stores the ledger, and Razorpay drives both subscriptions and credit purchases.
Auth session
/api/auth/session turns a Firebase ID token into a session cookie, and lib/auth-context.tsx syncs that cookie on sign-in and clears it on sign-out.
Provisioning
/api/provision creates the S3 userdata prefix and grants the signup bonus credits on first sign-in.
Payments
Subscription and one-time credit purchases both go through Razorpay, with webhook-driven status updates for subscription state.
REST tools
Tools that can be run over REST
The agent tool registry is directly exposed through /api/tools and /api/tools/[tool], so the same capabilities available to the agent can be called from HTTP.
Invocation pattern
GET /api/tools
POST /api/tools/[tool]
// body
{
"args": { ... }
}The handler returns { ok, result } and parses JSON when the tool returns JSON text. That makes it easy to script the same operations the agent uses.
Example calls
curl http://localhost:3000/api/tools
curl -X POST http://localhost:3000/api/tools/split_pdf_to_pages \
-H 'Content-Type: application/json' \
-d '{"args":{"pdf_path":"Notes/demo.pdf","wait":false}}'
curl -X POST http://localhost:3000/api/tools/graph_status \
-H 'Content-Type: application/json' \
-d '{"args":{}}'Model control
Ingest and reading
Persistence and graph
Retrieval and analysis
Batch variants
Repo map
Other code and support files worth knowing
These files explain the repo beyond the UI. They are useful when you want to understand the product model or the offline tooling.
Framework and config
- Next.js 16 App Router is the routing model.
- next.config.ts ignores TS build errors for the external agent package.
- A rewrite maps /models.json to /gemini/models.json.
- serverExternalPackages includes Pi, Prisma adapter, Postgres, and Neo4j packages.
Reference docs
- AGENTS.md and CLAUDE.md describe how the agent should treat the repo.
- system.md, llmwiki.md, and sdk.md explain the knowledge-base and SDK patterns.
- ref/ contains auth notes, SDK references, and debug artifacts.
Offline tooling
- utils/sync_userdata.py, utils/migrate_postgres.py, and utils/run_cypher.py support data movement.
- prisma/*.sql appears to hold import and migration helpers.
- public/userdata/ contains the real corpus, OCR artifacts, transcripts, notes, and media.
Finish
Operational summary
If you remember one thing from this repo, remember this: it is a document workspace with an agent and a billing loop, not just a chat demo.
The codebase is centered on turning uploaded or synced content into a searchable, navigable knowledge system. Users sign in with Firebase, receive credits, browse and edit files, chat with an agent, run OCR and locate flows over PDFs and notes, and inspect costs and graph data as the workspace grows.
The agent stack is especially important: app/api/agent/sessions.ts handles lifecycle and persistence, app/api/agent/custom-tools.ts exposes the toolbelt, and app/api/tools gives you a REST path to invoke those same tools directly.