# developertharan/udemy-clone architecture

> Architecture diagram of the GitHub repository developertharan/udemy-clone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/developertharan/udemy-clone
- Repository: https://github.com/developertharan/udemy-clone

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    BROWSER["User Browser"]:::external

    %% Frontend Layer
    subgraph "Frontend (Next.js)"
        AUTH["Auth Routes"]:::frontend
        COURSE["Course Routes"]:::frontend
        MAIN["Main Routes"]:::frontend
        COMPONENTS["UI Components"]:::frontend
        COMPONENTS --> HEADER["MainHeader"]:::frontend
        COMPONENTS --> FOOTER["Footer"]:::frontend
        COMPONENTS --> VIDEOPLAYER["VideoPlayer"]:::frontend
        PROVIDERS["Global Providers & Context"]:::frontend
        PROVIDERS --> FORM["Form Provider"]:::frontend
        PROVIDERS --> THEME["Theme Provider"]:::frontend
        PROVIDERS --> UI["UI Provider"]:::frontend
        PROVIDERS --> USERCTX["User Context"]:::frontend
    end

    %% Backend/API Layer
    subgraph "Backend (API Endpoints)"
        COURSEAPI["Course API"]:::backend
        USERAPI["User Data API"]:::backend
        subgraph "Webhooks API"
            CLERK["Clerk Webhook"]:::backend
            STRIPEW["Stripe Webhook"]:::backend
        end
        UPLOADAPI["File Upload API"]:::backend
    end

    %% Supporting Database
    DB["Database (PostgreSQL via Prisma)"]:::database

    %% External Services and Integrations
    subgraph "External Services"
        CLERK_EXT["Authentication (Clerk)"]:::external
        STRIPE_EXT["Payment Processing (Stripe)"]:::external
        UPLOAD_EXT["Uploadthing Service"]:::external
    end

    %% Connections from Browser to Frontend
    BROWSER -->|"access"| AUTH
    BROWSER -->|"access"| COURSE
    BROWSER -->|"access"| MAIN

    %% Frontend to Backend API
    AUTH -->|"HTTP"| USERAPI
    COURSE -->|"HTTP"| COURSEAPI
    MAIN -->|"HTTP"| COURSEAPI

    %% Backend API to Database
    COURSEAPI -->|"PRISMA"| DB
    USERAPI -->|"PRISMA"| DB

    %% Backend API to External Services
    COURSEAPI -->|"Stripe"| STRIPE_EXT
    COURSEAPI -->|"UploadFile"| UPLOAD_EXT
    UPLOADAPI -->|"FileUpload"| UPLOAD_EXT

    %% Webhook connections
    CLERK -->|"Webhook"| CLERK_EXT
    STRIPEW -->|"Webhook"| STRIPE_EXT

    %% Styling Classes
    classDef frontend fill:#ACE1AF,stroke:#1B5E20,stroke-width:2px;
    classDef backend fill:#FFD59A,stroke:#E65100,stroke-width:2px;
    classDef database fill:#A8DADC,stroke:#1D3557,stroke-width:2px;
    classDef external fill:#F1FAEE,stroke:#457B9D,stroke-width:2px;

    %% Click Events for Frontend UI Layer
    click AUTH "https://github.com/developertharan/udemy-clone/tree/main/app/(auth)"
    click COURSE "https://github.com/developertharan/udemy-clone/tree/main/app/(course)"
    click MAIN "https://github.com/developertharan/udemy-clone/tree/main/app/(main)"
    click HEADER "https://github.com/developertharan/udemy-clone/blob/main/components/MainHeader.tsx"
    click FOOTER "https://github.com/developertharan/udemy-clone/blob/main/components/Footer.tsx"
    click VIDEOPLAYER "https://github.com/developertharan/udemy-clone/blob/main/components/videoplayer/VideoPlayer.tsx"
    click FORM "https://github.com/developertharan/udemy-clone/blob/main/provider/form-provider.tsx"
    click THEME "https://github.com/developertharan/udemy-clone/blob/main/provider/theme-provider.tsx"
    click UI "https://github.com/developertharan/udemy-clone/blob/main/provider/ui-provider.tsx"
    click USERCTX "https://github.com/developertharan/udemy-clone/blob/main/context/userContext.tsx"

    %% Click Events for Backend/API Layer
    click COURSEAPI "https://github.com/developertharan/udemy-clone/tree/main/app/api/courses"
    click USERAPI "https://github.com/developertharan/udemy-clone/tree/main/app/api/userdata"
    click UPLOADAPI "https://github.com/developertharan/udemy-clone/tree/main/app/api/uploadthing"
    click CLERK "https://github.com/developertharan/udemy-clone/tree/main/app/api/webhooks/clerk"
    click STRIPEW "https://github.com/developertharan/udemy-clone/tree/main/app/api/webhooks/stripe"

    %% Click Events for External Services
    click CLERK_EXT "https://github.com/developertharan/udemy-clone/tree/main/app/api/webhooks/clerk"
    click STRIPE_EXT "https://github.com/developertharan/udemy-clone/blob/main/lib/stripe.ts"
    click UPLOAD_EXT "https://github.com/developertharan/udemy-clone/tree/main/app/api/uploadthing"

    %% Click Event for Database
    click DB "https://github.com/developertharan/udemy-clone/blob/main/prisma/schema.prisma"
```
