How snsa-kscc/edureteai works
Project Type and Purpose
• edureteAI is a full-stack, chat-focused web application built with Next.js (App Router) that leverages large language models (LLMs) to let students experiment with and compare AI model outputs.
• It integrates user management (Clerk), payment/billing (Stripe + Neon PostgreSQL), chat memory (Upstash Redis), multimodal uploads, and streams UI components via Vercel’s AI SDK.
High-Level File/Folder Structure Analysis
• app/ → Next.js App Router: React Server/Client components, page layouts, and REST/edge API route handlers (chat, billing, uploads).
• components/ & components/ui/ → Reusable UI building blocks (chat form, sidebar, design system).
• lib/ → Business logic & integrations (chat config, model limits, Stripe actions, Redis/Neon actions).
• db/ & migrations/ → Database schema definitions and SQL migrations for PostgreSQL.
• hooks/ → Custom React hooks (clipboard, streaming text, image uploads).
• public/ → Static assets (CSS, JS, fonts, images).
• middleware.ts, next.config.mjs, vercel.json → Deployment and routing configurations.
Additional README Insights
• “Generative UI architecture”: UI components stream in real-time based on AI responses.
• External services: Clerk for authentication, Upstash Redis for KV chat memory, Neon PostgreSQL for billing/rate-limit, Stripe for payments, Vercel AI SDK + third-party LLM providers.
a. Main Components
• User Browser (React Client)
• Next.js Server (Server-Side & Edge Functions)
• API Routes Layer (chat, stripe, upload-picture, send-report)
• Authentication Service (Clerk)
• AI Orchestration (Vercel AI SDK + multiple LLM Vendors)
• KV Store (Upstash Redis)
• Relational DB (Neon PostgreSQL)
• Payment Processor (Stripe)
• Object Storage or Upload Service (for image uploads)
b. Relationships & Data Flow
1. User interacts with React UI → Next.js pages/components under app/.
2. UI calls API routes (/api/chat, /api/stripe/route.ts, /api/upload-picture) via fetch or streaming RPC style.
3. API handlers authenticate via Clerk middleware → authorize requests.
4. Chat handler uses Vercel AI SDK to fan-out requests to different LLM endpoints and streams responses back to the client.
5. Chat memory is read/write in Upstash Redis; usage metrics and rate limits validated.
6. Billing events (subscription creation, payments) go through Stripe API → webhooks update Neon PostgreSQL via subscription-actions.
7. Upload-picture handler stores images in object storage (cloud bucket or your choice) and returns secure URLs.
8. Reporting endpoint (/api/send-report) aggregates data from Redis and PostgreSQL to generate usage reports.
c. Architectural Patterns & Principles
• Generative UI (streaming React components).
• Edge/serverless functions for low-latency API.
• Clear separation of concerns: UI vs. API vs. data.
• Modular business logic in lib/ for testability and reuse.
d. Key Technologies & Frameworks
• Next.js App Router (React 18+ server/client components)
• Vercel AI SDK
• Clerk for auth
• Upstash Redis (KV)
• Neon PostgreSQL (serverless)
• Stripe (billing + webhooks)
• pnpm, TypeScript, Tailwind/CSS modules