# samson667/samson_ai architecture

> Architecture diagram of the GitHub repository samson667/samson_ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/samson667/samson_ai
- Repository: https://github.com/samson667/samson_ai

## Overview

Samson AI is a bilingual chat application with a browser-based interface and an Express backend. Users enter a prompt, choose the Samson or quick model, and receive a reply or a creator-information response. The backend validates prompts, handles creator questions locally, and dispatches other requests to Gemini or Groq; the frontend renders the result and maintains conversation state. README and sampled source show no separate persistence layer. Frontend details beyond the excerpts are uncertain, so the graph focuses on evidenced interactions and documented capabilities.

Main entry points: [`Backend/ai.js`](https://github.com/samson667/samson_ai/blob/main/Backend/ai.js) (Chat routing), [`Frontend/script.js`](https://github.com/samson667/samson_ai/blob/main/Frontend/script.js) (Chat UI), [`Backend/index.js`](https://github.com/samson667/samson_ai/blob/main/Backend/index.js) (Express server), [`Frontend`](https://github.com/samson667/samson_ai/tree/main/Frontend) (Static frontend assets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat interface"]
  node_chat_ui["Chat UI<br/>[script.js]"]
  node_message_render["Message rendering<br/>[script.js]"]
  node_creator_experience["Creator display and audio<br/>[script.js]"]
  node_static_frontend["Static frontend assets"]
end

subgraph group_server["Chat backend"]
  node_express_server["Express server<br/>[index.js]"]
  node_chat_router["Chat routing<br/>[ai.js]"]
  node_prompt_handling["Prompt and history handling<br/>[ai.js]"]
  node_creator_detection["Creator question handling<br/>[ai.js]"]
  node_model_dispatch["Model dispatch<br/>[ai.js]"]
  node_gemini_client["Gemini client<br/>[ai.js]"]
  node_groq_client["Groq client<br/>[ai.js]"]
end

subgraph group_models["AI providers"]
  node_gemini{{"Gemini API"}}
  node_groq{{"Groq API"}}
end

node_user(("Chat user"))
node_chat_result["Chat response"]

node_user -->|"enters prompt"| node_chat_ui
node_chat_ui -->|"renders messages"| node_message_render
node_chat_ui -->|"posts chat"| node_express_server
node_express_server -->|"serves assets"| node_static_frontend
node_express_server -->|"mounts router"| node_chat_router
node_chat_router -->|"validates input"| node_prompt_handling
node_chat_router -->|"checks creator question"| node_creator_detection
node_chat_router -->|"dispatches request"| node_model_dispatch
node_model_dispatch -->|"calls Samson model"| node_gemini_client
node_model_dispatch -->|"calls quick model"| node_groq_client
node_gemini_client -->|"requests completion"| node_gemini
node_groq_client -->|"requests completion"| node_groq
node_chat_router -->|"returns response"| node_chat_result
node_chat_ui -->|"shows creator response"| node_creator_experience
node_creator_experience -.->|"plays bundled audio"| node_static_frontend

click node_chat_ui "https://github.com/samson667/samson_ai/blob/main/Frontend/script.js"
click node_message_render "https://github.com/samson667/samson_ai/blob/main/Frontend/script.js"
click node_creator_experience "https://github.com/samson667/samson_ai/blob/main/Frontend/script.js"
click node_static_frontend "https://github.com/samson667/samson_ai/tree/main/Frontend"
click node_express_server "https://github.com/samson667/samson_ai/blob/main/Backend/index.js"
click node_chat_router "https://github.com/samson667/samson_ai/blob/main/Backend/ai.js"
click node_prompt_handling "https://github.com/samson667/samson_ai/blob/main/Backend/ai.js"
click node_creator_detection "https://github.com/samson667/samson_ai/blob/main/Backend/ai.js"
click node_model_dispatch "https://github.com/samson667/samson_ai/blob/main/Backend/ai.js"
click node_gemini_client "https://github.com/samson667/samson_ai/blob/main/Backend/ai.js"
click node_groq_client "https://github.com/samson667/samson_ai/blob/main/Backend/ai.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_chat_ui,node_message_render,node_creator_experience,node_static_frontend,node_user toneBlue
class node_express_server,node_chat_router,node_prompt_handling,node_creator_detection,node_model_dispatch,node_gemini_client,node_groq_client toneAmber
class node_gemini,node_groq toneMint
class node_chat_result toneIndigo
```

## Components

### Chat interface

- [Chat UI](https://github.com/samson667/samson_ai/blob/main/Frontend/script.js): `Frontend/script.js`
- [Message rendering](https://github.com/samson667/samson_ai/blob/main/Frontend/script.js): `Frontend/script.js`
- [Creator display and audio](https://github.com/samson667/samson_ai/blob/main/Frontend/script.js): `Frontend/script.js`
- [Static frontend assets](https://github.com/samson667/samson_ai/tree/main/Frontend): `Frontend`

### Chat backend

- [Express server](https://github.com/samson667/samson_ai/blob/main/Backend/index.js): `Backend/index.js`
- [Chat routing](https://github.com/samson667/samson_ai/blob/main/Backend/ai.js): `Backend/ai.js`
- [Prompt and history handling](https://github.com/samson667/samson_ai/blob/main/Backend/ai.js): `Backend/ai.js`
- [Creator question handling](https://github.com/samson667/samson_ai/blob/main/Backend/ai.js): `Backend/ai.js`
- [Model dispatch](https://github.com/samson667/samson_ai/blob/main/Backend/ai.js): `Backend/ai.js`
- [Gemini client](https://github.com/samson667/samson_ai/blob/main/Backend/ai.js): `Backend/ai.js`
- [Groq client](https://github.com/samson667/samson_ai/blob/main/Backend/ai.js): `Backend/ai.js`

### AI providers

- **Gemini API**
- **Groq API**

### Other components

- **Chat user**
- **Chat response**

## Connections

- Chat user → Chat UI: enters prompt (evidence: `Frontend/script.js`)
- Chat UI → Message rendering: renders messages (evidence: `Frontend/script.js`)
- Chat UI → Express server: posts chat (evidence: `Frontend/script.js`)
- Express server → Static frontend assets: serves assets (evidence: `Backend/index.js`)
- Express server → Chat routing: mounts router (evidence: `Backend/index.js`)
- Chat routing → Prompt and history handling: validates input (evidence: `Backend/ai.js`)
- Chat routing → Creator question handling: checks creator question (evidence: `Backend/ai.js`)
- Chat routing → Model dispatch: dispatches request (evidence: `Backend/ai.js`)
- Model dispatch → Gemini client: calls Samson model (evidence: `Backend/ai.js`)
- Model dispatch → Groq client: calls quick model (evidence: `Backend/ai.js`)
- Gemini client → Gemini API: requests completion (evidence: `Backend/ai.js`)
- Groq client → Groq API: requests completion (evidence: `Backend/ai.js`)
- Chat routing → Chat response: returns response (evidence: `Backend/ai.js`)
- Chat UI → Creator display and audio: shows creator response (evidence: `Frontend/script.js`)
- Creator display and audio → Static frontend assets: plays bundled audio
