# ghost-vedant/gurukul architecture

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

- Interactive diagram: https://gitdiagram.com/ghost-vedant/gurukul
- Repository: https://github.com/ghost-vedant/gurukul

## Overview

##### Main Components
- Next.js Frontend: Represent the pages and UI components found in the "src/app" directory. This includes pages for routes like about, addnewcourse, courses, categories, profile, and error handling.
- API Endpoints: Mark the API routes under "src/app/api". Highlight the endpoints such as authentication ([...nextauth]), classroom, comments, course creation, course purchase (which include dynamic segments like [courseId]), order processing, registration, and testimonials. These endpoints represent the backend services that handle data requests.
- Business Logic/Actions: Identify the "src/actions" folder where key functions (e.g., assessment, auth, aws, purchase, user progress) reside. They encapsulate the application's core business logic that coordinate with the API endpoints.
- Database Integration: Display the "prisma" directory with its Prisma schema. This is the ORM layer used for interacting with the database, and you may also indicate how API endpoints use this layer via utilities in "src/lib/prisma.ts".
- State Management: Illustrate the "src/recoil" directory which includes Recoil atoms managing user sessions, popups, and login status.
- Custom Hooks and Utility Libraries: Indicate the “src/Custom_hooks” and utility scripts in "src/lib" (such as awsUtil, token management, bcrypt, zod, etc.) which serve to provide common functionality throughout the project.
- UI Components & Design: Highlight organized UI component directories ("src/components/ui", "src/components/cards", "src/components/navbar", "src/components/popups") which are essential for building the interactive interface.
- Middleware & Configurations: Show global middleware (middleware.ts files both at root and under src), configuration files (next.config.mjs, tailwind.config.ts, tsconfig.json, postcss.config.mjs), and environment settings (like auth.ts for next-auth integration).

##### Relationships and Interactions
- That the API endpoints call the business logic in "src/actions" and interact with the database through Prisma (from the "prisma" folder and "src/lib/prisma.ts").
- Custom hooks and utility functions to both the frontend components and API logic to underline shared functionality.

##### Architectural Patterns and Design Principles
- File-based Routing: Explain the Next.js routing mechanism, with pages and API routes defined based on the file system structure under "src/app".
- Separation of Concerns: Emphasize how the project cleanly separates API logic, UI components, business logic (actions), state management (Recoil), and utility layers.
- Modular Architecture: The granularity in the "src" folder (actions, components, lib, and recoil) indicates a design that favors reusability and modularity.
- Integration with External Services: Note components that handle authentication (using NextAuth, visible in auth.ts and API route [...nextauth]), payment (Razorpay), and external file storage or computational operations (AWS).

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User (Browser)"]:::external

    subgraph "Frontend Layer"
        NextPages["Next.js Pages"]:::frontend
        UIComponents["UI Components"]:::frontend
    end

    subgraph "State Management"
        Recoil["Recoil Atoms"]:::state
    end

    subgraph "Backend Layer"
        APIEndpoints["API Endpoints"]:::backend
        BusinessLogic["Business Logic: Actions"]:::backend
    end

    subgraph "Database Integration"
        PrismaSchema["Prisma Schema"]:::db
        PrismaUtil["Prisma Client Util"]:::db
    end

    subgraph "Shared Utilities"
        CustomHooks["Custom Hooks"]:::utility
        UtilityLibs["Utility Libraries"]:::utility
    end

    Configs["Middleware & Configurations"]:::config
    External["AWS & Razorpay Integration"]:::external

    %% Data Flow
    User -->|"requests"| NextPages
    NextPages -->|"renders"| UIComponents
    NextPages -->|"calls"| APIEndpoints
    NextPages -->|"uses"| CustomHooks
    NextPages -->|"uses"| UtilityLibs
    UIComponents -->|"bindsTo"| Recoil
    APIEndpoints -->|"invokes"| BusinessLogic
    BusinessLogic -->|"queries"| PrismaSchema
    BusinessLogic -->|"queries"| PrismaUtil
    BusinessLogic -->|"integratesWith"| External
    UtilityLibs -->|"assists"| BusinessLogic
    CustomHooks -->|"assists"| UIComponents
    Configs -->|"appliesTo"| NextPages
    Configs -->|"appliesTo"| APIEndpoints

    %% Click Events
    click NextPages "https://github.com/ghost-vedant/gurukul/tree/main/src/app"
    click APIEndpoints "https://github.com/ghost-vedant/gurukul/tree/main/src/app/api"
    click BusinessLogic "https://github.com/ghost-vedant/gurukul/tree/main/src/actions"
    click PrismaSchema "https://github.com/ghost-vedant/gurukul/blob/main/prisma/schema.prisma"
    click PrismaUtil "https://github.com/ghost-vedant/gurukul/blob/main/src/lib/prisma.ts"
    click Recoil "https://github.com/ghost-vedant/gurukul/tree/main/src/recoil"
    click CustomHooks "https://github.com/ghost-vedant/gurukul/tree/main/src/Custom_hooks"
    click UtilityLibs "https://github.com/ghost-vedant/gurukul/tree/main/src/lib"
    click UIComponents "https://github.com/ghost-vedant/gurukul/tree/main/src/components"
    click Configs "https://github.com/ghost-vedant/gurukul/blob/main/middleware.ts"

    %% Class Definitions for Colors
    classDef frontend fill:#e0f7fa, stroke:#006064, stroke-width:2px;
    classDef backend fill:#ffecb3, stroke:#ff9800, stroke-width:2px;
    classDef db fill:#d1c4e9, stroke:#673ab7, stroke-width:2px;
    classDef state fill:#c8e6c9, stroke:#2e7d32, stroke-width:2px;
    classDef utility fill:#ffcdd2, stroke:#e57373, stroke-width:2px;
    classDef config fill:#eeeeee, stroke:#9e9e9e, stroke-width:2px;
    classDef external fill:#fff9c4, stroke:#fbc02d, stroke-width:2px;
```
