# mr-green1337/thoth architecture

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

- Interactive diagram: https://gitdiagram.com/mr-green1337/thoth
- Repository: https://github.com/mr-green1337/thoth

## Overview

##### Main Components
a. Frontend/UI Layer:
- The application’s client-side is built with Next.js. The UI components are located in folders such as src/app (with subdirectories for pages like (auth), (dashboard), and various course-related pages) and src/components (which holds reusable UI components, global components, and providers). This represents the view and interaction layer.
b. API / Backend Layer:
- The Next.js API routes are found in src/app/api. These endpoints handle authentication, course management (including course forking, publishing, generating AI responses, etc.), user preferences, and other server-side logic.
- The src/app/actions folder contains helper functions to support these API routes (e.g., for authentication, generating suggestions, etc.).
c. Database Layer:
- The prisma directory with schema.prisma and migration folders defines the ORM and database schema. This layer is responsible for persisting data.
d. External/Populator Script:
- The populate_db_atlas folder holds a Python script (main.py) and associated configuration to populate the database. This illustrates a separate process for managing initial database state or data migrations.
e. Utilities & Shared Code:
- The src/lib folder contains utility functions (including auth, prisma connections, and other helpers).
- The src/hooks and src/types directories include custom hooks and TypeScript definitions that help maintain strong typing and behavior consistency throughout the project.

##### Component Interactions
- The Client (rendered via Next.js frontend) interacts with the API endpoints using HTTP requests. API endpoints handle business logic, manipulate data (using interactions defined in src/actions and src/lib), and respond accordingly.
- The API routes leverage Prisma to communicate with the underlying database.
- The database is subject to schema definitions and migrations stored under the prisma folder.
- The Python (populate_db_atlas/main.py) script can be depicted as an external tool/script that interacts with the same database, ensuring it is seeded or maintained separately.
- UI components interact with the API layer via calls handled within the Next.js framework, with real-time updates provided by components and hooks (e.g., use-debounce, use-toast).

##### Architectural Patterns & Technologies
- Next.js 13 with App Router is central, distinguishing the separation between UI pages and API routes.
- Server-Side Rendering (SSR) or Static Site Generation (SSG) are implied for page rendering.
- RESTful API endpoints are created in the src/app/api folder.
- Prisma acts as an ORM to abstract database access and enforce a schema-driven design.
- The project also demonstrates component-driven design by modularizing components (e.g., auth components, global components, UI libraries).
- TailwindCSS (configured via tailwind.config.ts) and Next.js font optimization (using next/font) are also part of the tech stack.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend/UI Layer
    subgraph "Frontend (Next.js UI)"
        UI1["Next.js Frontend (Pages & Views)"]:::frontend
        UI2["Reusable UI Component: UI"]:::frontend
        UI3["Reusable UI Component: Global"]:::frontend
        UI4["Reusable UI Component: Auth"]:::frontend
        UI5["Reusable UI Component: Providers"]:::frontend
    end

    %% Backend/API Layer
    subgraph "Backend/API (Next.js Server)"
        API1["API Endpoints (src/app/api)"]:::backend
        API2["Helper Functions (src/app/actions)"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB1["Prisma ORM (schema.prisma)"]:::database
        DB2["Prisma Migrations (migrations)"]:::database
    end

    %% External DB Populator Script
    subgraph "External Script"
        EX["DB Populator (Python)"]:::external
    end

    %% Utilities & Shared Code
    subgraph "Utilities & Shared Code"
        UTL1["Utility Functions (src/lib)"]:::utilities
        UTL2["Custom Hooks (src/hooks)"]:::utilities
        UTL3["TS Definitions (src/types)"]:::utilities
    end

    %% Relationships: Frontend interactions
    UI1 -->|"HTTPRequests"| API1
    UI1 ---|"integrates"| UI2
    UI1 ---|"integrates"| UI3
    UI1 ---|"integrates"| UI4
    UI1 ---|"integrates"| UI5
    UI1 -->|"utilizes"| UTL1
    UI1 -->|"utilizes"| UTL2
    UI1 -->|"utilizes"| UTL3

    %% Relationships: API interactions
    API1 -->|"invokes"| API2
    API1 -->|"data-access"| DB1
    API1 -->|"data-access"| DB2
    API1 -->|"uses"| UTL1

    %% Relationships: External script
    EX -->|"seeds"| DB1
    EX -->|"seeds"| DB2

    %% Relationships: Helper functions interaction with DB
    API2 -->|"manipulates"| DB1
    API2 -->|"manipulates"| DB2

    %% Class definitions for colors
    classDef frontend fill:#a4d4ff,stroke:#000,stroke-width:1px;
    classDef backend fill:#caffbf,stroke:#000,stroke-width:1px;
    classDef database fill:#ffadad,stroke:#000,stroke-width:1px;
    classDef external fill:#ffd6a5,stroke:#000,stroke-width:1px;
    classDef utilities fill:#d0afff,stroke:#000,stroke-width:1px;

    %% Click Events
    click UI1 "https://github.com/mr-green1337/thoth/tree/main/src/app/(pages)"
    click UI2 "https://github.com/mr-green1337/thoth/tree/main/src/components/ui"
    click UI3 "https://github.com/mr-green1337/thoth/tree/main/src/components/global"
    click UI4 "https://github.com/mr-green1337/thoth/tree/main/src/components/auth"
    click UI5 "https://github.com/mr-green1337/thoth/tree/main/src/components/providers"
    click API1 "https://github.com/mr-green1337/thoth/tree/main/src/app/api"
    click API2 "https://github.com/mr-green1337/thoth/tree/main/src/app/actions"
    click DB1 "https://github.com/mr-green1337/thoth/blob/main/prisma/schema.prisma"
    click DB2 "https://github.com/mr-green1337/thoth/tree/main/prisma/migrations"
    click EX "https://github.com/mr-green1337/thoth/blob/main/populate_db_atlas/main.py"
    click UTL1 "https://github.com/mr-green1337/thoth/tree/main/src/lib"
    click UTL2 "https://github.com/mr-green1337/thoth/tree/main/src/hooks"
    click UTL3 "https://github.com/mr-green1337/thoth/tree/main/src/types"
```
