- Project Overview
- Tech Stack
- Project Structure
- Environment Variables & Credentials Management
- Authentication System
- Database Architecture
- API Endpoints
- Pages & Routing
- Components Architecture
- Server Actions
- Real-time Features
- Code Execution System
- AI Integration
- Admin Panel
- UI/UX Features
- Security Considerations
- Data Flow Diagrams
Inherit is an AI-powered personalized coding education platform built with Next.js 14. Named after Aristotle's ancient school (Lyceum), it combines traditional learning principles with modern technology to provide an immersive and structured learning experience for aspiring developers.
- Learning Platform: Curated video tutorials from top programming channels (freeCodeCamp, Telusko)
- AI-Powered Roadmaps: Custom learning path generation based on user goals
- Quest System: Time-based coding challenges with AI-powered evaluation
- Dev Discuss: Community-driven Q&A forum with optional AI answers
- Code Playground: Real-time collaborative coding environment
- Dashboard: Progress tracking, learning streaks, and statistics
Bridge the digital divide by making coding education accessible, collaborative, and empowering for everyone, particularly focusing on Bangladesh's tech industry growth.
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 14.x | React framework with App Router |
| React | 18.3.1 | UI library |
| Tailwind CSS | 3.3.2 | Utility-first CSS framework |
| Framer Motion | 11.18.1 | Animation library |
| Monaco Editor | 4.6.0 | Code editor (VS Code engine) |
| React Icons | 5.5.0 | Icon library |
| Library | Purpose |
|---|---|
| Radix UI | Accessible primitives (Dialog, Select, Tabs, Progress) |
| Chakra UI | Component library |
| shadcn/ui | Pre-built components (New York style) |
| Headless UI | Unstyled accessible components |
| Lucide React | Icon set |
| Technology | Purpose |
|---|---|
| Next.js API Routes | Backend API endpoints |
| MongoDB | Database |
| Mongoose | ODM for MongoDB |
| Service | Purpose |
|---|---|
| Clerk | User authentication & management |
| svix | Webhook verification |
| Service | Purpose |
|---|---|
| Pusher | Real-time WebSocket connections |
| Pusher.js | Client-side Pusher SDK |
| Service | Purpose |
|---|---|
| Groq AI | LLM for code reviews, quest evaluation, roadmap generation |
| Model: llama-3.3-70b-versatile | Primary AI model |
| Service | Purpose |
|---|---|
| YouTube Data API v3 | Video search and metadata |
| Piston API | Code execution engine |
| Service | Purpose |
|---|---|
| Vercel Analytics | Usage analytics |
| Vercel Speed Insights | Performance monitoring |
| Library | Purpose |
|---|---|
| axios | HTTP client |
| date-fns | Date manipulation |
| react-confetti | Celebration animations |
| react-joyride | Onboarding tours |
| react-markdown | Markdown rendering |
| howler/use-sound | Audio playback |
inherit/
├── app/ # Next.js 14 App Router
│ ├── admin/ # Admin panel
│ │ ├── components/ # Admin-specific components
│ │ │ ├── AdminHeader.jsx
│ │ │ ├── QuestForm.jsx
│ │ │ └── QuestList.jsx
│ │ ├── login/page.jsx # Admin login
│ │ ├── layout.jsx # Admin layout (no sidebar)
│ │ └── page.jsx # Admin dashboard
│ │
│ ├── api/ # API Routes
│ │ ├── admin/ # Admin-protected endpoints
│ │ │ ├── auth/route.js # Admin authentication
│ │ │ └── quests/ # Quest CRUD operations
│ │ ├── attempts/ # Quest attempt management
│ │ ├── leaderboard/ # Leaderboard data
│ │ ├── Piston/api.js # Code execution wrapper
│ │ ├── questions/ # Dev discuss questions
│ │ ├── quests/ # Public quest endpoints
│ │ ├── video-search/ # YouTube video search
│ │ ├── voice-routing/ # Voice command processing
│ │ └── webhooks/clerk/ # Clerk webhook handler
│ │
│ ├── components/ # App-level components
│ │ ├── dev-discuss/ # Discussion components
│ │ ├── playground/ # Playground components
│ │ ├── ClientLayout.jsx # Conditional layout wrapper
│ │ ├── fun-loaders.jsx # Loading animations
│ │ ├── Header.jsx # Main navigation header
│ │ ├── LandingPage.jsx # Homepage
│ │ └── Sidebar.jsx # Navigation sidebar
│ │
│ ├── dashboard/page.jsx # User dashboard
│ ├── dev-discuss/ # Q&A forum
│ ├── faq/ # Help & FAQ pages
│ ├── learn/ # Video learning pages
│ ├── playground/ # Collaborative coding
│ ├── quests/ # Quest system
│ ├── roadmaps/ # Learning roadmaps
│ ├── sign-in/ # Clerk sign-in
│ ├── sign-up/ # Clerk sign-up
│ │
│ ├── constants.js # Language versions & snippets
│ ├── globals.css # Global styles & CSS variables
│ ├── layout.jsx # Root layout
│ ├── not-found.jsx # 404 page
│ └── page.jsx # Landing page wrapper
│
├── components/ # Shared components
│ ├── learn/ # Learning feature components
│ │ ├── editor/ # Code editor components
│ │ ├── CodeWorkspace.jsx
│ │ └── VideoPlayer.jsx
│ ├── playground/ # Playground components
│ ├── ui/ # shadcn/ui components
│ ├── Progress.jsx
│ └── TourGuide.jsx # Onboarding tour
│
├── lib/ # Utilities & business logic
│ ├── actions/ # Server actions
│ │ ├── codeReview.js # AI code review
│ │ ├── quest.js # Quest evaluation
│ │ ├── question.js # Question management
│ │ ├── roadmap.js # Roadmap generation
│ │ └── user.js # User management
│ ├── middleware/
│ │ └── adminAuth.js # Admin auth middleware
│ ├── models/ # Mongoose schemas
│ │ ├── attemptModel.js
│ │ ├── questionModel.js
│ │ ├── questModel.js
│ │ ├── roadmapModel.js
│ │ └── userModel.js
│ ├── mongodb/
│ │ └── mongoose.js # Database connection
│ ├── pusher-client.js # Client-side Pusher
│ ├── pusher.js # Server-side Pusher
│ └── utils.js # Utility functions (cn)
│
├── pages/api/ # Pages Router API (Socket)
│ └── socket.js # Pusher socket handler
│
├── public/ # Static assets
│ ├── sounds/ # Audio files
│ └── *.png, *.svg # Images
│
├── middleware.js # Next.js middleware
├── next.config.js # Next.js configuration
├── tailwind.config.js # Tailwind configuration
├── components.json # shadcn/ui configuration
├── jsconfig.json # Path aliases
└── package.json # Dependencies
# ============================================
# CLERK AUTHENTICATION
# ============================================
# Get from: https://dashboard.clerk.com
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...
WEBHOOK_SECRET=whsec_...
# Clerk redirect URLs
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard
# ============================================
# DATABASE
# ============================================
# MongoDB Atlas connection string
MONGODB_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/<database>
# ============================================
# AI SERVICES
# ============================================
# Groq AI - Get from: https://console.groq.com
GROQ_API_KEY=gsk_...
# Optional: Plagiarism check service
PLAGIARISM_CHECK_API_KEY=your_key
# ============================================
# YOUTUBE API
# ============================================
# Google Cloud Console YouTube Data API v3
# Supports multiple comma-separated keys for rate limiting
NEXT_PUBLIC_YOUTUBE_API_KEY=key1,key2,key3
# ============================================
# REAL-TIME (PUSHER)
# ============================================
# Get from: https://dashboard.pusher.com
PUSHER_APP_ID=123456
NEXT_PUBLIC_PUSHER_KEY=abc123...
PUSHER_SECRET=secret...
NEXT_PUBLIC_PUSHER_CLUSTER=us2
# ============================================
# APPLICATION URLs
# ============================================
NEXT_PUBLIC_SOCKET_SERVER_URL=http://localhost:3000
NEXT_PUBLIC_FRONTEND_URL=http://localhost:3000-
Clerk Authentication
- Publishable keys (NEXT_PUBLIC_*) are exposed to client
- Secret keys should never be exposed client-side
- Webhook secret used for verifying Clerk webhook signatures
-
Admin Credentials (Hardcoded - SECURITY RISK)
- Username:
admin - Password:
admin123 - Stored in
middleware.jsandlib/middleware/adminAuth.js - Recommendation: Move to environment variables
- Username:
-
YouTube API Key Rotation
- Supports multiple API keys (comma-separated)
getRandomApiKey()function randomly selects keystryWithMultipleKeys()provides fallback mechanism
┌─────────────────────────────────────────────────────────────┐
│ CLERK AUTHENTICATION │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────────────────┐ │
│ │ User │────▶│ Clerk │────▶│ Webhook (svix) │ │
│ │ Login │ │ Auth │ │ /api/webhooks/clerk │ │
│ └──────────┘ └──────────┘ └──────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────┐ │
│ │ MongoDB User Doc │ │
│ │ - clerkId │ │
│ │ - firstName │ │
│ │ - lastName │ │
│ │ - email │ │
│ │ - userName │ │
│ └──────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
- Uses
ClerkProviderwrapping the entire application - Light theme base appearance
- Redirects configured via environment variables
- Verifies webhook signatures using svix
- Handles events:
user.created: Creates new user in MongoDBuser.updated: Updates existing user datauser.deleted: Removes user from MongoDB
Public Routes:
/(home)/sign-in/sign-up/api/video-search/api/voice-routing
Ignored Routes:
/api/webhooks/*
┌─────────────────────────────────────────────────────────────┐
│ ADMIN AUTHENTICATION │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────┐ ┌──────────────┐ ┌────────────────┐ │
│ │ Admin │────▶│ /admin/login │────▶│ POST /api/ │ │
│ │ Login │ │ Form Submit │ │ admin/auth │ │
│ └──────────┘ └──────────────┘ └────────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────────────────────────────────┐ │
│ │ Credentials: admin / admin123 │ │
│ │ Store in: Cookie + SessionStorage │ │
│ │ Format: Base64 encoded "username:password" │ │
│ └────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────┐ │
│ │ middleware.js checks: │ │
│ │ - adminAuth cookie │ │
│ │ - Authorization header │ │
│ └──────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Admin Routes Protected:
/admin/*- Pages/api/admin/*- API endpoints
- Singleton pattern prevents multiple connections
- Database name:
Inherit - Uses
strictQuery: true
{
clerkId: String (required, unique), // Clerk's user ID
firstName: String (required),
lastName: String (required),
image_url: String (optional), // Profile picture URL
email: String (required, unique),
userName: String (required, unique),
createdAt: Date (default: Date.now)
}{
name: String (required),
timeLimit: Number (minutes, required),
level: Enum ['beginner', 'intermediate', 'advanced'] (required),
questions: [{
type: Enum ['short', 'coding'] (required),
title: String (required),
description: String (required),
testCases: [{
input: String,
expectedOutput: String
}],
points: Number (required)
}],
startTime: Date (required),
endTime: Date (required),
isActive: Boolean (default: true),
createdBy: String (required),
timestamps: true
}{
userId: String (required), // Clerk user ID
questId: ObjectId (ref: 'Quest', required),
startTime: Date (required),
endTime: Date,
status: Enum ['in-progress', 'completed', 'time-expired'] (default: 'in-progress'),
answers: [{
questionId: ObjectId (required),
answer: String (required),
isCorrect: Boolean (default: false),
points: Number (default: 0),
submittedAt: Date (default: Date.now),
aiEvaluation: {
score: Number (0-100, default: 0),
feedback: String (default: ''),
evaluatedAt: Date
}
}],
totalPoints: Number (default: 0),
maxPoints: Number (required),
timestamps: true
}
// Index: { userId: 1, questId: 1, status: 1 }{
title: String (required),
description: String (required),
votes: Number (default: 0),
voters: [{
userId: String (required),
vote: Number (required) // 1 or -1
}],
answers: Number (default: 0), // Reply count
views: Number (default: 0),
tags: [String],
author: String (ref: 'User', required), // userName
replies: [{
author: String (required),
content: String (required),
createdAt: Date (default: Date.now)
}],
aiAnswerRequested: Boolean (default: false),
aiAnswer: {
content: String (default: ''),
time: Date (default: Date.now)
},
timestamps: true
}{
title: String (required),
prompt: String (required), // User's learning goal
content: {
steps: [{
step: Number,
topic: String,
description: String,
documentation: String, // URL
videoId: String, // YouTube video ID
videoDuration: String // ISO 8601 duration
}]
},
author: String (required), // userName
createdAt: Date (default: Date.now)
}┌─────────────────────────────────────────────────────────────────┐
│ DATABASE RELATIONSHIPS │
├─────────────────────────────────────────────────────────────────┤
│ │
│ User (clerkId) │
│ │ │
│ ├──────┬──────┬──────────┐ │
│ │ │ │ │ │
│ ▼ ▼ ▼ ▼ │
│ Attempt Question Roadmap (author/userName reference) │
│ │ │
│ │ │
│ ▼ │
│ Quest (via questId reference) │
│ │
└─────────────────────────────────────────────────────────────────┘
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/admin/auth |
None | Admin login verification |
| POST | /api/webhooks/clerk |
Webhook | Clerk user sync |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/admin/quests |
Admin | List all quests |
| POST | /api/admin/quests |
Admin | Create new quest |
| GET | /api/admin/quests/[id] |
Admin | Get quest by ID |
| PUT | /api/admin/quests/[id] |
Admin | Update quest |
| DELETE | /api/admin/quests/[id] |
Admin | Delete quest |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/quests |
None | List active quests |
| GET | /api/quests/[questId] |
None | Get quest details |
| GET | /api/quests/user |
Clerk | User's quest stats |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/attempts |
Clerk | Start new attempt |
| GET | /api/attempts/[attemptId] |
None | Get attempt details |
| POST | /api/attempts/[attemptId]/submit |
Clerk | Submit & evaluate |
| GET | /api/attempts/user/[questId] |
Clerk | User's quest attempt |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/questions/all-questions |
Clerk | Get all questions |
| POST | /api/questions/[id]/reply |
Clerk | Add reply |
| POST | /api/questions/[id]/upvote |
Clerk | Upvote question |
| POST | /api/questions/[id]/downvote |
Clerk | Downvote question |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/video-search |
None | Search YouTube videos |
| POST | /api/voice-routing |
None | Process voice commands |
| GET | /api/leaderboard |
None | Get quest leaderboard |
| POST | /pages/api/socket |
None | Pusher socket events |
| Route | Component | Description |
|---|---|---|
/ |
LandingPage |
Marketing landing page |
/sign-in |
Clerk | User sign-in |
/sign-up |
Clerk | User registration |
| Route | Component | Description |
|---|---|---|
/dashboard |
Dashboard |
User statistics & progress |
/learn |
LearnPage |
Browse video tutorials |
/learn/[videoId] |
VideoPage |
Video + code workspace |
/roadmaps |
RoadmapsPage |
View/create roadmaps |
/roadmaps/[id] |
RoadmapDetailPage |
Roadmap steps & progress |
/quests |
QuestsPage |
Browse quests & leaderboard |
/quests/[questId]/attempt |
QuestAttemptPage |
Take a quest |
/quests/[questId]/results/[attemptId] |
QuestResultsPage |
View results & AI feedback |
/dev-discuss |
DevDiscussPage |
Community Q&A |
/dev-discuss/[Id] |
QuestionDetailPage |
Question details & replies |
/dev-discuss/ask-question |
AskQuestionPage |
Post new question |
/playground |
Playground |
Create/join coding room |
/playground/[roomId] |
RoomPage |
Collaborative coding |
/faq |
FAQPage |
Help & documentation |
/faq/contact |
Contact page | Support contact |
| Route | Component | Auth | Description |
|---|---|---|---|
/admin/login |
AdminLogin |
None | Admin login form |
/admin |
AdminDashboard |
Admin | Quest management |
Layout Structure:
RootLayout (ClerkProvider)
└── ClientLayout (conditional header/sidebar)
├── Header (shows on all except landing)
├── Sidebar (shows on all except landing, auth, admin)
├── TourGuide (onboarding tour)
└── Page Content
ClientLayout Logic:
- No layout on landing page (
/) - No sidebar on
/sign-in,/sign-up,/admin/* - Admin pages use separate
AdminLayout
- Determines which layout elements to render based on route
- Manages sidebar state (open/closed)
- Dynamically imports
TourGuide(no SSR) - Responsive sidebar behavior (auto-collapse on mobile)
- Fixed navigation bar with logo
- Clerk
UserButtonfor authentication - Links to home on logo click
- Collapsible navigation sidebar
- Sections: Dashboard, Learning, Interactive, Achievements, Help
- Tooltip on collapsed state
- Auto-expand on desktop, collapse on mobile
- Monaco Editor integration
- Multi-language support (JS, Python, Java, C++, C#, PHP)
- Features:
- Code execution via Piston API
- AI code review via Groq
- File import/export
- Auto-save to localStorage
- Keyboard shortcuts
- Cursor position tracking
- Word count
- YouTube embed iframe
- Responsive sizing
- No related videos (
rel=0)
EditorHeader.jsx: Language selector, file name, action buttonsEditorFooter.jsx: Status bar (language, cursor, word count)OutputPanel.jsx: Code execution resultsAIReviewPanel.jsx: AI review feedback displayKeyboardShortcuts.jsx: Shortcut reference modal
- Displays quest info (name, level, time, questions)
- Status badge (upcoming/active/past)
- Timeline display (start/end times)
- Action button for active quests
- Top 10 users by total score
- Shows rank, username, points, quests completed
- Highlights current user
QuestPageLoader: Loading quests animationQuestAttemptLoader: Loading attempt animationQuestResultsLoader: Processing results animationSubmissionLoader: Submit overlay with progress
| Component | Purpose |
|---|---|
QuestionHeader.jsx |
Page header with "Ask Question" button |
QuestionFilters.jsx |
Search and filter controls |
QuestionTabs.jsx |
Tab navigation (all/my questions/popular) |
QuestionList.jsx |
List of question cards |
QuestionCard.jsx |
Individual question preview |
Loading.jsx |
Skeleton loading state |
QuestionDetailLoading.jsx |
Detail page skeleton |
- Displays active users in room
- Avatar circles with initials
- Overflow counter for 3+ users
| Component | File | Radix UI Base |
|---|---|---|
| Button | button.jsx |
Slot |
| Card | card.jsx |
Native |
| Dialog | dialog.jsx |
Dialog |
| Input | input.jsx |
Native |
| Select | select.jsx |
Select |
| Skeleton | skeleton.jsx |
Native |
| Tabs | tabs.jsx |
Tabs |
| Textarea | textarea.jsx |
Native |
- Uses
react-joyridefor onboarding - Different tours for guests vs. signed-in users
- Persists tour completion in localStorage
- Highlights sidebar navigation items
// Create or update user from Clerk webhook
createOrUpdateUser(id, first_name, last_name, image_url, email, username)
// Delete user when removed from Clerk
deleteUser(id)// Create question with optional AI answer
createQuestion(title, description, tags, author, aiAnswerRequested)
// - Creates question in DB
// - Async generates AI answer if requested
// Get question by ID
getQuestionById(questionId)
// - Fetches question with formatted replies// Create AI-generated roadmap
createRoadmap(title, prompt, author)
// - Validates topic is CS/IT related
// - Generates learning steps via Groq
// - Fetches YouTube videos for each step
// Get user's roadmaps
getUserRoadmaps(author)
// Get roadmap by ID
getRoadmapById(id)Roadmap Generation Flow:
- Validate topic relevance (CS/IT only)
- Generate roadmap steps via Groq AI
- For each step, search YouTube for tutorials
- Filter videos by duration (>10 minutes)
- Attach video IDs to roadmap steps
// Evaluate individual answer using AI
evaluateQuestAnswer(questData, userAnswer, questionData)
// - Returns score, feedback, evaluatedAt
// Submit and evaluate entire attempt
submitQuestAttempt(attemptId, answers)
// - Evaluates each answer
// - Calculates total scoreAI Evaluation Criteria:
- Correctness of solution
- Code quality and best practices
- Efficiency and optimization
- Clarity and readability
- Test cases passed (for coding questions)
// Generate AI code review
generateReview(code, retries = 3)
// Returns: { suggestions, issues, improvements }Review Structure:
{
suggestions: [{
title: String,
description: String,
code: String,
lineNumber: Number
}],
issues: [{
title: String,
description: String,
severity: 'high' | 'medium' | 'low',
code: String,
lineNumber: Number
}],
improvements: [{
title: String,
description: String,
code: String,
lineNumber: Number
}]
}Server (lib/pusher.js):
new Pusher({
appId: process.env.PUSHER_APP_ID,
key: process.env.NEXT_PUBLIC_PUSHER_KEY,
secret: process.env.PUSHER_SECRET,
cluster: process.env.NEXT_PUBLIC_PUSHER_CLUSTER,
useTLS: true
})Client (lib/pusher-client.js):
new Pusher(process.env.NEXT_PUBLIC_PUSHER_KEY, {
cluster: process.env.NEXT_PUBLIC_PUSHER_CLUSTER,
enabledTransports: ['ws', 'wss'],
forceTLS: true
})Channel Format: room-{roomId}
Events:
| Event | Trigger | Payload |
|---|---|---|
join-room |
User joins room | { roomId, userId, username } |
leave-room |
User leaves room | { roomId, userId } |
codeUpdate |
Code changes | { userId, username, data } |
collaboratorsUpdate |
Room membership changes | [{ userId, username, timestamp }] |
┌─────────────────────────────────────────────────────────────────┐
│ REAL-TIME COLLABORATION FLOW │
├─────────────────────────────────────────────────────────────────┤
│ │
│ User A User B │
│ │ │ │
│ │ 1. POST /api/socket │ │
│ │ event: 'join-room' │ │
│ │ │ │ │
│ │ ▼ │ │
│ │ ┌───────────────┐ │ │
│ │ │ Pusher │────────────────────────┼──────────▶ │
│ │ │ Server │ collaboratorsUpdate │ │
│ │ └───────────────┘ │ │
│ │ │ │ │
│ │ 2. Type code │ │ │
│ │ POST /api/socket │ │
│ │ event: 'codeUpdate' │ │
│ │ │ │ │
│ │ ▼ │ │
│ │ ┌───────────────┐ │ │
│ │ │ Pusher │────────────────────────┼──────────▶ │
│ │ │ Server │ codeUpdate │ Editor │
│ │ └───────────────┘ │ updates │
│ │ │ │
└─────────────────────────────────────────────────────────────────┘
- Rooms stored in memory (
roomCollaboratorsMap) - 7-character uppercase room codes (UUID-based)
- Auto-cleanup when all users leave
Endpoint: https://emkc.org/api/v2/piston
Supported Languages:
const LANGUAGE_VERSIONS = {
python: "3.10.0",
csharp: "6.12.0",
php: "8.2.3",
java: "15.0.2",
typescript: "5.0.3",
javascript: "18.15.0",
cpp: "17.0.0"
};Request Format:
{
language: "python",
version: "3.10.0",
files: [{
content: "print('Hello World')"
}]
}Response Format:
{
run: {
output: "Hello World\n",
stderr: "" // Error output if any
}
}┌─────────────────────────────────────────────────────────────────┐
│ CODE EXECUTION FLOW │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Monaco Editor │
│ │ │
│ │ User clicks "Run" │
│ ▼ │
│ ┌──────────────┐ │
│ │ executeCode │ │
│ │ function │ │
│ └──────────────┘ │
│ │ │
│ │ POST /api/v2/piston/execute │
│ ▼ │
│ ┌──────────────┐ │
│ │ Piston API │ (External service - emkc.org) │
│ │ Sandbox │ │
│ └──────────────┘ │
│ │ │
│ │ { run: { output, stderr } } │
│ ▼ │
│ ┌──────────────┐ │
│ │ OutputPanel │ Display results │
│ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
Model: llama-3.3-70b-versatile
Client Initialization:
const groq = new Groq({
apiKey: process.env.GROQ_API_KEY
});- Temperature: 0.5
- Max Tokens: 1500
- Output: JSON with suggestions, issues, improvements
- Temperature: 0.3
- Max Tokens: 1000
- Output: Score, correctness, feedback, improvements
- Temperature: 0.5
- Max Tokens: 800
- Persona: "15 years experience in CS/IT"
- Refuses non-CS/IT questions
- Validation Step:
- Temperature: 0.1
- Validates topic is CS/IT related
- Generation Step:
- Temperature: 0.7
- Max Tokens: 1024
- Output: JSON with learning steps
- Temperature: 0.5
- Max Tokens: 100
- Response Format: JSON object
- Routes to pages or triggers actions
All AI integrations include:
- JSON response validation
- Markdown code block stripping
- Retry logic (typically 3 attempts)
- Error fallback responses
- Navigate to
/admin/login - Enter credentials (admin/admin123)
- POST to
/api/admin/auth - On success:
- Store Base64 credentials in cookie (
adminAuth) - Store in sessionStorage
- Redirect to
/admin
- Store Base64 credentials in cookie (
Statistics Display:
- Total Quests
- Active Quests
- Upcoming Quests
Quest Management:
- View all quests (sorted by creation date)
- Create new quests
- Edit existing quests
- Delete quests
Quest Fields:
- Name
- Time Limit (minutes)
- Level (beginner/intermediate/advanced)
- Start Time (datetime-local)
- End Time (auto-calculated)
- Active status (checkbox)
Question Fields:
- Type (short/coding)
- Title
- Description
- Points
- Test Cases (for coding questions)
getQuestStatus(quest) {
const now = new Date();
const startTime = new Date(quest.startTime);
const endTime = new Date(quest.endTime);
if (!quest.isActive) return "Inactive";
if (now < startTime) return "Upcoming";
if (now > endTime) return "Ended";
return "Active";
}Typography:
- Primary Font: Kanit (Google Fonts)
- Weights: 100-900
- Fallback: Inter, system fonts
Color Scheme (CSS Variables):
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
--primary: 240 5.9% 10%;
--secondary: 240 4.8% 95.9%;
--muted: 240 4.8% 95.9%;
--accent: 240 4.8% 95.9%;
--destructive: 0 84.2% 60.2%;
--border: 240 5.9% 90%;
--ring: 240 10% 3.9%;Dark Mode:
- Supported via CSS variables
- Toggle via
darkclass on root
Framer Motion Usage:
- Page transitions
- Loading animations
- Card hover effects
- Quest skeletons
CSS Animations:
fadeIn: Toast notificationsshimmer: Loading skeletonsgradient: Progress barsshine: Progress bar effects
Breakpoints:
- Mobile: < 768px (Sidebar collapses)
- Tablet: 768px - 1024px
- Desktop: > 1024px (Full sidebar)
Sidebar Behavior:
- Desktop: Expanded (56px collapsed / 224px expanded)
- Mobile: Collapsed by default
- Toggle button for manual control
Skeleton Loaders:
- Dashboard cards
- Quest list
- Roadmap cards
- Question list
- Video grid
Animated Loaders:
- Spinning circles
- Emoji animations (🎯, 📊, 📋)
- Progress dots
- Shimmer effects
Files:
/public/sounds/complete.mp3: Step completion/public/sounds/success.mp3: Roadmap completion
Usage:
useSoundhook fromuse-soundpackage- Triggered on roadmap step completion
- Uses
react-confetti - Triggered when completing all roadmap steps
- 15-second duration
- 400 pieces
- Responsive to window size
Guest Tour (1 step):
- Welcome message
- Points to "Get Started" button
User Tour (7 steps):
- Welcome back message
- Dashboard highlight
- Roadmaps highlight
- Learn highlight
- Playground highlight
- Dev Discuss highlight
- Quests highlight
-
Clerk Authentication:
- Industry-standard auth provider
- Session management
- CSRF protection
-
Webhook Verification:
- svix signature verification
- Prevents webhook spoofing
-
API Route Protection:
- Middleware checks Clerk auth
- Admin routes check credentials
-
Input Validation:
- Mongoose schema validation
- Required field enforcement
-
Hardcoded Admin Credentials
// middleware.js if (username !== "admin" || password !== "admin123")
Fix: Move to environment variables, use proper hashing
-
Exposed API Keys
// Client-side YouTube API key NEXT_PUBLIC_YOUTUBE_API_KEY
Fix: Proxy through server-side API route
-
No Rate Limiting:
- AI endpoints could be abused
- Fix: Implement rate limiting middleware
-
Missing Input Sanitization:
- XSS potential in question descriptions
- Fix: Sanitize HTML/markdown input
-
No CORS Configuration:
- API routes accessible from any origin
- Fix: Configure allowed origins
-
Add Request Logging:
- Track API usage patterns
- Detect abuse early
-
Implement Content Security Policy:
- Restrict resource loading
- Prevent XSS attacks
-
Add Session Timeout:
- Admin sessions don't expire
- Implement session expiry
┌─────────────────────────────────────────────────────────────────┐
│ USER REGISTRATION FLOW │
├─────────────────────────────────────────────────────────────────┤
│ │
│ User ────▶ /sign-up ────▶ Clerk UI ────▶ Clerk Backend │
│ │ │
│ │ │
│ ▼ │
│ Webhook: user.created │
│ │ │
│ ▼ │
│ /api/webhooks/clerk/route.js │
│ │ │
│ ▼ │
│ createOrUpdateUser() │
│ │ │
│ ▼ │
│ MongoDB: User document │
│ │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ LEARNING FLOW │
├─────────────────────────────────────────────────────────────────┤
│ │
│ /learn │
│ │ │
│ ├─── Fetch videos from YouTube API (freeCodeCamp, Telusko) │
│ │ │
│ ▼ │
│ Video Grid Display │
│ │ │
│ │ Click video │
│ ▼ │
│ /learn/[videoId] │
│ │ │
│ ├─── VideoPlayer (YouTube embed) │
│ │ │
│ └─── CodeWorkspace │
│ │ │
│ ├─── Write code in Monaco Editor │
│ ├─── Run code via Piston API │
│ └─── Get AI review via Groq │
│ │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ QUEST ATTEMPT FLOW │
├─────────────────────────────────────────────────────────────────┤
│ │
│ /quests │
│ │ │
│ │ Select active quest │
│ ▼ │
│ /quests/[questId]/attempt │
│ │ │
│ ├─── Check existing attempt │
│ │ │ │
│ │ ├─── If completed ──▶ Redirect to results │
│ │ └─── If none/in-progress ──▶ Show questions │
│ │ │
│ ├─── Timer countdown (quest.endTime - now) │
│ │ │
│ ├─── Fill in answers (short/code) │
│ │ │
│ └─── Submit │
│ │ │
│ ├─── POST /api/attempts (create) │
│ │ │
│ └─── POST /api/attempts/[id]/submit │
│ │ │
│ ├─── AI evaluation for each answer │
│ │ │
│ └─── Calculate total score │
│ │ │
│ ▼ │
│ /quests/[questId]/results/[attemptId] │
│ │ │
│ └─── Display scores, AI feedback, improvements │
│ │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ ROADMAP CREATION FLOW │
├─────────────────────────────────────────────────────────────────┤
│ │
│ /roadmaps │
│ │ │
│ │ Click "Create New Roadmap" │
│ ▼ │
│ Dialog Form │
│ │ │
│ ├─── Title: "My Python Journey" │
│ └─── Prompt: "Learn Python for data science" │
│ │ │
│ │ Submit │
│ ▼ │
│ createRoadmap() server action │
│ │ │
│ ├─── 1. Validate topic (Groq AI) │
│ │ └─── Reject if not CS/IT │
│ │ │
│ ├─── 2. Generate steps (Groq AI) │
│ │ └─── { steps: [{ topic, description, ... }] } │
│ │ │
│ ├─── 3. For each step: searchYouTubeVideo() │
│ │ └─── Attach videoId, duration │
│ │ │
│ └─── 4. Save to MongoDB │
│ │
│ /roadmaps/[id] │
│ │ │
│ ├─── Display steps with checkboxes │
│ ├─── Progress saved to localStorage │
│ ├─── Links to documentation & YouTube videos │
│ └─── Confetti on completion │
│ │
└─────────────────────────────────────────────────────────────────┘
npm run dev # Start development server
npm run build # Production build
npm start # Start production server
npm run lint # Run ESLint| Feature | Primary Files |
|---|---|
| Authentication | middleware.js, lib/actions/user.js, api/webhooks/clerk/ |
| Quests | lib/models/questModel.js, lib/actions/quest.js, app/quests/ |
| Roadmaps | lib/models/roadmapModel.js, lib/actions/roadmap.js, app/roadmaps/ |
| Learning | components/learn/, app/learn/, api/video-search/ |
| Playground | lib/pusher*.js, pages/api/socket.js, app/playground/ |
| Dev Discuss | lib/models/questionModel.js, lib/actions/question.js, app/dev-discuss/ |
| Admin | lib/middleware/adminAuth.js, app/admin/, api/admin/ |
| Code Execution | app/api/Piston/api.js, app/constants.js |
| AI Integration | lib/actions/codeReview.js, lib/actions/quest.js, lib/actions/roadmap.js |
| Collection | Model File | Primary Purpose |
|---|---|---|
users |
userModel.js |
User profiles from Clerk |
quests |
questModel.js |
Coding challenges |
attempts |
attemptModel.js |
Quest attempt records |
questions |
questionModel.js |
Dev discuss posts |
roadmaps |
roadmapModel.js |
Learning paths |
| Service | Purpose | Required For |
|---|---|---|
| Clerk | Authentication | User login/signup |
| MongoDB Atlas | Database | All data storage |
| Pusher | Real-time | Playground collaboration |
| Groq AI | LLM | AI features |
| YouTube Data API | Video search | Learn & Roadmaps |
| Piston | Code execution | Running user code |
Documentation generated: January 2026 Version: 1.0 Codebase analyzed: inherit @ latest