# vaishnav-3/ai-project architecture

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

- Interactive diagram: https://gitdiagram.com/vaishnav-3/ai-project
- Repository: https://github.com/vaishnav-3/ai-project

## Overview

##### Main Components
- Frontend (Next.js App Router): This includes the “app” directory where pages, UI components, and layouts reside. Notice separate subdirectories such as:
- (auth): Containing sign-in/sign-up pages (authentication flows with Clerk).
- course/[courseId]: Dynamic routing for individual course pages with nested components (flashcards, notes, Q&A, quizzes).
- create and dashboard: For course creation and user-specific dashboards.
- API Endpoints within “app/api”: Contains endpoints to handle course generation, user creation, study type content generation, etc.
- Background Tasks and Orchestration (Inngest):
- Separate Inngest files (inngest/client.js and inngest/functions.js) and related API endpoints trigger backend functions for asynchronous operations, such as generating notes or study-type content.
- Database and Configuration:
- The “configs” folder holds files for AI models (using Google Gemini), database connection (db.js) and schema definitions (schema.js).
- Drizzle ORM setup (drizzle.config.js and SQL migration files in “drizzle”).
- External Services:
- Clerk for authentication.
- Google Gemini for AI content generation.
- Neon Serverless PostgreSQL for database hosting.

##### Relationships and Interactions
- User Interaction Flow:
- Users authenticate via Clerk on the frontend (pages under app/(auth)).
- Authenticated users interact with dashboards and course pages.
- API and Background Workflow:
- When users initiate actions (e.g., generating a course outline or study materials), the client calls corresponding API endpoints (in “app/api/...”).
- The API endpoints trigger background tasks via Inngest functions (e.g., GenerateNotes, GenerateStudyTypeContent) and update the course state in the database.
- Database Operations:
- API endpoints and Inngest tasks interact with the Neon PostgreSQL database through Drizzle ORM (configured in configs/db.js and schema.js).

##### Architectural Patterns/Design Principles
- Separation of Concerns: Frontend components are separated from backend API logic, and asynchronous tasks are offloaded to Inngest.
- Modular Design: Each service (authentication, content generation, study material rendering) is encapsulated in its own module or API route.
- Dynamic Routing: Next.js dynamic routing for courses (course/[courseId]) allows for individual course pages.
- Asynchronous Processing: Background task orchestration via Inngest ensures that AI content generation and database updates are processed in a decoupled manner.

##### Relevant Technologies
- Frontend: Next.js, React, Tailwind CSS, client-side UI libraries.
- Backend/API: Node.js, Next.js API Routes.
- Authentication: Clerk.
- Background Tasks: Inngest.
- Database: Neon PostgreSQL with Drizzle ORM.
- AI Service: Google Gemini.
- Additional scripts or configuration from package.json, jest.config.js, etc., that support the build and testing process.

