# rycerzes/shl-rag-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/rycerzes/shl-rag-chatbot
- Repository: https://github.com/rycerzes/shl-rag-chatbot

## Overview

##### Main components
- Frontend:
- Next.js Application: Represent the client-side application that handles user interactions.
- UI Components: Include components for chat interfaces, messages, recommendation tables, and theming.
- Utility Libraries: Show supporting libraries in “lib” for extracting recommendations and other utilities.
- Backend:
- HTTP Server: Use “app.py” as the entry point of the backend service.
- Processing Modules: Include “brain.py” and “evaluation.py” as core processing components (possibly handling business logic or ML/AI functions).
- Scraper Module: Under the “scraper” directory, include sub-components like html_parser, playwright_scraper, and request_dl. Also, note the CSV file (shl_solutions.csv) that might serve as a static data source or reference.
- Dependency & Build Management: Represent configuration files (pyproject.toml, requirements.txt) as part of the backend’s setup layer.
- Data/Integration Layer (if applicable):
- Although there is no dedicated "database" directory, the CSV file indicates data persistence or seed data.

##### Relationships and interactions
- Backend app to the Scraper module to highlight that data is either fetched or refreshed dynamically.
- Optionally, if data flows are relevant, indicate how the scraped information (or processed recommendations) might be utilized by the frontend.

##### Architectural patterns and design principles
- Separation of concerns: Clearly partition the system into frontend and backend with distinct responsibilities.
- Modularization: Both backend and frontend are structured in sub-modules (e.g., consistent organization in “scraper” and in “components”/“hooks”).
- Maintainability: Emphasize the use of configuration and dependency management files (like pyproject.toml, requirements.txt, and bun.lock/package.json) that underline a modern development approach.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend Layer
    subgraph "Frontend"
        F1["Next.js Application"]:::frontend
        F2["UI Components"]:::frontend
        F2a["Chat Interface"]:::ui
        F2b["Chat Message"]:::ui
        F2c["Recommendation Table"]:::ui
        F2d["Theme Provider"]:::ui
        F2e["Typing Indicator"]:::ui
        F2f["UI Subcomponents"]:::ui
        F3["State Mgmt & Hooks"]:::frontend
        F3a["use-chat.ts"]:::hooks
        F3b["use-mobile.ts"]:::hooks
        F4["Utility Libraries"]:::frontend
        F4a["extract-recommendations.ts"]:::utils
        F4b["extract-recommendations.tsx"]:::utils
        F4c["utils.ts"]:::utils
    end

    %% Backend Layer
    subgraph "Backend"
        B1["HTTP Server (app.py)"]:::backend
        B2["Processing Modules"]:::backend
        B2a["brain.py"]:::processing
        B2b["evaluation.py"]:::processing
        B3["Scraper Module"]:::backend
        B3a["HTML Parser"]:::scraper
        B3b["Playwright Scraper"]:::scraper
        B3c["Request Downloader"]:::scraper
        B3d["Seed Data (shl_solutions.csv)"]:::data
        B4["Dependency & Build Management"]:::backend
        B41["pyproject.toml"]:::config
        B42["requirements.txt"]:::config
    end

    %% Internal Frontend Connections
    F1 -->|"uses"| F2
    F2 --> F2a
    F2 --> F2b
    F2 --> F2c
    F2 --> F2d
    F2 --> F2e
    F2 --> F2f
    F1 -->|"manages"| F3
    F3 --> F3a
    F3 --> F3b
    F1 -->|"utilizes"| F4
    F4 --> F4a
    F4 --> F4b
    F4 --> F4c

    %% Frontend to Backend Relationship
    F1 -->|"API_request"| B1

    %% Internal Backend Connections
    B1 -->|"calls"| B2
    B2 --> B2a
    B2 --> B2b
    B2a -->|"triggers"| B3
    B2b -->|"triggers"| B3
    B3 --> B3a
    B3 --> B3b
    B3 --> B3c
    B3 --> B3d
    B1 -->|"loads"| B4
    B4 --> B41
    B4 --> B42

    %% Click Events
    click F1 "https://github.com/rycerzes/shl-rag-chatbot/tree/main/frontend/app"
    click F2 "https://github.com/rycerzes/shl-rag-chatbot/tree/main/frontend/components"
    click F3 "https://github.com/rycerzes/shl-rag-chatbot/tree/main/frontend/hooks"
    click F4 "https://github.com/rycerzes/shl-rag-chatbot/tree/main/frontend/lib"
    click B1 "https://github.com/rycerzes/shl-rag-chatbot/blob/main/backend/app.py"
    click B2a "https://github.com/rycerzes/shl-rag-chatbot/blob/main/backend/brain.py"
    click B2b "https://github.com/rycerzes/shl-rag-chatbot/blob/main/backend/evaluation.py"
    click B3 "https://github.com/rycerzes/shl-rag-chatbot/tree/main/backend/scraper"
    click B41 "https://github.com/rycerzes/shl-rag-chatbot/blob/main/backend/pyproject.toml"
    click B42 "https://github.com/rycerzes/shl-rag-chatbot/blob/main/backend/requirements.txt"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef ui fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef hooks fill:#D2B4DE,stroke:#512E5F,stroke-width:2px;
    classDef utils fill:#A9DFBF,stroke:#117864,stroke-width:2px;
    classDef backend fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef processing fill:#F1948A,stroke:#78281F,stroke-width:2px;
    classDef scraper fill:#FAD7A0,stroke:#9A7D0A,stroke-width:2px;
    classDef data fill:#D5F5E3,stroke:#1E8449,stroke-width:2px;
    classDef config fill:#E8DAEF,stroke:#6C3483,stroke-width:2px;
```
