How developertharan/udemy-clone works
Project Type and Purpose
• The project is a full-stack web application that clones Udemy’s core functionality.
• It focuses on role-based authentication (using Clerk), managing courses (with chapters, attachments, etc.), and secure payment processing (with Stripe).
• The tech stack includes Next.js 14 for the frontend and server-side rendering, Tailwind CSS for styling, Prisma ORM for PostgreSQL connectivity, and integration with external services like Stripe and Clerk.
File Structure
• The “app” directory is central and follows the new Next.js app router style. It contains separate folders for different parts of the website:
• (auth) for sign-in and sign-up pages
• (course) for course-related views and components
• (main) with nested routes for student and teacher dashboards, settings, and course listings along with dynamic routes (e.g., [courseId], [chapterId])
• The “app/api” directory contains various RESTful or Next.js API endpoints that handle operations for courses (CRUD, publish/unpublish, checkout, and search), user data, and webhooks for external integrations.
• Other directories like “components”, “provider”, “context”, “lib”, and “utils” host reusable UI components, global providers (theme/form/UI), context management, database and utility functions, as well as integrations such as Stripe.
• The “prisma” folder includes the schema and seed data for the database, indicating PostgreSQL is used via Prisma.
• The repository also includes typical configuration files such as “next.config.js”, “tsconfig.json”, and styles (“globals.css”, “tailwind.config.ts”).
Main Components
• Frontend UI Layer:
• Next.js pages inside the “app” directory (e.g., routes for authentication, course details, teacher/student dashboards)
• Components (e.g., MainHeader, Footer, Carousel, Table, VideoPlayer)
• Provider/context for theming, forms, and user state.
• Backend/API Layer:
• API routes in “app/api” handling courses (CRUD operations, attachments, chapters), user data, and webhooks.
• Separate endpoints to manage payment processing (through Stripe) and file uploads (using uploadthing).
• Database:
• The PostgreSQL database accessed via Prisma (from “lib/db.ts” and “prisma/schema.prisma”).
• External Services and Integrations:
• Authentication system (Clerk) as configured via environment variables.
• Payment processing (Stripe integration) with corresponding API endpoints and webhooks.
• File upload service integration.
Relationships and Interactions
• The frontend interacts with the backend API layer through HTTP requests for course operations, authentication, and payment processing.
• External services (Clerk and Stripe) are integrated with the backend:
• The “provider” and “context” layers in the frontend ensure that state (e.g., user session details and theming) is accessible application-wide.
Architectural Patterns and Design Principles
• Separation of Concerns: Distinct separation between presentation (pages/components), business logic (API endpoints), and data access (Prisma DB routines).
• Server-Side Rendering (SSR) and Static Rendering: Utilize Next.js rendering paradigm to improve performance.
• API-First Approach: Well-defined API endpoints for courses, authentication, and payments.
• Role-Based Access Control: Different interfaces and API endpoints based on user roles (student, teacher, admin) as indicated in the route directories.
• At the top, start with the user’s browser accessing the Next.js client.
• Below the backend, show the supporting database (PostgreSQL via Prisma) and the external services.
• Role-based routes in the “app/(auth)”, “app/(main)/(routes)/teacher”, “student” sections by grouping them under “Authentication & Role-Specific Interfaces”.
• Clearly separate the frontend (Next.js app structure) from the backend (API endpoints).
• Key integrations with external services (Stripe, Clerk, uploadthing).
• Major interactions such as authentication flow, course management, file uploads, and database connectivity.