# mecha-aima/teachlm architecture

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

- Interactive diagram: https://gitdiagram.com/mecha-aima/teachlm
- Repository: https://github.com/mecha-aima/teachlm

## Overview

##### Project type and purpose
- This is a full-stack, server-rendered e-learning web application (“teachLM”) built with Next.js (App Router), React, and TypeScript.
- It connects students with teachers, manages lessons, subscriptions, authentication, and AI-powered features.

##### File structure
- Top-level “app/” directory holds all route handlers/pages (Next.js App Router).
- “components/” holds reusable UI components, organized further into “ui/” primitives.
- “lib/actions/” contains server actions for business logic (lesson.actions.ts, teacher.actions.ts).
- “lib/supabase.ts” is the database client.
- “instrumentation.ts” and sentry.{edge,server}.config.ts configure Sentry for error monitoring.
- “middleware.ts” applies Clerk authentication at edge.
- “constants/”, “public/” and “types/” support static assets, JSON data, and TypeScript definitions.
- Config files (next.config.ts, tsconfig.json, postcss.config.mjs, etc.) handle build/deploy settings.

##### README insights
- Tech stack includes Next.js/Turbopack, Clerk for auth, Supabase for DB, React Hook Form & Zod for forms, Vapi AI for voice AI, Tailwind+shadcn/ui for styling, and Sentry for monitoring.
- Data flow: UI → server actions → Supabase; authentication via Clerk middleware/components; Vercel deploy.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Browser (User)"]:::external
        NextFrontend["Next.js Frontend\n(app/)"]:::internal
        UIComponents["UI Components\n(components/)"]:::internal
        UIPrimitives["UI Primitives\n(components/ui/)"]:::internal
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        VercelEdge["Vercel Edge\n(Hosting/CDN)"]:::external
        NextServer["Next.js Server\n(Server Components)"]:::internal
        Middleware["Auth Middleware\n(middleware.ts)"]:::internal
        ServerActions["Server Actions\n(lib/actions/)"]:::internal
        SupabaseClient["Supabase Client\n(lib/supabase.ts)"]:::internal
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Clerk["Clerk Auth Service"]:::external
        SupabaseDB["Supabase Database"]:::external
        VapiAI["Vapi AI Service\n(lib/vapi.sdk.ts)"]:::external
        Sentry["Sentry Monitoring"]:::monitoring
    end

    %% Data Flow
    Browser -->|"HTTP GET/POST"| NextFrontend
    NextFrontend -->|"Renders Pages"| Browser
    NextFrontend -->|"Invoke Server"| VercelEdge
    VercelEdge --> NextServer
    NextServer -->|"Auth Token Verification"| Middleware
    Middleware -->|"Verify Token"| Clerk
    NextServer -->|"Call Server Actions"| ServerActions
    ServerActions -->|"DB Query via Client"| SupabaseClient
    SupabaseClient -->|"SQL CRUD"| SupabaseDB
    ServerActions -->|"AI Request"| VapiAI
    NextServer -->|"Error/Event Reporting"| Sentry
    VercelEdge -->|"Edge Reporting"| Sentry
    NextFrontend --> UIComponents
    UIComponents --> UIPrimitives

    %% Click Events
    click NextFrontend "https://github.com/mecha-aima/teachlm/tree/main/app/"
    click UIComponents "https://github.com/mecha-aima/teachlm/tree/main/components/"
    click UIPrimitives "https://github.com/mecha-aima/teachlm/tree/main/components/ui/"
    click Middleware "https://github.com/mecha-aima/teachlm/blob/main/middleware.ts"
    click ServerActions "https://github.com/mecha-aima/teachlm/blob/main/lib/actions/lesson.actions.ts"
    click ServerActions "https://github.com/mecha-aima/teachlm/blob/main/lib/actions/teacher.actions.ts"
    click SupabaseClient "https://github.com/mecha-aima/teachlm/blob/main/lib/supabase.ts"
    click VapiAI "https://github.com/mecha-aima/teachlm/blob/main/lib/vapi.sdk.ts"
    click Sentry "https://github.com/mecha-aima/teachlm/blob/main/sentry.edge.config.ts"
    click Sentry "https://github.com/mecha-aima/teachlm/blob/main/sentry.server.config.ts"
    click Sentry "https://github.com/mecha-aima/teachlm/blob/main/instrumentation.ts"
    click Sentry "https://github.com/mecha-aima/teachlm/blob/main/instrumentation-client.ts"
    click Browser "https://github.com/mecha-aima/teachlm/blob/main/app/lessons/page.tsx"
    click Browser "https://github.com/mecha-aima/teachlm/blob/main/app/lessons/[id]/page.tsx"
    click Browser "https://github.com/mecha-aima/teachlm/blob/main/app/teachers/page.tsx"
    click Browser "https://github.com/mecha-aima/teachlm/blob/main/app/teachers/[id]/page.tsx"
    click Browser "https://github.com/mecha-aima/teachlm/blob/main/app/teachers/new/page.tsx"
    click Browser "https://github.com/mecha-aima/teachlm/blob/main/app/my-journey/page.tsx"
    click Browser "https://github.com/mecha-aima/teachlm/blob/main/app/subscription/page.tsx"
    click Browser "https://github.com/mecha-aima/teachlm/blob/main/app/sign-in/[[...sign-in]]/page.tsx"
    click Browser "https://github.com/mecha-aima/teachlm/blob/main/app/layout.tsx"
    click Browser "https://github.com/mecha-aima/teachlm/blob/main/app/globals.css"
    click Browser "https://github.com/mecha-aima/teachlm/blob/main/app/global-error.tsx"

    %% Styles
    classDef internal fill:#AED6F1,stroke:#2E86C1,color:#1B4F72
    classDef external fill:#ABEBC6,stroke:#27AE60,color:#145A32
    classDef monitoring fill:#F9E79F,stroke:#B9770E,color:#7D6608
```
