How druvkotwani/leetcode-profiles works
Project Type and Purpose
• This is a full-stack web application built on Next.js (React + Node) that lets users fetch and display their LeetCode statistics.
• The “client” folder houses both the frontend (UI) and backend (API routes and cron job) via Next.js’s hybrid routing. Data is stored in MongoDB and the entire app is deployed on Vercel.
Main Components
a. Frontend (Next.js “app” & “pages” folders)
– React components (Card, Heatmap, Navbar, etc.)
– Pages and Routes:
• Public UI pages: Home, Worth, Admin sync page
• DataContext wrapper for app-wide state
b. Backend (Next.js API routes + Cron)
– API endpoints under client/src/pages/api and client/src/app/api/cron
• fetchdata, add, syncProfile, syncAllProfiles
• Cron scheduler route (/api/cron) for periodic profile syncs
– Database layer:
• lib/mongodb.js (connection)
• models/userdata.ts (data schema)
c. Database
– MongoDB Atlas (hosted externally)
d. External Service
– LeetCode platform (data source)
e. Hosting/Deployment
– Vercel platform (Serverless functions + static hosting)
Relationships & Data Flows
• User → Frontend UI → Internal API endpoints → MongoDB
• Cron service (serverless function invoked on schedule) → sync endpoints → fetch from LeetCode → update MongoDB
• Frontend pages fetch stored data via client-side calls to API or via Next.js Server Side Rendering/Static Generation
• All serverless API functions run on Vercel Lambdas
Architectural Patterns & Principles
• Component-based UI (React + Tailwind CSS)
• Hybrid routing (Next.js App Router + Pages Router for legacy APIs)
• Serverless functions for backend logic (Next.js API routes)
• Scheduled jobs modeled as HTTP-triggered cron functions
• Single repository monorepo for both frontend and backend
Essential Elements to Capture
– React UI components (Card, Heatmap, etc.) served by Next.js
– Next.js App Router vs Pages Router for API vs UI
– MongoDB connection (lib/mongodb.js) and schema (models/userdata.ts)
– Cron endpoint under /app/api/cron/route.ts
– External data source (LeetCode) with scrape/fetch logic
– Deployment on Vercel (serverless hosting)