# rohittcodes/heymate architecture

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

- Interactive diagram: https://gitdiagram.com/rohittcodes/heymate
- Repository: https://github.com/rohittcodes/heymate

## Overview

##### Main System Components

a) Client Layer:
- Next.js Frontend (app directory structure)
- Authentication UI components (/(auth) route)
- Main Application UI components (/(main) route)
- Global UI components

b) Server Layer:
- API Routes (/api directory)
- Authentication System (Auth.js)
- Real-time Communication (Pusher)
- File Upload System (UploadThing)

c) Database Layer:
- MySQL Database (via Prisma)
- MindsDB AI Models
- Data Models (User, Group, VerificationToken)

d) External Services:
- MindsDB API
- OAuth Providers (GitHub, Google)
- Email Service (Resend)
- File Storage (UploadThing)

##### Component Relationships

a) Data Flow:
- Client → API Routes → Database
- Real-time message flow through Pusher
- Authentication flow through Auth.js
- AI Bot interactions with MindsDB

b) Authentication Flow:
- Social login paths
- Email verification process
- Session management

##### Specific Implementation Details

Specialized sections for:

a) Chat System:
- Direct messaging
- Messaging
- Real-time updates
- Sentiment analysis pipeline

b) AI Integration:
- Bot management system
- MindsDB model connections
- Sentiment analysis flow

##### Component Details

Key components to highlight:

**Frontend:**
- Auth Components (/app/(auth))
- Main App Components (/app/(main))
- Chat Interface (/app/(main)/app/chat)
- Group Management (/app/(main)/app/groups)

**Backend:**
- API Routes (/app/api)
- Authentication Handlers (/app/api/auth)
- Message Handlers (/app/api/messages)
- Friend Management (/app/api/friends)

**Services:**
- Pusher Integration (real-time)
- MindsDB Connection (AI bots)
- Email Service (verification)
- File Upload Service

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FE[Next.js Frontend]
        AC[Authentication Components]:::auth
        MC[Main App Components]:::main
        GC[Global Components]:::global
        
        FE --> AC
        FE --> MC
        FE --> GC
        
        subgraph AuthUI
            VF[Verification Form]:::auth
            LP[Login Providers]:::auth
        end
        
        subgraph MainUI
            CH[Chat Interface]:::main
            GM[Group Management]:::main
            GB[Group Bots]:::main
            FP[Friend Preview]:::main
            MV[Message View]:::main
            PR[Profile]:::main
            FU[File Upload]:::main
        end
    end
    
    subgraph Server
        API[API Routes]
        AS[Auth System]:::auth
        RT[Real-time System]:::realtime
        FS[File System]:::storage
        
        subgraph APIRoutes
            AR["/api/auth"]:::api
            MR["/api/messages"]:::api
            FR["/api/friends"]:::api
            UR["/api/uploadthing"]:::api
            SR["/api/sentiment"]:::api
        end
    end
    
    subgraph Database
        DB[(MySQL/Prisma)]:::db
        AI[(MindsDB)]:::ai
        
        subgraph Models
            UM[User Model]:::model
            GM2[Group Model]:::model
            VM[Verification Model]:::model
        end
    end
    
    subgraph External
        MDB[MindsDB API]:::external
        OAP[OAuth Providers]:::external
        EMS[Email Service]:::external
        UPT[UploadThing]:::external
        PSH[Pusher]:::external
    end
    
    %% Connections
    AC --> AR
    AR --> AS
    AS --> OAP
    AS --> DB
    
    MC --> MR
    MR --> RT
    RT --> PSH
    
    CH --> MR
    GM --> MR
    
    GB --> AI
    AI --> MDB
    
    FU --> UR
    UR --> FS
    FS --> UPT
    
    VF --> EMS
    
    %% Click Events
    click AC "https://github.com/rohittcodes/heymate/tree/main/app/(auth)"
    click AS "https://github.com/rohittcodes/heymate/blob/main/auth.ts"
    click AR "https://github.com/rohittcodes/heymate/blob/main/app/api/auth/[...nextauth]"
    click CH "https://github.com/rohittcodes/heymate/tree/main/app/(main)/app/chat"
    click MR "https://github.com/rohittcodes/heymate/tree/main/app/api/messages"
    click RT "https://github.com/rohittcodes/heymate/blob/main/lib/pusher.ts"
    click GM "https://github.com/rohittcodes/heymate/tree/main/app/(main)/app/groups"
    click GB "https://github.com/rohittcodes/heymate/blob/main/app/(main)/app/_components/group-bots.tsx"
    click FU "https://github.com/rohittcodes/heymate/blob/main/components/globals/file-upload.tsx"
    click UR "https://github.com/rohittcodes/heymate/tree/main/app/api/uploadthing"
    click FP "https://github.com/rohittcodes/heymate/blob/main/app/(main)/app/chat/_components/friend-preview.tsx"
    click FR "https://github.com/rohittcodes/heymate/tree/main/app/api/friends"
    click DB "https://github.com/rohittcodes/heymate/blob/main/prisma/schema.prisma"
    click VF "https://github.com/rohittcodes/heymate/blob/main/app/(auth)/_components/verification-form.tsx"
    click MV "https://github.com/rohittcodes/heymate/blob/main/app/(main)/app/chat/_components/message-view.tsx"
    click PR "https://github.com/rohittcodes/heymate/tree/main/app/(main)/app/profil"

    %% Styles
    classDef auth fill:#e6e6fa
    classDef main fill:#add8e6
    classDef global fill:#98fb98
    classDef api fill:#f08080
    classDef db fill:#ffd700
    classDef ai fill:#ff69b4
    classDef external fill:#ff7f50
    classDef model fill:#deb887
    classDef realtime fill:#87ceeb
    classDef storage fill:#98fb98

    %% Legend
    subgraph Legend
        L1[Authentication]:::auth
        L2[Main Components]:::main
        L3[Global Components]:::global
        L4[API Routes]:::api
        L5[Database]:::db
        L6[AI Components]:::ai
        L7[External Services]:::external
        L8[Data Models]:::model
        L9[Real-time]:::realtime
        L10[Storage]:::storage
    end
```
