How manavalan2517/ai-lms works
1. This repository is a Next.js App Router application for an AI-powered LMS. The core architecture is split into three layers: UI pages under app/, HTTP API routes under app/api/, and asynchronous background work under inngest/. Persistent state lives in a PostgreSQL database accessed through Drizzle ORM.
2. Authentication is handled by Clerk and integrated at the app boundary. The app/(auth) route group contains sign-in and sign-up screens, while middleware.js likely protects authenticated routes and redirects unauthenticated users. app/provider.js and the root layout wire Clerk context into the client UI.
3. The main user-facing flows are organized by route: app/create for starting a new learning plan, app/dashboard for listing and tracking courses, and app/course/[courseId] for viewing an individual course. The course area is further subdivided into notes, flashcards, quiz, and Q&A pages, each with its own UI components.
4. Course creation is a two-step pipeline. The create page collects topic, course type, and difficulty, then calls /api/generate-course-outline. That endpoint creates the course record and triggers AI generation of the outline. The generated outline becomes the parent structure for all later study materials.
5. Study material generation is intentionally asynchronous. /api/study-type-content triggers Inngest jobs for flashcards, quizzes, and Q&A, rather than generating everything inline in the request. This lets the UI show “generating” states while the background workers produce content and update database status fields.
6. Notes appear to be generated as part of the course outline pipeline, while flashcards/quiz/Q&A are generated per chapter or study type. The readme indicates notes are stored as markdown, and the course pages render them with markdown tooling. This means content is structured in the database but presented as rich text in the UI.
7. The database boundary is centralized in configs/db.js and configs/schema.js, with Drizzle ORM defining the data model. The schema likely includes users, courses, chapters, and study-material tables or fields for statuses and generated content. All API routes and Inngest functions use this shared schema rather than duplicating persistence logic.
8. Inngest is the orchestration layer for side effects. inngest/client.js and inngest/functions.js define event-driven jobs such as user creation sync, course-outline generation, note generation, and study-type generation. app/api/inngest/route.js exposes the webhook/handler endpoint that Inngest uses to run these jobs.
9. The AI boundary is isolated in configs/AiModel.js. That file likely encapsulates Gemini model setup and prompt templates so the rest of the code only deals with “generate outline,” “generate notes,” or “generate flashcards” operations. This keeps AI prompting and model selection separate from routing and persistence.
10. The dashboard is the operational hub for a logged-in user. Its components show course cards, progress, alerts, loading states, and a welcome banner. That suggests the dashboard reads course rows from the database and reflects generation status rather than recomputing anything locally.
11. The course detail area is built as a nested layout with reusable section components. CourseIntroCard, ChapterList, and StudyMaterialSection form the top-level structure, while the flashcard subroute uses Swiper and flip-card UI, the quiz subroute provides interactive scoring/timers, and the notes/Q&A views focus on markdown rendering.
12. Overall data flow: user authenticates with Clerk → creates a course from the create page → API persists the course and enqueues Inngest jobs → Gemini generates outline and study content → Drizzle writes results and status back to Postgres → dashboard and course pages read the stored course/material data and render the appropriate study experience. The main architectural boundary is between synchronous request/response endpoints and asynchronous AI generation workers.
Main entry points: layout.jsx Course Layout · db.js Database · route.js Outline API · functions.js Jobs
Components 23
App Router
User-facing routes, layouts, and page flows
- Root Layout · Global app shell and shared providers
app/layout.js - Provider · Wires shared client context such as authentication
app/provider.js - Middleware · Protects routes and handles auth redirects
middleware.js - Auth Pages · Sign-in and sign-up route group
app/(auth) - Create Flow · Collects topic and course parameters before generation
app/create/page.jsx - Dashboard · Shows course list, progress, alerts, and loading states
app/dashboard/page.jsx - Course Layout · Shared shell for course detail subroutes
app/course/layout.jsx - Course View · Main course page with intro and chapter navigation
app/course/[courseId]/page.jsx - Notes · Renders generated notes for a course
app/course/[courseId]/notes/page.jsx - Flashcards · Interactive flashcard study experience
app/course/[courseId]/flashcards/page.jsx - Quiz · Timed quiz and scoring experience
app/course/[courseId]/quiz/page.jsx - Q&A · Question and answer study view
app/course/[courseId]/qa/page.jsx
API Layer
HTTP endpoints for persistence and AI orchestration
- Courses API · Reads and serves course records
app/api/courses/route.js - Create User · Creates or syncs user records after auth events
app/api/create-user/route.js - Outline API · Persists a course and starts outline generation
app/api/generate-course-outline/route.js - Study Type API · Starts asynchronous study content jobs
app/api/study-type/route.jsx - Study Content API · Enqueues flashcard, quiz, and Q&A generation
app/api/study-type-content/route.jsx - Inngest Hook · Receives Inngest event deliveries
app/api/inngest/route.js
Core Services
Shared database, AI, and background job infrastructure
- Database · Shared Drizzle connection to persistent storage
configs/db.js - Schema · Central data model for users, courses, chapters, and materials
configs/schema.js - AI Model · Encapsulates prompting and model calls for content generation
configs/AiModel.js - Inngest Client · Defines the application event bus integration
inngest/client.js - Jobs · Runs outline, notes, and study material background tasks
inngest/functions.js
Connections 21
- Root Layout → Provider: wraps · Root layout injects shared client providers
- Middleware → Auth Pages: guards · Protects authenticated areas and routes unauthenticated users
- Auth Pages → Provider: uses · Auth UI depends on app-wide provider context
- Create Flow → Outline API: submits · Create flow sends course setup data to the outline endpoint
- Dashboard → Courses API: reads · Dashboard loads user courses and progress
- Course Layout → Course View: wraps · Shared course shell contains the main course view
- Course Layout → Notes: routes to · Layout serves the notes subroute
- Course Layout → Flashcards: routes to · Layout serves the flashcards subroute
- Course Layout → Quiz: routes to · Layout serves the quiz subroute
- Course Layout → Q&A: routes to · Layout serves the Q&A subroute
- Outline API → Database: writes · Persists the course before generation starts
- Outline API → AI Model: calls · Uses AI to generate the course outline and notes
- Outline API → Inngest Client: emits · Triggers event-driven background processing
- Study Type API → Inngest Client: emits · Starts asynchronous study material jobs
- Study Content API → Inngest Client: emits · Enqueues study content generation tasks
- Inngest Hook → Jobs: serves · Webhook handler executes registered background jobs
- Jobs → AI Model: calls · Workers generate outlines, notes, and study content
- Jobs → Database: updates · Workers persist generated content and status fields
- Database → Schema: conforms to · Database access is structured by the shared schema
- Create User → Database: writes · Syncs user records into Postgres
- Courses API → Database: reads · Serves stored course data to the UI