How akshat-owo/down works
Project Type and Purpose
• “Down” is a full-stack web application (Next.js) that lets users upload PDFs, index them in a vector store, and chat with a bot that answers questions about the PDF content.
• It’s backed by a MySQL (PlanetScale) database (via Prisma), a Pinecone vector store, the OpenAI API for embeddings and chat, and Stripe for billing. Authentication uses Kinde.
File Structure
• src/app: Next.js 13 “app directory” with pages (/, /pricing, /dashboard, /auth-callback, etc.).
• src/app/api: Next.js API routes split into:
• auth/[kindeAuth] for login callbacks
• message and trpc endpoints for your chat backend
• uploadthing endpoints for PDF upload
• webhooks/stripe for billing events
• src/app/_trpc: client instantiation
• src/components: React UI, chat widgets, upload buttons, billing form, Navbars, etc.
• prisma/schema.prisma: DB schema
• src/lib: wrappers around OpenAI, Pinecone, Stripe, file-upload logic
• src/trpc: server-side TRPC init
• src/db/index.ts: Prisma client
• config files: stripe, infinite-query (TanStack Query), tailwind, next.config.js, etc.
README for Additional Insights
• Confirms tech stack (Next.js, Tailwind, Radix UI, PlanetScale, OpenAI, Pinecone).
• Explains user flows: signup/login, upload PDF, chat interface, billing.
a. Main Components
• Client Browser (React/Next.js)
• Next.js Server (app router + API routes + TRPC)
• Auth Service (Kinde)
• PDF-Upload Service (UploadThing)
• Chat Backend (TRPC handlers calling lib/openai & lib/pinecone)
• Database (PlanetScale via Prisma)
• Vector Store (Pinecone)
• LLM Service (OpenAI)
• Billing Service (Stripe + webhooks)
b. Relationships & Interactions
1. User Browser → Next.js pages for UI
2. Browser → API routes (via TRPC client or REST endpoints) for:
– Authentication → Kinde
– PDF upload → UploadThing → Next.js → store file metadata in PlanetScale
– Chat requests → TRPC endpoint → query Pinecone for relevant embeddings → call OpenAI → return answers
– Billing → Stripe Checkout → Webhook → Next.js /webhooks/stripe → update subscription in DB
3. Next.js Server ↔ PlanetScale (Prisma client) for user, file, billing records
4. Next.js Server ↔ Pinecone for vector insert/query
5. Next.js Server ↔ OpenAI (embeddings + chat completions)
c. Architectural Patterns & Principles
• Monolithic full-stack app using Next.js app router
• API boundary via Next.js API routes + TRPC for type-safe RPC
• Separation of concerns: UI, API, DB, vector store, billing, auth, external AI
• Dependency inversion: wrap external services in src/lib for easier testing/mocking
d. Key Technologies/Frameworks
• Next.js 13 (app router + server components)
• TRPC (end-to-end typesafe APIs)
• Prisma + PlanetScale (MySQL)
• Pinecone (vector search)
• OpenAI (GPT embeddings & chat)
• UploadThing (file hosting)
• Stripe (billing + webhooks)
• Kinde (authentication)
• Tailwind CSS & Radix UI for design
Detail without Over-Engineering
• How TRPC client.ts plugs into the TRPC routes on the server.
• Middleware.ts if applicable for cross-cutting concerns (authentication checks, logging).
• Don’t forget the Prisma schema leading to PlanetScale and the Pinecone indexer service.