How namanpatel7030/scanx---ai-note-writer-applicataion- works
Project Type and Purpose
• Full‑stack, server‑rendered React application built with Next.js (App Router).
• Purpose: AI‑powered note writer that lets authenticated users upload PDFs, view/edit them in a workspace, and generate AI‑assisted notes.
• Backed by Convex (real‑time database + serverless functions), integrates with an external AI model (via configs/AIModel.js, likely OpenAI).
Main Components
a. Client (Browser) / Frontend
– Next.js pages (scanx/app/…)
• Public pages: /about, /features, /pricing, /solution
• Auth pages: /sign‑in, /sign‑up (App Router dynamic routes)
• Dashboard: /dashboard, /dashboard/upgrade
• Workspace: /workspace/[fileid] with sub‑components (PdfViewer, TextEditor, EditorExtension)
– Shared UI library (scanx/components/components/ui) for buttons, dialogs, inputs, progress, etc.
– Global styles (tailwind & postcss), provider.js, middleware.js for authentication checks.
b. Backend / Serverless
– Next.js API routes (scanx/app/api/pdf‑loader/route.js) for handling file uploads, perhaps returning a fileId.
– Convex functions & schema (scanx/convex/)
• Schema: defines collections (users, notes, pdfStorage, etc.).
• Generated client/server bindings (_generated/...).
• Serverless actions: user.js, notes.js, pdfStorage.js, myAction.js, langchain/db.js – implement core business logic, database queries, AI calls.
c. Database & Real‑Time
– Convex Database (NoSQL document store)
– Real‑time subscriptions for collaborative editing or status updates in the workspace.
d. External AI Service
– AIModel.js config points to whatever external LLM (e.g., OpenAI) is used via LangChain (scanx/convex/langchain/db.js).
– The Convex action functions orchestrate AI calls and post back results to the DB.
e. File Storage
– PDF storage is handled inside Convex (pdfStorage.js) or an external blob store (if implemented).
– Next.js public/ folder for static assets.
Relationships & Data Flow
1. User in Browser → Next.js SSR/CSR page load → UI components render.
2. User uploads PDF via UploadPdf component → Next.js API route (/api/pdf‑loader) → Convex function stores PDF and returns fileId.
3. Frontend navigates to /workspace/[fileid] → subscribes to Convex DB for that file’s metadata & notes.
4. User edits text in TextEditor → real‑time updates via Convex client → Convex DB writes.
5. User triggers AI note generation → Frontend calls a Convex action (myAction or LangChain function) → action fetches PDF text, calls external AI (OpenAI), writes result as “note” document.
6. Convex subscriptions push new notes back to the UI → User sees AI‑generated notes in workspace.
Architectural Patterns & Design Principles
• Component‑based UI: re‑usable, decoupled UI primitives in components/ui.
• App Router and API Routes: clear separation of serverless endpoints and page logic.
• Real‑time data with Convex: subscription‑based updates mean less manual polling.
• Serverless functions: isolates business logic close to data, scales automatically.
• Single codebase monorepo: frontend, backend, config, and shared utils in one place.