##### Specific Elements
- Frontend: App Router with subdirectories (auth, course, dashboard, create).
- API Endpoints: /api/courses, /api/generate-course-outline, /api/create-user, /api/study-type, /api/study-type-content.
- Inngest Service: Functions like GenerateNotes and GenerateStudyTypeContent.
- Configuration and Database modules (configs, drizzle).
- External Services: Clerk, Google Gemini, Neon PostgreSQL.
- Client → API → Inngest functions.
- Inngest functions → Database.
- API → External Services (if directly involved).
- That all dependencies (e.g., the use of Drizzle ORM, integration with Clerk) are clearly marked.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Next.js App Router)"
        A1["Authentication Sign-In (app/(auth)/sign-in)"]:::frontend
        A2["Authentication Sign-Up (app/(auth)/sign-up)"]:::frontend
        F1["Course Pages (app/course/[courseId])"]:::frontend
        F2["Course Components: Flashcards, Notes, Q&A, Quiz (app/course/[courseId])"]:::frontend
        F3["Course Creation (app/create)"]:::frontend
        F4["User Dashboard (app/dashboard)"]:::frontend
    end

    %% Backend/API Layer
    subgraph "Backend/API Endpoints"
        B1["Courses Endpoint (app/api/courses/route.js)"]:::backend
        B2["Create-User Endpoint (app/api/create-user/route.js)"]:::backend
        B3["Generate Course Outline Endpoint (app/api/generate-course-outline/route.js)"]:::backend
        B4["Study-Type Endpoint (app/api/study-type/route.jsx)"]:::backend
        B5["Study-Type Content Endpoint (app/api/study-type-content/route.jsx)"]:::backend
        B6["Inngest Trigger Endpoint (app/api/inngest/route.js)"]:::backend
    end

    %% Inngest Background Tasks
    subgraph "Inngest Background Tasks"
        I1["Inngest Client Config (ingnest/client.js)"]:::orchestration
        I2["Inngest Functions (ingnest/functions.js)"]:::orchestration
    end

    %% Database and Configuration
    subgraph "Database/Config"
        D1["Database Connection (configs/db.js)"]:::database
        D2["Database Schema (configs/schema.js)"]:::database
        D3["Drizzle ORM Config (drizzle.config.js)"]:::database
        D4["Drizzle Migrations (drizzle/)"]:::database
        C1["AI Model Config (configs/AiModel.js)"]:::config
        C2["Service Config (configs/service.js)"]:::config
    end

    %% External Services
    subgraph "External Services"
        E1["Authentication (Clerk)"]:::external
        E2["AI Service (Google Gemini)"]:::external
        E3["Neon PostgreSQL"]:::external
    end

    %% Relationships

    %% User authentication flows
    A1 -->|"uses"| E1
    A2 -->|"uses"| E1

    %% Frontend calls API endpoints
    F1 -->|"calls"| B1
    F1 -->|"calls"| B3
    F3 -->|"calls"| B2
    F4 -->|"calls"| B1

    %% API endpoints triggering Inngest background tasks
    B3 -->|"triggers"| I2
    B6 -->|"triggers"| I2

    %% API endpoints interacting with the database
    B1 -->|"reads/writes"| D1
    B1 -->|"reads/writes"| D2
    B2 -->|"writes"| D1
    B3 -->|"reads/writes"| D1
    B4 -->|"reads/writes"| D1
    B5 -->|"reads/writes"| D1

    %% Inngest functions interacting with the database and AI service
    I2 -->|"updates"| D1
    I2 -->|"calls"| E2

    %% Database configuration and hosting
    D1 -->|"configuredBy"| D3
    D1 -->|"migrations"| D4
    D1 -->|"hostedOn"| E3

    %% Frontend and API using configuration files
    F1 -->|"loads"| C1
    B3 -->|"uses"| C2

    %% Styling Classes
    classDef frontend fill:#DEF,stroke:#000,stroke-width:1px;
    classDef backend fill:#FED,stroke:#000,stroke-width:1px;
    classDef orchestration fill:#DDF,stroke:#000,stroke-width:1px;
    classDef database fill:#FDD,stroke:#000,stroke-width:1px;
    classDef config fill:#DFD,stroke:#000,stroke-width:1px;
    classDef external fill:#FFD,stroke:#000,stroke-width:1px;

    %% Click Events
    click A1 "https://github.com/vaishnav-3/ai-project/tree/main/app/(auth)/sign-in"
    click A2 "https://github.com/vaishnav-3/ai-project/tree/main/app/(auth)/sign-up"
    click F1 "https://github.com/vaishnav-3/ai-project/tree/main/app/course/[courseId]"
    click F3 "https://github.com/vaishnav-3/ai-project/tree/main/app/create"
    click F4 "https://github.com/vaishnav-3/ai-project/tree/main/app/dashboard"
    click B1 "https://github.com/vaishnav-3/ai-project/blob/main/app/api/courses/route.js"
    click B2 "https://github.com/vaishnav-3/ai-project/blob/main/app/api/create-user/route.js"
    click B3 "https://github.com/vaishnav-3/ai-project/blob/main/app/api/generate-course-outline/route.js"
    click B4 "https://github.com/vaishnav-3/ai-project/blob/main/app/api/study-type/route.jsx"
    click B5 "https://github.com/vaishnav-3/ai-project/blob/main/app/api/study-type-content/route.jsx"
    click B6 "https://github.com/vaishnav-3/ai-project/blob/main/app/api/inngest/route.js"
    click I1 "https://github.com/vaishnav-3/ai-project/blob/main/ingnest/client.js"
    click I2 "https://github.com/vaishnav-3/ai-project/blob/main/ingnest/functions.js"
    click D1 "https://github.com/vaishnav-3/ai-project/blob/main/configs/db.js"
    click D2 "https://github.com/vaishnav-3/ai-project/blob/main/configs/schema.js"
    click D3 "https://github.com/vaishnav-3/ai-project/blob/main/drizzle.config.js"
    click D4 "https://github.com/vaishnav-3/ai-project/tree/main/drizzle/"
    click C1 "https://github.com/vaishnav-3/ai-project/blob/main/configs/AiModel.js"
    click C2 "https://github.com/vaishnav-3/ai-project/blob/main/configs/service.js"
```
