# sankalpcreat/bhabhaai architecture

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

- Interactive diagram: https://gitdiagram.com/sankalpcreat/bhabhaai
- Repository: https://github.com/sankalpcreat/bhabhaai

## Overview

##### Main Components Identification
The system appears to have the following key components:

a. Frontend Layer (Next.js App Router)
- Client-side components (app/page.tsx, app/layout.tsx)
- API Routes (app/api/chat/route.ts)
- Styling (globals.css, Tailwind CSS)

b. Service Layer (lib directory)
- Image API Service (imageApi.ts)
- LLM API Service (llmApi.ts)
- Memory Management Service (memoryManager.ts)

**┌─────────────────────────────────────────────────────────┐**
- Client Browser                        │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Next.js Application                   │
- ┌───────────────┐    ┌───────────────┐                 │
- Pages Layer  │    │   API Layer   │                 │
- (app/*.tsx)  │    │ (/api/chat)   │                 │
- ┘    └───────────────┘                 │
- ↕                   ↕                         │
- ┌─────────────────────────────────────────────┐        │
- Service Layer                   │        │
- ┌──────────┐  ┌────────┐  ┌────────────┐  │        │
- Image API │  │LLM API │  │Memory      │  │        │
- Service   │  │Service │  │Manager     │  │        │
- ┘  └────────┘  └────────────┘  │        │
- ┘        │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- External Services                      │
- (Image API Provider, LLM Provider, etc.)            │
- ┘

##### Important Elements

a. Components:
- Next.js App Router structure
- API routes for chat functionality
- Service layer abstractions
- External service integrations

b. Data Flow:
- Client-server communication
- Internal service communication
- External API calls

c. Key Technologies:
- Next.js
- TypeScript
- Tailwind CSS
- Image Processing
- LLM Integration

##### Specific Implementation Details

- The App Router architecture of Next.js 13+
- The separation between client components and API routes
- The service layer abstraction for external services
- Memory management implementation
- Image and LLM API integration points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph NextApp["Next.js Application"]
        subgraph FrontendLayer["Frontend Layer"]
            MainComponent["Main Component"]:::frontend
            Layout["Layout"]:::frontend
            GlobalStyles["Global Styles"]:::frontend
        end

        subgraph APILayer["API Layer"]
            ChatAPI["/api/chat"]:::api
        end

        subgraph ServiceLayer["Service Layer"]
            ImageService["Image API Service"]:::service
            LLMService["LLM API Service"]:::service
            MemoryManager["Memory Manager"]:::service
        end

        subgraph Config["Configuration"]
            NextConfig["Next.js Config"]:::config
            TSConfig["TypeScript Config"]:::config
            TailwindConfig["Tailwind Config"]:::config
            PostCSSConfig["PostCSS Config"]:::config
        end
    end

    subgraph External["External Services"]
        ImageProvider["Image API Provider"]:::external
        LLMProvider["LLM Provider"]:::external
    end

    %% Relationships
    Browser --> MainComponent
    Browser --> Layout
    MainComponent --> ChatAPI
    ChatAPI --> ImageService
    ChatAPI --> LLMService
    ChatAPI --> MemoryManager
    ImageService --> ImageProvider
    LLMService --> LLMProvider
    Layout --> GlobalStyles

    %% Click Events
    click MainComponent "https://github.com/Sankalpcreat/BhabhaAI/blob/main/app/page.tsx"
    click Layout "https://github.com/Sankalpcreat/BhabhaAI/blob/main/app/layout.tsx"
    click GlobalStyles "https://github.com/Sankalpcreat/BhabhaAI/blob/main/app/globals.css"
    click ChatAPI "https://github.com/Sankalpcreat/BhabhaAI/blob/main/app/api/chat/route.ts"
    click ImageService "https://github.com/Sankalpcreat/BhabhaAI/blob/main/lib/imageApi.ts"
    click LLMService "https://github.com/Sankalpcreat/BhabhaAI/blob/main/lib/llmApi.ts"
    click MemoryManager "https://github.com/Sankalpcreat/BhabhaAI/blob/main/lib/memoryManager.ts"
    click NextConfig "https://github.com/Sankalpcreat/BhabhaAI/blob/main/next.config.ts"
    click TSConfig "https://github.com/Sankalpcreat/BhabhaAI/blob/main/tsconfig.json"
    click TailwindConfig "https://github.com/Sankalpcreat/BhabhaAI/blob/main/tailwind.config.ts"
    click PostCSSConfig "https://github.com/Sankalpcreat/BhabhaAI/blob/main/postcss.config.mjs"

    %% Styles
    classDef frontend fill:#3b82f6,color:white
    classDef api fill:#22c55e,color:white
    classDef service fill:#eab308,color:black
    classDef external fill:#6b7280,color:white
    classDef config fill:#a855f7,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Components"]:::frontend
        API["API Endpoints"]:::api
        Service["Services"]:::service
        ExternalService["External Services"]:::external
        Configuration["Configuration"]:::config
    end
```
