# stephensanwo/fullstack-ai-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/stephensanwo/fullstack-ai-chatbot
- Repository: https://github.com/stephensanwo/fullstack-ai-chatbot

## Overview

##### Main Components

a) Frontend Layer:
- React Client Application (in /client)
- WebSocket Client Connection
- Key UI Components (Chat Interface, Input, Header)

b) Backend Layer:
- FastAPI Server (in /server)
- WebSocket Server Connection
- Route Handlers

c) Worker Layer:
- GPT-J Worker Service (in /worker)
- Hugging Face API Integration

d) Data Layer:
- Redis Enterprise
- Redis JSON Store
- Redis Streams
- Redis Cache

**[Client Tier]**
- ↕
**[API Server Tier]**
- ↕
**[Worker Tier]**
- ↕
**[Data Tier]**

##### Component Details

Client Tier:
- Main React components structure
- WebSocket connection point
- UI components (ChatBox, ChatInput, Header)

API Server Tier:
- FastAPI server with WebSocket handler
- Route handlers
- Connection to Redis

Worker Tier:
- GPT-J worker service
- Hugging Face API integration
- Redis stream consumer

Data Tier:
- Redis Enterprise instance
- Separate Redis functionalities (JSON, Streams, Cache)

##### Additional Elements

Technical details:
- WebSocket connection endpoints
- Redis stream names
- Key API routes
- Component interaction patterns

##### Notes Section

Technical notes about:
- WebSocket implementation details
- Redis stream configuration
- GPT-J model integration
- Scaling considerations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        App["React App"]:::frontend
        ChatBox["Chat Interface"]:::frontend
        ChatInput["Chat Input"]:::frontend
        Header["Header"]:::frontend
        WSClient["WebSocket Client"]:::frontend
        
        App --> ChatBox
        App --> ChatInput
        App --> Header
        App --> WSClient
    end

    subgraph Server
        FastAPI["FastAPI Server"]:::backend
        WSHandler["WebSocket Handler"]:::backend
        RouteHandler["Route Handler"]:::backend
        RedisProducer["Redis Producer"]:::backend
        RedisCache["Redis Cache"]:::backend
        RedisStream["Redis Stream Handler"]:::backend
        RedisConfig["Redis Config"]:::backend
        WSUtils["WebSocket Utils"]:::backend
        ChatSchema["Chat Schema"]:::backend

        FastAPI --> WSHandler
        FastAPI --> RouteHandler
        RouteHandler --> RedisProducer
        RouteHandler --> RedisCache
        WSHandler --> RedisStream
        WSHandler --> WSUtils
        RouteHandler --> ChatSchema
        RedisProducer & RedisCache & RedisStream --> RedisConfig
    end

    subgraph Worker
        WorkerMain["Worker Service"]:::worker
        GPTJ["GPT-J Model"]:::worker
        HFApi["Hugging Face API"]:::external

        WorkerMain --> GPTJ
        GPTJ --> HFApi
    end

    subgraph Data
        Redis[(Redis Enterprise)]:::database
        RedisJSON[("Redis JSON")]:::database
        RedisStreams[("Redis Streams")]:::database
        RedisCacheStore[("Redis Cache")]:::database

        Redis --> RedisJSON
        Redis --> RedisStreams
        Redis --> RedisCacheStore
    end

    WSClient <--> WSHandler
    RedisProducer --> RedisStreams
    RedisStream --> RedisStreams
    RedisCache --> RedisCacheStore
    WorkerMain --> RedisStreams
    
    %% Click Events
    click App "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/client/src/App.tsx"
    click ChatBox "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/client/src/components/Chatbox/index.tsx"
    click ChatInput "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/client/src/components/ChatInput/index.tsx"
    click Header "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/client/src/components/Header/Header.tsx"
    click FastAPI "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/server/main.py"
    click WSHandler "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/server/src/socket/connection.py"
    click RouteHandler "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/server/src/routes/chat.py"
    click ChatSchema "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/server/src/schema/chat.py"
    click GPTJ "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/worker/src/model/gptj.py"
    click WorkerMain "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/worker/main.py"
    click RedisCache "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/server/src/redis/cache.py"
    click RedisStream "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/server/src/redis/stream.py"
    click RedisConfig "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/server/src/redis/config.py"
    click RedisProducer "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/server/src/redis/producer.py"
    click WSUtils "https://github.com/stephensanwo/fullstack-ai-chatbot/blob/master/server/src/socket/utils.py"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef worker fill:#f1c40f,stroke:#f39c12,color:black
    classDef database fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        WorkerComp["Worker Component"]:::worker
        DB["Database Component"]:::database
        Ext["External Service"]:::external
    end
```
