# yash8745/ai-backend architecture

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

- Interactive diagram: https://gitdiagram.com/yash8745/ai-backend
- Repository: https://github.com/yash8745/ai-backend

## Overview

##### Main Components

A. Client Layer:
- React Frontend (ai-app repository)
- User interface components for memory upload and retrieval

B. Backend Services:
1. Node Backend:
- User authentication
- MongoDB integration
- User management

2. AI Backend (This repository):
- Audio processing (audio.py, audio_routes.py)
- Image processing (image_routes.py, image_description_main.py)
- Chatbot functionality (chatbot.py)
- Vector database integration (pinecone_tools.py)

C. External Services:
- Langchain API
- Groq API
- Vector Database (Pinecone)
- MongoDB

##### Component Relationships

- Frontend → Node Backend: Authentication requests
- Frontend → AI Backend: Memory storage and retrieval requests
- AI Backend → Pinecone: Vector storage and RAG operations
- AI Backend → External APIs: LLM and AI processing
- Node Backend → MongoDB: User data storage

##### Specific Elements

a. AI Backend Components:
- Audio Processing Pipeline
- Image Processing Pipeline
- RAG Implementation
- Chatbot Service
- Vector Database Interface

- User requests flow
- Authentication flow
- Memory processing flow
- AI processing flow

##### Technical Details to Highlight

- REST API endpoints between components
- Vector embedding process
- RAG architecture within the AI backend
- Memory storage and retrieval flow
- Authentication and authorization flow

##### Implementation Notes

- Rectangles: Services and components
- Clouds: External services
- Hexagons: AI/ML components

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef nodebackend fill:#2ecc71,stroke:#27ae60,color:white
    classDef aibackend fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef api fill:#e74c3c,stroke:#c0392b,color:white

    %% Frontend Layer
    subgraph Frontend
        UI[React Frontend]:::frontend
        UI --> |"Authentication"| Auth
        UI --> |"Memory Operations"| Gateway
    end

    %% Backend Services Layer
    subgraph "Backend Services"
        %% Node.js Backend
        subgraph "Node Backend"
            Auth[Authentication Service]:::nodebackend
            UserMgmt[User Management]:::nodebackend
            click UserMgmt "https://github.com/Yash8745/ai-backend/blob/main/routes/user_routes.py"
        end

        %% AI Backend
        subgraph "AI Backend"
            Gateway[API Gateway]:::aibackend
            click Gateway "https://github.com/Yash8745/ai-backend/blob/main/app.py"
            
            Config[Configuration]:::aibackend
            click Config "https://github.com/Yash8745/ai-backend/blob/main/config.py"
            
            AudioProc[Audio Processing]:::aibackend
            click AudioProc "https://github.com/Yash8745/ai-backend/blob/main/audio.py"
            
            AudioRoutes[Audio Routes]:::aibackend
            click AudioRoutes "https://github.com/Yash8745/ai-backend/blob/main/audio_routes.py"
            
            ImageProc[Image Processing]:::aibackend
            click ImageProc "https://github.com/Yash8745/ai-backend/blob/main/image_description_main.py"
            
            ImageRoutes[Image Routes]:::aibackend
            click ImageRoutes "https://github.com/Yash8745/ai-backend/blob/main/image_routes.py"
            
            Chatbot[Chatbot Service]:::aibackend
            click Chatbot "https://github.com/Yash8745/ai-backend/blob/main/chatbot.py"
            
            VectorDB[Vector DB Interface]:::aibackend
            click VectorDB "https://github.com/Yash8745/ai-backend/blob/main/pinecone_tools.py"
            
            RAG[RAG Implementation]:::aibackend
            click RAG "https://github.com/Yash8745/ai-backend/blob/main/notebooks/rag_app.ipynb"
            
            ModelRoutes[Model Routes]:::aibackend
            click ModelRoutes "https://github.com/Yash8745/ai-backend/blob/main/model_routes.py"
            
            Utils[Utility Functions]:::aibackend
            click Utils "https://github.com/Yash8745/ai-backend/blob/main/utils.py"
        end
    end

    %% External Services Layer
    subgraph "External Services"
        Langchain[Langchain API]:::external
        Groq[Groq API]:::external
        Pinecone[(Pinecone Vector DB)]:::database
        MongoDB[(MongoDB)]:::database
    end

    %% Relationships
    Auth --> MongoDB
    UserMgmt --> MongoDB
    Gateway --> AudioProc
    Gateway --> ImageProc
    Gateway --> Chatbot
    Gateway --> RAG
    
    AudioProc --> AudioRoutes
    ImageProc --> ImageRoutes
    
    VectorDB --> Pinecone
    RAG --> VectorDB
    RAG --> Langchain
    Chatbot --> Groq
    
    %% Legend
    subgraph Legend
        F[Frontend]:::frontend
        N[Node.js Backend]:::nodebackend
        A[AI Backend]:::aibackend
        E[External Service]:::external
        D[(Database)]:::database
    end
```
