# samugit83/ai-superagent architecture

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

- Interactive diagram: https://gitdiagram.com/samugit83/ai-superagent
- Repository: https://github.com/samugit83/ai-superagent

## Overview

##### Project type and purpose
- This is a full-stack Next.js web application that integrates Generative AI.
- Purpose: build an AI super-agent that scrapes the web, uploads files to S3, trains a personal model, streams chat responses via WebSockets, and calls Amazon Bedrock foundation models (e.g., Claude 3 Sonnet, Amazon Titan).

##### File structure
- app/ – Next.js (app router) React components and pages: chat UI (chat_comp.jsx, training_window.jsx), layout.js, page.js, global CSS.
- redux/ – client state management: store.js, appslice.js.
- server_actions/ – Next.js server actions for fetching and S3 multipart uploads.
- websocket_server/ – a Socket.io / WebSocket server (websocket.js, bedrock_agent_runtime.js) for real-time streaming.
- lambda-repo/ – AWS Lambda microservices, each in its own subfolder (ActionGroupGenericQuestionToModel, SmartAgentPreprocessParser, webdiscoveryActionGroup), plus a Node.js bedrock_api module.
- bedrock-workflow/ – PDF documenting the AI workflow.
- Config files: next.config.mjs, jsconfig.json, .eslintrc.json.

##### README for additional insights
- Highlights features: web scraping (Python + Beautiful Soup), S3 multipart uploads, streaming chat division into chunks, Amazon Bedrock usage, multiple FM integration, Socket.io real-time comms.
- Mentions AWS Lambda and OpenSearch (though OpenSearch isn’t in the file tree, you may integrate it similarly).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        UI["Client Browser / React UI"]:::frontend
        Redux["Redux Store"]:::frontend
    end

    %% Application/API Layer
    subgraph "Application/API Layer"
        direction TB
        NextServer["Next.js Server Actions"]:::backend
        WS["WebSocket Server"]:::backend
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        Lambdas["AWS Lambda Microservices"]:::backend
        BedrockAPI["Bedrock API Module"]:::backend
    end

    %% Integration Layer
    subgraph "Integration Layer"
        direction TB
        S3["AWS S3 (Storage)"]:::storage
        AI["Amazon Bedrock & Foundation Models"]:::ai
    end

    %% Connections
    UI -->|"dispatch actions"| Redux
    Redux -->|"HTTPS POST"| NextServer
    NextServer -->|"S3 multipart upload"| S3
    NextServer -->|"invoke lambda"| Lambdas
    Lambdas -->|"use bedrock_api"| BedrockAPI
    BedrockAPI -->|"HTTPS call"| AI
    NextServer -->|"HTTP upgrade"| WS
    WS -->|"...stream chunks (Socket.IO emit)"| UI

    %% Click Events - Presentation Layer
    click UI "https://github.com/samugit83/ai-superagent/blob/master/app/chat/chat_comp.jsx"
    click UI "https://github.com/samugit83/ai-superagent/blob/master/app/chat/page.jsx"
    click UI "https://github.com/samugit83/ai-superagent/blob/master/app/chat/training_window.jsx"
    click UI "https://github.com/samugit83/ai-superagent/blob/master/app/chat/ingestion_job.js"
    click UI "https://github.com/samugit83/ai-superagent/blob/master/app/chat/multipartupload.js"
    click UI "https://github.com/samugit83/ai-superagent/blob/master/app/globals.css"
    click UI "https://github.com/samugit83/ai-superagent/blob/master/app/layout.js"
    click UI "https://github.com/samugit83/ai-superagent/blob/master/app/page.js"
    click UI "https://github.com/samugit83/ai-superagent/blob/master/app/page.module.css"
    click UI "https://github.com/samugit83/ai-superagent/blob/master/app/prism.css"
    click Redux "https://github.com/samugit83/ai-superagent/blob/master/redux/store.js"
    click Redux "https://github.com/samugit83/ai-superagent/blob/master/redux/reduxfeat/appslice.js"
    click Redux "https://github.com/samugit83/ai-superagent/blob/master/redux/redux_useclient_export.js"

    %% Click Events - API Layer
    click NextServer "https://github.com/samugit83/ai-superagent/blob/master/server_actions/fetching.js"
    click NextServer "https://github.com/samugit83/ai-superagent/blob/master/server_actions/s3_multipart_upload.js"
    click WS "https://github.com/samugit83/ai-superagent/blob/master/websocket_server/websocket.js"
    click WS "https://github.com/samugit83/ai-superagent/blob/master/websocket_server/bedrock_agent_runtime.js"
    click WS "https://github.com/samugit83/ai-superagent/blob/master/websocket_server/.env"

    %% Click Events - Service Layer
    click Lambdas "https://github.com/samugit83/ai-superagent/blob/master/lambda-repo/ActionGroupGenericQuestionToModel/lambda_function.py"
    click Lambdas "https://github.com/samugit83/ai-superagent/blob/master/lambda-repo/SmartAgentPreprocessParser/lambda_function.py"
    click Lambdas "https://github.com/samugit83/ai-superagent/blob/master/lambda-repo/webdiscoveryActionGroup/lambda_function.py"
    click BedrockAPI "https://github.com/samugit83/ai-superagent/blob/master/lambda-repo/bedrock_api/index.js"
    click BedrockAPI "https://github.com/samugit83/ai-superagent/blob/master/lambda-repo/bedrock_api/methods.js"

    %% Click Events - Integration Layer
    click S3 "https://github.com/samugit83/ai-superagent/blob/master/server_actions/s3_multipart_upload.js"
    click S3 "https://github.com/samugit83/ai-superagent/blob/master/app/chat/multipartupload.js"
    click AI "https://github.com/samugit83/ai-superagent/blob/master/bedrock-workflow/AI app workflow.pdf"

    %% Project Configuration
    Config["Project Configuration"]:::config
    Config --> UI
    Config --> NextServer

    click Config "https://github.com/samugit83/ai-superagent/blob/master/next.config.mjs"
    click Config "https://github.com/samugit83/ai-superagent/blob/master/jsconfig.json"
    click Config "https://github.com/samugit83/ai-superagent/blob/master/.eslintrc.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef backend fill:#E2F0D9,stroke:#22863A,color:#22863A;
    classDef storage fill:#FFE8A1,stroke:#D69F00,color:#8A5800;
    classDef ai fill:#F5D0FE,stroke:#8A3FFC,color:#5A15A7;
    classDef config fill:#F0F0F0,stroke:#CCCCCC,color:#333333;
```
