How sanidhyy/duolingo-clone works
Project Type and Purpose
• Full‑stack Next.js web application (app router) for interactive language learning, with user‑facing “main” and “marketing” sections, a “lesson” area, and a built‑in admin console.
• Features: course browsing, lessons with quizzes/challenges, user progress tracking (quests, leaderboard), a shop (Stripe payments), and administrative CRUD for courses, units, lessons, challenges.
File Structure
• Top‑level “app” directory holds all Next.js routes:
• (main) – user‑facing learning flows
• (marketing) – landing pages
• lesson – deep dive pages (quizzes, headers, footers)
• admin – react‑admin or custom CRUD UI
• api – RESTful endpoints (courses, lessons, challenges, units, Stripe webhooks)
• “db” folder with Drizzle‑ORM schema, queries, config.
• “lib” for utility wrappers (Clerk auth, Stripe client).
• “store” for client state (Zustand).
• “components” and “components/ui” for shared UI.
• “scripts” for seeding/migrations, “actions” for server actions.
• Config files: .env, Clerk & Stripe secrets, next.config.mjs, Tailwind.
README for Additional Insights
• Uses Clerk for authentication/authorization (NEXT_PUBLIC_CLERK_*, CLERK_SECRET_KEY).
• PostgreSQL (Neon) via Drizzle‑ORM.
• Stripe for payments and webhooks.
• Hosted on Vercel.
• Admin IDs stored in env to gate admin UI.
Main Components & Their Interactions
a. Client (Browser/Mobile)
• React/Next.js UI, Tailwind CSS, Zustand state, Sonner notifications.
• Two UI spheres: “Marketing” (static pages) and “Main” (authenticated learning).
• Admin UI under /admin (React‑Admin or custom).
b. Next.js Server
• App Router handles SSR/SSG, Server Actions (in “actions/”), API Routes under app/api/*.
• Auth middleware (Clerk).
• Business logic in lib/ and config/.
c. Database
• PostgreSQL (Neon) with Drizzle‑ORM: tables for users, courses, units, lessons, challenges, options, progress, subscriptions.
d. External Services
• Clerk (Auth): token validation, user metadata, admin ID checks.
• Stripe (Payments): checkout sessions, webhooks to app/api/webhooks/stripe/route.ts.
e. CI/CD
• GitHub Actions (folder .github/workflows) for tests, lint, deploy to Vercel.
• Vercel for hosting front‑ and back‑end.
Architectural Patterns & Design Principles
• Next.js App Router (directory‑based routing; server vs. client components).
• RESTful API endpoints for each domain entity.
• Single codebase for frontend, backend, and admin console (monorepo‑style).
• Separation of concerns:
• UI components vs. page (route) components
• Server logic (API) vs. client logic (hooks/store)
• Domain modules (db schema, queries) vs. orchestration (Next.js routes)
• Drizzle‑ORM for type‑safe DB access.
• Zustand for lightweight global state (modals, progress).
Be Detailed but Structured
• Group related routes (e.g., all /api/courses/* endpoints).
• Annotate key technologies next to each component (e.g., “Next.js 14 App Router, TypeScript, Tailwind”).
• Highlight the serverless nature of API routes (Vercel Functions).
• Call out the real‑time/reactive UX (Zustand store, Sonner notifications, progress updates).