# l33tkr3w/llamacards architecture

> Architecture diagram of the GitHub repository l33tkr3w/llamacards, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/l33tkr3w/llamacards
- Repository: https://github.com/l33tkr3w/llamacards

## Overview

##### Main Components

a) Client-Side Layer:
- HTML5 Canvas/DOM for node-based interface
- WebSocket client
- JavaScript runtime environment
- Card management UI

b) Server-Side Layer:
- Quart ASGI Server component
- WebSocket Server handler
- Card Processing Engine
- Model Integration Layer

c) External Services:
- Ollama AI Models container
- Database for RAG (Retrieval-Augmented Generation)

##### Component Relationships

- Bidirectional WebSocket connection between client and server
- HTTP/HTTPS connections for initial page load
- Data flow between server and Ollama models
- Database connections for embedding storage and retrieval

##### Specific Implementation Details

a) Card System Architecture:
- Card Types (Input, Output, Vision, RAG, Repeater)
- Card Connection Manager
- Card State Manager

b) Processing Pipeline:
- Concurrent processing handler
- Sequential processing handler
- Real-time update broadcaster

##### Detailed Component Specifications

For each major component, include:
- Technology stack (Quart, aiohttp, HTTPX)
- Primary responsibilities
- Input/Output specifications
- Key interfaces

##### External Services Layer (Ollama/Storage)

Remember to maintain a balance between detail and clarity, focusing on the real-time, node-based nature of the application while clearly showing how the different components interact to process and manage the AI model interactions.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Browser
        UI[HTML5 Canvas/DOM Interface]
        WC[WebSocket Client]
        JS[JavaScript Runtime]
        CM[Card Management UI]
    end

    %% Server Layer
    subgraph Server
        QS["Quart ASGI Server"]
        WS[WebSocket Server]
        CPE[Card Processing Engine]
        MIL[Model Integration Layer]
    end

    %% Card System
    subgraph CardSystem
        CT[Card Types]
        CCM[Card Connection Manager]
        CSM[Card State Manager]
        
        subgraph CardTypes
            IC[Input Card]
            OC[Output Card]
            VC[Vision Card]
            RC[RAG Card]
            RPC[Repeater Card]
        end
    end

    %% Processing Layer
    subgraph Processing
        CP[Concurrent Processing]
        SP[Sequential Processing]
        RU[Real-time Updates]
    end

    %% External Services
    subgraph External
        OM[Ollama AI Models]
        DB[(RAG Database)]
    end

    %% Connections
    UI --> WC
    WC <-.->|WebSocket| WS
    QS --> WS
    QS --> CPE
    CPE --> MIL
    MIL --> OM
    RC --> DB
    
    %% Card Relationships
    CT --> CCM
    CCM --> CSM
    CardTypes --> CPE
    
    %% Processing Flow
    CPE --> CP
    CPE --> SP
    CP & SP --> RU
    RU --> WS

    %% Styling
    classDef browser fill:#a8d1f0
    classDef server fill:#90EE90
    classDef external fill:#FFE5B4
    classDef card fill:#DDA0DD
    
    class Browser,UI,WC,JS,CM browser
    class QS,WS,CPE,MIL server
    class OM,DB external
    class CardSystem,CT,CCM,CSM,IC,OC,VC,RC,RPC card

    %% Click Events
    click QS "https://github.com/l33tkr3w/LlamaCards/blob/main/LlamaCards.py"
    click UI "https://github.com/l33tkr3w/LlamaCards/blob/main/templates/index.html"
    click UI "https://github.com/l33tkr3w/LlamaCards/blob/main/LlamaCards_Webllm.html"
    click QS "https://github.com/l33tkr3w/LlamaCards/blob/main/Requirements.txt"

    %% Legend
    subgraph Legend
        L1[Client Components]:::browser
        L2[Server Components]:::server
        L3[External Services]:::external
        L4[Card Components]:::card
    end
```
