# rishipatel9/elytra architecture

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

- Interactive diagram: https://gitdiagram.com/rishipatel9/elytra
- Repository: https://github.com/rishipatel9/elytra

## Overview

##### Main System Components

a) Client Layer:
- Next.js Frontend (src/app directory)
- Video Chat Interface (src/components/video-bot)
- Authentication UI (src/app/auth)
- Admin Dashboard (src/app/admin)

b) API Layer:
- Next.js API Routes (src/app/api)
- Authentication Endpoints
- Chat/Counseling Endpoints
- Admin Management Endpoints

c) Service Layer:
- AI Services Integration
- OpenAI Assistant (lib/openai-assistant.ts)
- Google Gemini (lib/GeminiClient.ts)
- Video Streaming (LiveKit)
- Email Service (lib/email.ts)

d) Data Layer:
- Prisma ORM
- Database (shown by prisma/schema.prisma)
- Pinecone Vector Storage

##### Component Relationships

a) Frontend to Backend:
- API routes connecting components to services
- WebSocket connections for real-time chat
- Authentication flows

b) Service Interactions:
- AI services communication flow
- Video streaming data flow
- Email notification system

##### Specific Implementation Details

Key architectural patterns:

a) Authentication Flow:
- NextAuth integration
- OAuth providers (Google, GitHub)
- Admin authentication system

b) AI Counseling System:
- Chat processing pipeline
- Video bot integration
- Session management

c) Data Management:
- Prisma schema relationships
- Vector storage for AI responses
- Real-time data synchronization

##### Additional Elements

Supporting components:

a) Infrastructure:
- Environment configuration
- API endpoints structure
- Database migrations

b) Development Tools:
- TypeScript integration
- ESLint/Prettier setup
- Build pipeline

This system design should emphasize the integration of AI services with real-time video capabilities, showing how they work together to provide an effective student counseling platform.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Frontend["Next.js Frontend"]:::frontend
        VideoChat["Video Chat Interface"]:::frontend
        AuthUI["Authentication UI"]:::frontend
        AdminDash["Admin Dashboard"]:::frontend
    end

    subgraph API
        AuthAPI["Authentication API"]:::api
        ChatAPI["Chat/Counseling API"]:::api
        AdminAPI["Admin API"]:::api
        SessionAPI["Session API"]:::api
    end

    subgraph Services
        OpenAI["OpenAI Assistant"]:::service
        Gemini["Google Gemini"]:::service
        LiveKit["LiveKit Streaming"]:::service
        Email["Email Service"]:::service
    end

    subgraph Data
        Prisma["Prisma ORM"]:::data
        DB[(Database)]:::data
        Pinecone[(Pinecone Vector DB)]:::data
    end

    subgraph Auth
        NextAuth["NextAuth"]:::auth
        OAuth["OAuth Providers"]:::auth
    end

    %% Client Layer Connections
    Frontend --> AuthAPI
    Frontend --> ChatAPI
    VideoChat --> LiveKit
    AdminDash --> AdminAPI
    AuthUI --> NextAuth

    %% API Layer Connections
    AuthAPI --> NextAuth
    ChatAPI --> OpenAI
    ChatAPI --> Gemini
    SessionAPI --> DB
    AdminAPI --> DB

    %% Service Layer Connections
    OpenAI --> Pinecone
    Gemini --> Pinecone
    Email --> DB
    LiveKit -.-> Frontend

    %% Data Layer Connections
    Prisma --> DB
    NextAuth --> DB
    OAuth --> NextAuth

    %% Click Events
    click Frontend "https://github.com/rishipatel9/elytra/tree/main/src/app"
    click VideoChat "https://github.com/rishipatel9/elytra/tree/main/src/components/video-bot"
    click AuthUI "https://github.com/rishipatel9/elytra/tree/main/src/app/auth"
    click AdminDash "https://github.com/rishipatel9/elytra/tree/main/src/app/admin/dashboard"
    click AuthAPI "https://github.com/rishipatel9/elytra/tree/main/src/app/api/auth"
    click ChatAPI "https://github.com/rishipatel9/elytra/tree/main/src/app/api/chat"
    click AdminAPI "https://github.com/rishipatel9/elytra/tree/main/src/app/api/admin"
    click SessionAPI "https://github.com/rishipatel9/elytra/tree/main/src/app/api/sessions"
    click OpenAI "https://github.com/rishipatel9/elytra/blob/main/src/lib/openai-assistant.ts"
    click Gemini "https://github.com/rishipatel9/elytra/blob/main/src/lib/GeminiClient.ts"
    click Email "https://github.com/rishipatel9/elytra/blob/main/src/lib/email.ts"
    click Prisma "https://github.com/rishipatel9/elytra/blob/main/prisma/schema.prisma"
    click DB "https://github.com/rishipatel9/elytra/blob/main/src/lib/db.ts"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#f1c40f,stroke:#f39c12,color:black
    classDef data fill:#9b59b6,stroke:#8e44ad,color:white
    classDef auth fill:#e74c3c,stroke:#c0392b,color:white

    %% Legend
    subgraph Legend
        Frontend_L["Frontend Component"]:::frontend
        API_L["API Component"]:::api
        Service_L["Service Component"]:::service
        Data_L["Data Component"]:::data
        Auth_L["Auth Component"]:::auth
    end
```
